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

Is there a standard way to store state to build messages from separate submessages published on different topics at different times?

asked 2014-08-04 21:18:07 -0600

jackcviers gravatar image

Say message A depends on information from independently published messages B and C, posted on separate topics at different rates (example, a dilution of precision measurement and a position measurement from a gps sensor are combined to produce a NavSatFix message with both the position and the calculated accuracy of that position). This implies that either message B or message C must be stored and re-accessed after it is published and received in order to compose and publish message A.

Is there a standard way in ROS to handle situations like this?w Topics are a Pub/Sub event model that relies on fire and forget to be performant. Services are supposed to perform as transformation functions over their inputs without storing intermediate values and would make sense to do the job of transforming message B and C into message A after being passed B and C. However, B and C arrive independently.

tf appears to have a means of performing timed polling of a message on its topic. Is this capability built into all topics? Additionally, I'd like to access only the "latest" message rather than a message at a specific time point in the past. That ability does not seem to be built into tf, and so I would assume it isn't in other topic/msg based interfaces either.

I considered using rosbag, but I would prefer to not rely on storing items on the filesystem if possible, and it too appears to be able to only read messages at a specifed time, rather than the latest available message.

As a last resort, I have constructed my own message cache using a ring buffer and numpy arrays to store the messages. I'd prefer a standard solution if it exists.

edit retag flag offensive close merge delete

Comments

I think your method is the best solution, a class with two methods (callbackB and callbackC) subscribing to B and C and two attributes (msgB, msgC) containing the latest message contents from B and C. Whenever one of the methods is called, it updates the attributes content and rebuilds a new message A and publishes it.

Mehdi. gravatar image Mehdi.  ( 2014-08-04 23:05:08 -0600 )edit

Yes, the cache is separate from the Transformation_Publisher. The cache is exposed as a service. The Transformation_Publisher subscribes to the necessary topics, it caches the values using the cache service, requests the latest value, then publishes the combined message.

jackcviers gravatar image jackcviers  ( 2014-08-04 23:39:55 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-08-05 06:06:21 -0600

dornhege gravatar image

If you want to cache messages, use a message_filters::Cache.

However, this seems overkill for only storing one message. Also I'm not sure why you need a ring buffer and numpy arrays for that. Just do last_message_a = msg in the respective callbacks and store those somewhere globally.

edit flag offensive delete link more

Comments

My real life scenario invloves messages from multiple recievers in multiple frames - it was easier to describe using one, sorry. The ring buffers allow or cacheing by topic and frame id. Latest is the latest for a matching frame, in this case.

jackcviers gravatar image jackcviers  ( 2014-08-06 16:36:02 -0600 )edit

However, this api is very similar to what I have implemented. If this is a chain of transformations over a series of events, it might work as needed. The slop ability should make it possible to get all msgs, then filter by frames.

jackcviers gravatar image jackcviers  ( 2014-08-07 00:19:20 -0600 )edit
0

answered 2014-08-05 03:12:52 -0600

BennyRe gravatar image

I also think your solution works best. I did not find a solution to pull messages from a subscriber.

Additionally, I'd like to access only the "latest" message rather than a message at a specific time point in the past. That ability does not seem to be built into tf, and so I would assume it isn't in other topic/msg based interfaces either.

That is possible if you set the queue_size argument of the Subscriber. Set it to one and only the latest message will be stored.

edit flag offensive delete link more

Comments

Queue size only affects the subscriber, not the topic, correct? I could put state on that subscriber and read it directly, I guess, if I had a reference to the subscriber...

jackcviers gravatar image jackcviers  ( 2014-08-06 16:45:51 -0600 )edit

Yes I think it affects only the subscriber.

BennyRe gravatar image BennyRe  ( 2014-08-06 23:59:21 -0600 )edit

The answer below is the correct one, I think. message_filters allows you to setup an ApproximateTimeSynchronizer that subscribes to multiple events. An additional filter matching frames could then be implemented in the project.

jackcviers gravatar image jackcviers  ( 2014-08-07 00:36:12 -0600 )edit

See how ApproximateTimeSynchronizer(http://tinyurl.com/lhe9gl8) filters using the if in the for comprehension on line 170 to discover how to make your own filter. Edit: Link was broken.

jackcviers gravatar image jackcviers  ( 2014-08-07 00:40:10 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-08-04 21:18:07 -0600

Seen: 248 times

Last updated: Aug 05 '14