Rosanswers logo

I have been using ROS for a short time now and learned about callbacks & spinning. My question is, since be default all callbacks are added to the global callback queue, does ros::spin() in node A also process callbacks for subscribers in node B?

For a specific example, in MAVROS there is a 4 thread asynchronous spinner. I built a ROS node that uses MAVROS. In my node I also use an asynchronous spinner to process callbacks; however if they both use the global callback queue then is my asynchronous spinner redundant?


Originally posted by powerstorm42 on ROS Answers with karma: 11 on 2016-06-21

Post score: 0

Original comments

Comment by billy on 2016-06-21:
I can't comment on your specific use of MAVROS in your node, but in general, a spin in one node will not cause a callback to process in a different node. I know that from personal experience so have no cite for you. It's easy to check. Remove and see what happens.

Comment by Martin Günther on 2016-06-23:
The term "global callback queue" means "global" within the context of the node process, not between different processes. You can either create an asynchronous spinner, call spin() or call spinOnce().

Comment by powerstorm42 on 2016-06-23:
Thanks everyone! I understand it know, especially Martin's explanation that the queue is only global within the node, not across all nodes.


1 Answer 1


Rosanswers logo

Yes, every ROS node needs to spin, with the stipulation that your terminology matches conventional usage.

"ROS node" is conventionally used to refer to a process (or standalone executable, disregarding nodelets). (Edit: upon thinking about it, a more correct definition would also require use of a ROS callback queue. For instance, one might only access the master API in their executable; such a process would probably still be considered a ROS node, but it would have no need for a spin.) Threads, such as those used by an asynchronous spinner, are computational structures within a process. In the case of an asynchronous spinner, that are all able to use the global callback queue (thus, only one spin is necessary).

As to your use of MAVROS, it depends on what you mean by I built a node that uses MAVROS. If you run MAVROS as a node separate and distinct from your own node, then both need spin calls. If you've simply modified the MAVROS source, adding your own code to it that compiles into a single executable, then a single spin is sufficient.

Note that there are cases where it is helpful to use multiple spin calls (typically, multiple spinOnce calls with multiple threads) within a single node, and it is also sometimes useful to set up multiple callback queues within a single node. But these are beyond your question; any (communicating, functioning) ROS node must have at least one callback queue and one spin call.

Originally posted by kramer with karma: 1470 on 2016-06-22

This answer was ACCEPTED on the original site

Post score: 1


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.