Ask Your Question

Functional difference between ROS2 spin_some, spin_once, and spin_until_future

asked 2018-07-05 17:58:26 -0600

I understand that spin_once will just query once, but I'm not sure when spin_some would be a better choice or under what situations it would return. Spin until... is for service callbacks I've seen but any other time that would be helpful?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-07-08 20:33:59 -0600

William gravatar image

spin_once will process one item in the executor, it may or may not be the thing you expect, however. Sometimes you just want to spin one thing at a time periodically, and don't care what it is.

Other times you want to spin one thing at a time until something has completed, this is where spin_until_future_complete is useful, as it basically does while(future.not_done()) executor.spin_once(). It's a bit more complicated than that, but essentially that's what it is doing. You could do this yourself, so spin_until_future_complete is just a convenience function.

spin_some is slightly different. Basically it spins, executing zero to many items, until it is "idle", basically until there's a time where there is nothing for the executor to do. Some people might assume that spin_some would only process what available when it is called, exiting even if there's more work to be done after a period of time. There's an issue and pull request to try and make it behave that way, but they're still in progress:

edit flag offensive delete link more


I am having trouble finding literature on using ROS2 executors and getting a pub/sub file working. Do you know anywhere I can look to get more information or a hands on tutorial?

rhogan gravatar image rhogan  ( 2019-09-04 10:56:01 -0600 )edit

Your Answer

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

Add Answer

Question Tools



Asked: 2018-07-05 17:58:26 -0600

Seen: 5,504 times

Last updated: Jul 08 '18