当前位置:网站首页>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勾选即可显示

边栏推荐
- NBI visual platform quick start tutorial (V) introduction to editor functions and operations
- 德国AgBB VoC有害物质测试
- PyTorch学习(三)
- 删除排序链表中的重复元素 II[链表节点统一操作--dummyHead]
- 传统微服务框架如何无缝过渡到服务网格 ASM
- Lenovo Yoga 27 2022, full upgrade of super configuration
- Huaxing Securities: kitex practice under the original hybrid Cloud Architecture
- Where do the guests come from
- Ditto设置全局仅粘贴文本快捷键
- ArcGIS无插件加载(无偏移)天地图
猜你喜欢

Swin-Transformer(2021-08)

Influence and requirements of different manufacturing processes on the pad on PCB

Video content production and consumption innovation

Reading notes of "high EQ means being able to talk"

Four tips tell you how to use SMS to promote business sales?

DTD modeling

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

ANSI/UL 94 5-V级垂直燃烧试验

Nodejs installation and introduction

教你30分钟快速搭建直播间
随机推荐
Is it safe to open an account for goucai? Is it reliable?
Swin-Transformer(2021-08)
联想YOGA 27 2022,超强配置全面升级
Redis beginner to master 01
Video content production and consumption innovation
Cloud Native Landing Practice Using rainbond for extension dimension information
商业智能BI与业务管理决策思维之四:业务成本分析
Cobbler轻松上手
正则表达式(正则匹配)
新版EasyGBS如何配置WebRTC视频流格式播放?
ArcGIS无插件加载(无偏移)天地图
Practical application of "experience" crawler in work
《所谓情商高,就是会说话》读书笔记
Opencv data type code table dtype
【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
CODING 正式入驻腾讯会议应用市场!
开发那些事儿:Linux系统中如何安装离线版本MySQL?
Practical application of "experience" crawler in work "theory"
go之web框架 iris
「干货」数据分析常用的10种统计学方法,附上重点应用场景