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

Revision history [back]

For service (and also topic) callbacks to be able to get called, ros::spin() has to be called. This does not happen in your example, which is the reason for the behavior you observe. The easiest way to make things work in your example is probably adding a ros::spinOnce() somewhere in your while loop (This will add potentially non-deterministic delays to your controller loop however).

A better option is using an AsyncSpinner, which spins using one or more separate threads in parallel to your main loop. An example of it's use can be found here.