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

Revision history [back]

click to hide/show revision 1
initial version

So the problem is in all three methods there's no executor spinning while move_robot is running and you're waiting on the future value. Spinning is required because the service response is just another message coming in on a topic and so a subscription callback (internal to the service client) must be run to receive it.

In the first method, you're still in the node constructor so the spin function hasn't been called yet. In the second and third ones you're running move_robot from inside another callback and the executor won't return to spinning until that callback returns.

It is possible to have multiple callbacks run simultaneously (so the service response can arrive while you wait in another callback) but it's a bit complicated. You have to manually create a MultiThreadedExecutor and use it for spinning. You also have to either create separate callback groups or create a reentrant callback group since the default callback group setting is to be mutually exclusive and only allow one callback to run at a time.