栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

关于“ROS2 Topic-Statistics-Tutorial编译出错”的思考

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

关于“ROS2 Topic-Statistics-Tutorial编译出错”的思考

原文:

ROS2 Topic-Statistics-Tutorial编译出错


如何避免出现类似问题呢?

在最初的时候:

docs.ros.org/en/foxy/Tutorials/Topics/Topic-Statistics-Tutorial.html

此文档中:

 

wget -O member_function_with_topic_statistics.cpp https://raw.githubusercontent.com/ros2/examples/master/rclcpp/topics/minimal_subscriber/member_function_with_topic_statistics.cpp


遇到问题时必然的。


其实官方文档在版本管理上不足:

 

master主分支一般代表最新版本。

foxy和galactic,版本选择上推荐galactic


#include 
#include 

#include "rclcpp/rclcpp.hpp"
#include "rclcpp/subscription_options.hpp"

#include "std_msgs/msg/string.hpp"

class MinimalSubscriberWithTopicStatistics : public rclcpp::Node
{
public:
  MinimalSubscriberWithTopicStatistics()
  : Node("minimal_subscriber_with_topic_statistics")
  {
    // manually enable topic statistics via options
    auto options = rclcpp::SubscriptionOptions();
    options.topic_stats_options.state = rclcpp::TopicStatisticsState::Enable;

    // configure the collection window and publish period (default 1s)
    options.topic_stats_options.publish_period = std::chrono::seconds(10);

    // configure the topic name (default '/statistics')
    // options.topic_stats_options.publish_topic = "/topic_statistics"

    auto callback = [this](std_msgs::msg::String::SharedPtr msg) {
        this->topic_callback(msg);
      };

    subscription_ = this->create_subscription(
      "topic", 10, callback, options);
  }

private:
  void topic_callback(const std_msgs::msg::String::SharedPtr msg) const
  {
    RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg->data.c_str());
  }
  rclcpp::Subscription::SharedPtr subscription_;
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared());
  rclcpp::shutdown();
  return 0;
}

github.com/ros2/examples/blob/galactic/rclcpp/topics/minimal_subscriber/member_function_with_topic_statistics.cpp

docs.ros.org/en/foxy/Tutorials/Topics/Topic-Statistics-Tutorial.html

代码是保持一致的。


关于上问最后提及的疑问(::SharedPtr 和 & ):

github.com/ros2/examples/pull/281github.com/ros2/examples/pull/337

 


 github.com/ros2/rclcpp/pull/1598

C++ 17 新增特性。C++ 11 和 C++ 14 必然不支持啊。


  

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/743710.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号