Ask Your Question

What does rclcpp::spin actually do ? What is "spin node" mean?

asked 2021-10-13 08:03:10 -0500

Hieu Joestar gravatar image

Hello guys, i got a trouble of rclcpp::spin. The rclcpp Namespace Reference tell that spin() will spin the node. But with the code in create a publisher in link. Does the spin loop for all the scope of the constructor body, which means the publisher_ and timer_ variable will be assigned so much time? Or it just spin(loop) the call back function in timer_? or what is it actually happen. I want to know the explain of mechanism of this code. Thank you.

Sorry for my english skill.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-10-13 12:17:00 -0500

swilcock0 gravatar image

Essentially rclcpp::spin() is allowing the ros node to keep running and check for events on subscribed topics and service calls, and direct the callbacks. It doesn't loop through the constructor, it's a blocking operation in your code; rather it binds these topic/service/action events to the callbacks you define as publisher_ or timer_ through rclcpp executors. The executors are designed to queue callbacks and make sure nothing blocks other activities.

From the definition in that link above:

Coordinate the order and timing of available communication tasks. [...] It coordinates the nodes and callback groups by looking for available work and completing it, based on the threading or concurrency scheme provided by the subclass implementation.

edit flag offensive delete link more


Thank sir, but "The executors are designed to queue callbacks and make sure nothing blocks other activities." DId you mean all callbacks run parallel ? That 's so weird if it's parallel in a singlethread model.

Hieu Joestar gravatar image Hieu Joestar  ( 2021-10-13 21:35:53 -0500 )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: 2021-10-13 08:03:10 -0500

Seen: 799 times

Last updated: Oct 13 '21