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

Seeking clarity regarding callback queues and ros::spin()

asked 2022-02-02 00:36:01 -0500

Let's say that we have initialized 2 different nodes inside 2 different main functions. Also assume that each of these two nodes have one subscriber each, subscribing to the topic topic_a. We also have ros::Spin() at the end of each of these 2 main functions.

Would the callbacks corresponding to each of these 2 subscribers be pushed to the same global queue and ros::spin() call from either of the 2 nodes would spin the oldest callback from this queue? Or, there would be 2 callback queues, one for each node?

edit retag flag offensive close merge delete

Comments

After posting an answer I must say this sounds a lot like a question on an exam, or as part of someone's homework.

gvdhoorn gravatar image gvdhoorn  ( 2022-02-02 03:05:13 -0500 )edit

@gvdhoorn I need more time.

skpro19 gravatar image skpro19  ( 2022-02-03 10:46:30 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-02-02 03:02:51 -0500

gvdhoorn gravatar image

updated 2022-02-02 05:31:54 -0500

Let's say that we have initialized 2 different nodes inside 2 different main functions. Also assume that each of these two nodes have one subscriber each, subscribing to the topic topic_a. We also have ros::Spin() at the end of each of these 2 main functions.

In ROS 1, there is a 1-to-1 correspondence between nodes and processes.

So only a single node can "live" in a specific process (or: program).

Programs do not share any of their internal state by default, which would include any (global) variables.

You also -- by default -- cannot have "two different main functions" in a single program. The compiler will not allow you.

In my answer below I've assumed that "two different main functions" therefore means: "two different programs".

Would the callbacks corresponding to each of these 2 subscribers be pushed to the same global queue and ros::spin() call from either of the 2 nodes would spin the oldest callback from this queue?

Due to the way operating systems isolate processes from each other, it's impossible for two nodes to share a single callback queue (or to share anything of their internal state really).

In the end, this is not really a "ROS question". Distilling it down to its essence, you ask whether process_A can access internal state of process_B. For any modern operating system, and without using special "tricks" (ie: shared memory), the answer will always be: no.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-02-02 00:36:01 -0500

Seen: 78 times

Last updated: Feb 02 '22