handling asynchronous data in a service call
How do I design my ros::spin (and friends) when a service callback requires that I wait for for a topic before I can reply?
For example:
The application needs to get a certain parameter from a node. This is implemented as a service request: request: named parameter, response: value
But the node may need to request this from the hardware, and the reply from the hardware driver comes in asynchronously on a ROS topic. I think it is reasonable to stick with using a ROS service, since the hardware IO is fast and provides the response in less than 10ms.
So the scenario is something like:
- node receives service callback: get_param_service_cb
- node sends request to hardware for setting
- node waits for the reply as a certain message on some topic
- node evaluates message, sets the proper service response and exits the service callback
How do I spin during the service callback to receive the topic callback?
Do I need to use multiple callback queues to achieve this?
Or will a MultiThreadedSpinner ensure that the topic is serviced?
Isn't this a 'duplicate' of #q285882 (in combination with #q274894 and #q274903)?
Thanks for referencing related questions. Maybe my question is a little different by the fact that a service callback needs to be handled synchronously as far as I understand. So I guess I cannot use a plain spin() as suggested in the answer to #q285882.