ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

ROS2 how can I call a service and wait for the response from within a subscriber callback?

asked 2018-06-21 09:51:35 -0500

vandy2000 gravatar image

I'd like to continue to spin but know when the request is available, using C++

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-06-21 13:34:01 -0500

William gravatar image

This is not currently possible, so you'll have to do an asynchronous service call, starting it in the subscription callback and finishing it in a callback when the response is received. Here's an example:

In general, it's a bad idea to block in a subscription (or service, or timer) callback since that prevents other callbacks from being handled.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-06-21 09:51:35 -0500

Seen: 2,946 times

Last updated: Jun 21 '18