pythonrosrospy

Is there a way to see a ROS topic's previously published messages, so late subscribers can see previously published data?


I'm developing ros nodes in a system that has other nodes running which are opaque to me (developed by another party and essentially locked to any changes). One of these nodes publishes a single message on a ROS topic very early in the system boot sequence. There's no guarantee that my node will be alive in time to see this message be published, it's actually way more likely that my node will not be up yet. This message contains some information my node requires to properly configure itself and some other things.

So is there any way for my node to retrieve this message after it's been published?


Solution

  • There isn't exactly a way to see history of messages across a topic. However, you can make a publisher latching. This means that when it publishes a message it will continue to be seen by subscribers until a new message replaces it. It can be used via an optional argument to rospy.Publisher

    pub = rospy.Publisher('topic_name', topic_type, queue_size=10, latch=True)