Topic是ROS的三种通信方式中最为基本、也是常用的一种。本文对于ROS的Topic通信背后的数据吞吐机制做一个较为详细、深入的介绍。
Publisher
ROS中发布一个topic的函数是这样的
ros::Publisher advertise(const std::string& topic, uint32_t queue_size, bool latch = false);
Parameters:
topic: Topic to advertise on
queue_size: Maximum number of outgoing messages to be queued for delivery to subscribers
latch: (optional) If true, the last message published on this topic will be saved and sent to new subscribers when they connect
有三个参数:topic就是我们要发布的话题,queue_size是publisher队列中可以存储的消息数量, latch是锁存,比如停止publish后保存最后一条message,如果有新的subscriber订阅的话,把之前保存的消息发给新的subscriber。
下面讲一讲和queue_size相关的,关系到我们发送的数据能否按照期望频率传输,会不会丢帧等。
案例分析
ros::init(argc, argv, "talker");
ros::NodeHandle handle;
ros::Publisher chatter_pub = handle.advertise<std_msgs::String>("chatter", 10);
ros::Rate loop_rate(100);
int count = 0;
std::stringstream ss

本文深入介绍了ROS中的Topic通信机制,包括Publisher与Subscriber的工作原理、消息队列管理、回调函数注册及处理过程,以及如何通过调整参数确保数据吞吐效率。

875

被折叠的 条评论
为什么被折叠?



