Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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:

  1. node receives service callback: get_param_service_cb
  2. node sends request to hardware for setting
  3. node waits for the reply as a certain message on some topic
  4. 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?