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:
- have two variable in the "main" part of the node (which I believe is a separate process and so will survive)
- whenever the callback of either message is called, store the updated value in the corresponding variable
- do the computation using whatever was there from the last time the other callback was called.
- 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?