Ask Your Question

Is spinOnce needed?

asked 2013-06-22 15:51:51 -0500

updated 2014-01-28 17:17:00 -0500

ngrennan gravatar image

If I have ROS node that has an infinite loop that has other things running, do I need to use spin or spinOnce? The other items have specific timing such as 100 and 50 Hz but the subscriber I have does not need to but so specific. Can I call the subscriber some how in the loop?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-06-23 22:40:43 -0500

Philip gravatar image

updated 2013-06-23 22:42:12 -0500

For single-threaded nodes:

If you have an infinite loop of your own that does some processing, use spinOnce() somewhere in the loop. This allows ROS to process the callbacks for queued messages - if you don't include it, your callbacks will never be called and none of your messages will be published.

If all your calculations are performed in callbacks and you don't need an infinite loop for your custom processing, just use spin() which continuously pumps for callbacks.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-06-22 15:51:51 -0500

Seen: 1,798 times

Last updated: Jun 23 '13