Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Need information from two different topics at once

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?