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

I would suggest you to read the wiki about Callbacks and Spinning, from the introduciton :

The end result is that without a little bit of work from the user your subscription, service and other callbacks will never be called. The most common solution is ros::spin()

In your first code ros::spin() is outside the while loop so it's never called so neither are your callbacks. In your second code you are actually spinning so the behavior you describe is totally normal.

Now you should see some related questions to understand the concept of spinning : #q257361, #q11887.