ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Either of the patterns in Multi-threaded Spinning would work, when replacing the code block of
controller.run();
Both spinners shown create a pool of 4 threads, that will service your callbacks as they come in (on one queue, multiple callback queues are very specialized and likely unnecessary for most applications.)
So if you're worried that your one long-running service will prevent one topic's message callbacks from being processed, you can create a spinner(2), which can serve two callbacks in parallel. The only difference is that MultiThreadedSpinner.spin() is blocking similar to ros::spin(), while AsyncSpinner.spin() is not.
HOWEVER, services are specifically intended to return quickly and not be long-running tasks, which is why you should consider using actionlib clients/servers instead.