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

Functional difference between ROS2 spin_some, spin_once, and spin_until_future

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

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
8

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

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

Comments

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 -0500 )edit

Question Tools

2 followers

Stats

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

Seen: 16,749 times

Last updated: Jul 08 '18