当前位置:网站首页>ros advertise 发布数据小技巧--latch配置
ros advertise 发布数据小技巧--latch配置
2022-06-30 17:57:00 【龙性的腾飞】
在ros发布数据的advertise函数参数里面最后一个参数"latch",默认为false,一直没有注意,今天在分析其他问题时在ros wiki[Publishers and Subscribers]上偶然注意到了这个参数,
说明如下:
latch [optional]
- Enables "latching" on a connection. When a connection is latched, the last message published is saved and automatically sent to any future subscribers that connect. This is useful for slow-changing to static data like a map. Note that if there are multiple publishers on the same topic, instantiated in the same node, then only the last published message from that node will be sent, as opposed to the last published message from each publisher on that single topic.
advertise函数定义在文件/opt/ros/melodic/include/ros/node_handle.h, 也做了说明.
/**
* \brief Advertise a topic, simple version
*
* This call connects to the master to publicize that the node will be
* publishing messages on the given topic. This method returns a Publisher that allows you to
* publish a message on this topic.
*
* This version of advertise is a templated convenience function, and can be used like so
*
* ros::Publisher pub = handle.advertise<std_msgs::Empty>("my_topic", 1);
*
* \param topic Topic to advertise on
*
* \param queue_size Maximum number of outgoing messages to be
* queued for delivery to subscribers
*
* \param latch (optional) If true, the last message published on
* this topic will be saved and sent to new subscribers when they
* connect
*
* \return On success, a Publisher that, when it goes out of scope,
* will automatically release a reference on this advertisement. On
* failure, an empty Publisher.
*
* \throws InvalidNameException If the topic name begins with a
* tilde, or is an otherwise invalid graph resource name, or is an
* otherwise invalid graph resource name
*/
template <class M>
Publisher advertise(const std::string& topic, uint32_t queue_size, bool latch = false)
{
AdvertiseOptions ops;
ops.template init<M>(topic, queue_size);
ops.latch = latch;
return advertise(ops);
}一般接收节点要在发布节点启动后才能接收到数据,但启动顺序有时无法控制,就会导致某些数据丢失,尤其像地图这种只发布一次的. 当发布数据端设置了latch = true,后起节点也可以接收到之前的最后一帧消息.另外一个特别有用的就是发布rviz可视化数据调试程序时,根据namesapce分析某些结果时,可以重复勾选显示某些条目,只需在rviz中重新勾选一下这个Display就可以, 不需要重新播放数据.
如下图,先播放bag数据,暂停后,在rviz勾选即可显示

边栏推荐
- Large file transfer software based on UDP protocol
- 正则表达式(正则匹配)
- 基于 actix、async-graphql、rbatis、pgsql/mysql 构建 GraphQL 服务(4)-变更服务
- German agbb VOC hazardous substances test
- 传统微服务框架如何无缝过渡到服务网格 ASM
- 4个技巧告诉你,如何使用SMS促进业务销售?
- Lenovo Yoga 27 2022, full upgrade of super configuration
- Video content production and consumption innovation
- Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 1)
- Can go struct in go question bank · 15 be compared?
猜你喜欢

sqlserver SQL Server Management Studio和Transact-SQL创建账户、创建访问指定数据库的只读用户

全栈代码测试覆盖率及用例发现系统的建设和实践

一套十万级TPS的IM综合消息系统的架构实践与思考

正则表达式(正则匹配)

Full recharge, im+rtc+x full communication service "feedback season" starts

华兴证券:混合云原生架构下的 Kitex 实践

Lenovo Yoga 27 2022, full upgrade of super configuration

Nodejs 安装与介绍

Adhering to the concept of 'home in China', 2022 BMW children's traffic safety training camp was launched

教你30分钟快速搭建直播间
随机推荐
新版EasyGBS如何配置WebRTC视频流格式播放?
MySQL事务并发问题和MVCC机制
华兴证券:混合云原生架构下的 Kitex 实践
Dlib library for face key point detection (openCV Implementation)
openGauss数据库源码解析系列文章—— 密态等值查询技术详解(上)
Opencv data type code table dtype
链表中环的入口结点-链表专题
Influence and requirements of different manufacturing processes on the pad on PCB
Entropy - conditional entropy - joint entropy - mutual information - cross entropy
Kubernetes----Pod配置容器启动命令
Practical application of "experience" crawler in work "theory"
基于STM32F1的环境光与微距离检测系统
Vs common shortcut key commands
How to configure webrtc video stream format playback in the new version of easygbs?
Can go struct in go question bank · 15 be compared?
opencv数据类型代码表 dtype
Lenovo Yoga 27 2022, full upgrade of super configuration
Practical application of "experience" crawler in work
Coding officially entered Tencent conference application market!
Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 1)