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

Revision history [back]

Hi Sebastian,

a couple of points:

  • Service calls are blocking. This is a deliberate design decision. IMO, services should in general only be used for things which return quickly. If you want to query a long-running service asynchronously, that's a sign that that service should better be implemented as an actionlib action. (... assuming you control the implementation of the service, that is.)
  • Your topic callbacks aren't triggered because they only are triggered when your node enters ros::spin() or ros::spinOnce(). In roscpp, there are threads which handle topics asynchronously, but they only fill the subscriber queues. When you call ros::spin(), your thread goes through the messages in the subscriber queues one by one and calls the corresponding callbacks. This means that if you're only using ros::spin(), your code won't be multi-threaded.
  • A good solution for your problem could be the ros::AsyncSpinner class. It starts a user-defined number of threads which all call ros::spin(), so you don't have to call it yourself any more. The drawback (as with any multi-threaded solution) is of course that now you need to make sure that all resources are properly locked to prevent data races.

Hope this helps!