handling asynchronous data in a service call

asked 2018-04-17 07:39:35 -0500

MikeWx gravatar image

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?

edit retag flag offensive close merge delete

Comments

Isn't this a 'duplicate' of #q285882 (in combination with #q274894 and #q274903)?

gvdhoorn gravatar image gvdhoorn  ( 2018-04-17 07:55:40 -0500 )edit

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.

MikeWx gravatar image MikeWx  ( 2018-04-17 12:21:02 -0500 )edit