ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Order of called-back program when execute spinOnce

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

cangjiaxuan gravatar image

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

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

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

kramer gravatar image

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

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

Your Answer

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

Add Answer

Question Tools

1 follower


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

Seen: 531 times

Last updated: Jan 21 '15