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

Order of called-back program when execute spinOnce

asked 2015-01-21 10:22:24 -0500

cangjiaxuan gravatar image

updated 2015-01-21 10:55:38 -0500

Procópio gravatar image

Hi there, it's my first time asking question, if there is something I missed please inform me:) So my question is like this. I have one node, with two subscriber, linked to two different topic. When I use the while+ros::spinOnce() procedure to replace spin, which subscriber's program would be called first when ros::spinOnce() is executed?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2015-01-21 10:54:16 -0500

Procópio gravatar image

that does not depend on the subscriber node, but on the topics being published to it. the first topic to be published once you start your program will activate the callback of the correspondant subscriber.

edit flag offensive delete link more

answered 2015-01-21 14:23:02 -0500

kramer gravatar image

updated 2015-01-21 14:25:04 -0500

Briefly, yes, you're missing something. :)

More expansively, a node is a process; separate nodes execute independently. In your case, you have at least two nodes, one with two subscriber members (call it subNode) and (at least) one other node with publisher member(s) (call it pubNode). SubNode executes by endlessly looping -- during each loop, the 'spinOnce' checks the callback queue for messages. Unless and until pubNode publishes a message that subNode receives, nothing will happen (beyond the endless looping).

In general, there's no guarantee which message subNode will receive first, but it will handle its callbacks in the order it receives the messages.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-01-21 10:22:24 -0500

Seen: 554 times

Last updated: Jan 21 '15