ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

getting more than the last message from rostopic

asked 2021-06-11 09:28:49 -0500

Dynaflock gravatar image

Hi,

I'd like to know if, in general, it is possible to access the n last messages from a rostopic using a callback function for instance, in one shot ?

Or is it mandatory to use a buffer system to aggregate the messages as they are published ?

It's a general question about how ROS works.

Thank you in advance !

PS: I'm on ROS Melodic, Ubuntu 18.04.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-06-12 04:07:30 -0500

gvdhoorn gravatar image

Note: you tagged this melodic, meaning ROS 1. This answer would be significantly different in a ROS 2 context, where DDS QoS allows to configure such properties as history and durability.

As for ROS 1:

I'd like to know if, in general, it is possible to access the n last messages from a rostopic using a callback function for instance, in one shot ?

no, pub-sub is implemented in such a way that all participants must be on-line at the same time to receive messages.

See #q203129 for a related question.

There is one "exception" and that would be latched topics:

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.

But that will get subscribers only the last message published on a topic by a publisher, nothing more.

Or is it mandatory to use a buffer system to aggregate the messages as they are published ?

Yes, that's typically how this is implemented.

But you don't need to write that yourself. Use a message_filters Cache or even better, if possible, a TimeSynchronizer policy.

A community contributed alternative/improvement could be fkie/message_filters, which adds some more flexibility and generalises the pipeline concept a bit more.

edit flag offensive delete link more

Comments

Ok thank you, I'll have a look at those solution and see if I can work something out.

I will try to add my results in this topic as a report for others.

Thank you

Dynaflock gravatar image Dynaflock  ( 2021-06-14 10:16:01 -0500 )edit

Question Tools

Stats

Asked: 2021-06-11 09:28:49 -0500

Seen: 381 times

Last updated: Jun 14 '21