ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Is it possible to know if a topic is latched on subscriber side in cpp

asked 2021-01-13 03:36:14 -0500

arneboe gravatar image

I need to figure out if a topic is latched on the subscriber side in cpp. This is needed to implement a feature in rosbag-snapshot. Is that possible and if yes any hints how?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-01-13 04:11:20 -0500

gvdhoorn gravatar image

updated 2021-01-13 04:22:35 -0500

I don't know about doing this in C++ specifically, but at least the Connection header appears to have a field which encodes whether:

publisher is in latching mode (i.e. sends the last value published to new subscribers)

The wiki/rospy/Overview/Publishers and Subscribers: Subscribing to a topic - Connection Information shows how to access this in rospy.

In roscpp, you can get the header from the MessageEvent (getConnectionHeader(), via MessageEvent [ROS 1.1+]).

I would expect rosbag to have other options to get the connection header though, seeing as it already deals with connections.

Edit: this comment in the issue you commented on links to ros/ros_comm/tools/topic_tools/src/relay.cpp which actually shows how to do this:

boost::shared_ptr<const ros::M_string> const& connection_header =


// If the input topic is latched, make the output topic latched, #3385.
bool latch = false;
if (connection_header)
  ros::M_string::const_iterator it = connection_header->find("latching");
  if((it != connection_header->end()) && (it->second == "1"))
    ROS_DEBUG("input topic is latched; latching output topic to match");
    latch = true;
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2021-01-13 03:36:14 -0500

Seen: 349 times

Last updated: Jan 13 '21