Ask Your Question

Need information from two different topics at once

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

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

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

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


Note: there is also a tf_message_filter.

gvdhoorn gravatar imagegvdhoorn ( 2018-07-31 06:21:26 -0600 )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 imagepitosalas ( 2018-08-01 06:08:29 -0600 )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 imagegvdhoorn ( 2018-08-02 02:39:03 -0600 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


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

Seen: 96 times

Last updated: Jul 31 '18