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

Need information from two different topics at once

asked 2018-07-31 06:02:58 -0500

pitosalas gravatar image

This is an architectural question - or a best practices question. I am writing a node which will be computing based on a subscription to /LaserScan and /cmd_vel. As those messages will come in asynchronously I wonder if there's a best practice for holding onto one while I wait for the other, or how one does this.

The natural idea is this:

  1. have two variable in the "main" part of the node (which I believe is a separate process and so will survive)
  2. whenever the callback of either message is called, store the updated value in the corresponding variable
  3. do the computation using whatever was there from the last time the other callback was called.
  4. Each time the computation is done, publish the result on a different topic.

Is this right? Will the variables persist over the lifetime of the node? Are there race conditions to worry about? Or other concurrency or design problems?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-07-31 06:20:46 -0500

gvdhoorn gravatar image

The best practice I believe is to use message_filters. You have several options:

The first would be similar to what you sketch in your question, but a bit more robust and explicit, while the latter is a different approach, but it might be even more appropriate, depending on the temporal relationship there is between the incoming messages.

edit flag offensive delete link more

Comments

Note: there is also a tf_message_filter.

gvdhoorn gravatar image gvdhoorn  ( 2018-07-31 06:21:26 -0500 )edit

Thanks! Skimming the doc for message filters, they look like just what I need. I am working in python though, and it seems like the python bindings are less complete, or is that just an absence of doc?

pitosalas gravatar image pitosalas  ( 2018-08-01 06:08:29 -0500 )edit

Python support should be there, but it's been some time since I've used it (mostly C++). The tutorials aren't as extensive, no.

gvdhoorn gravatar image gvdhoorn  ( 2018-08-02 02:39:03 -0500 )edit

Hey! What about publishing a message that is computed based on filtered callback? If publisher method works separately from the callbacks, are there gonna be race conditions (since callback writes to the same variable the publisher reads from? Are mutexes a good practice to use here to avoid it?

sejego gravatar image sejego  ( 2022-01-26 08:02:10 -0500 )edit

You should really post a new question instead of a comment under an answered question (ie: basically a closed one) from 2018.

gvdhoorn gravatar image gvdhoorn  ( 2022-01-26 12:39:05 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-07-31 06:02:58 -0500

Seen: 312 times

Last updated: Jul 31 '18