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

Is spinOnce needed?

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

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

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 -0600

Philip gravatar image

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

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

Question Tools

1 follower


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

Seen: 2,036 times

Last updated: Jun 23 '13