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

Running ros nodes sequentially

asked 2021-04-09 05:56:12 -0500

sandeepROS gravatar image


I have 3 ROS nodes in Python and they run in a loop. The 1st node publishes the command to the 2nd node. The 2nd node subscribes to the 1st node and also to the feedback from the 3rd node and based on that, it publishes to the third node. The 3rd node which is subscribed to the 2nd node then publishes its feedback back to the 2nd node. When the feedback arrives, the 1st node should again publish to the 2nd node (until then, the publishing should be stopped/blocked from the 1st node) and this loop continues. How can I achieve this workflow? Right now, I launch 3 nodes in a launch file and this is not giving me desired result. I tested by running all nodes separately one after another. In this case, they do not connect with each other and I can see 3 unconnected nodes in rqt graph. In the first increment, I initialize feedback from the 3rd node to some default value so that the 2nd node can start working. Can someone please suggest to me how to tackle this? Should I use Ros services? Currently, I am just using subscribers and publishers. Could someone give me some hints?

Thanks in advance

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-04-10 04:18:36 -0500

parzival gravatar image

updated 2021-04-10 05:22:28 -0500

It is possible using pub-sub. You don't really have to launch the nodes in the exact order.

From what I understand, node1 will publish on topicA, node2 will subscribe to topicA, and publish on topicB, which is subscribed by node3. node3 also publishes topicC, subscribed by node2(which you call feedback), when node2 receives a message from topicC, it can publish a message on topicD, which will be subscribed by node1, and the entire process happens again.

You have used node and topic interchangeably at some places, so I might have made an error in understanding you, but if not, the above node graph should solve your issue

edit flag offensive delete link more


Thanks for the reply. I might have been unclear in my question, let me correct it. node1 publishes on topicA which is the starting point of the program. node2 is subscribed to topicA from node 1 and also to topicC (which should be initialized to zero in the 1st iteration) from node 3. Then, node2 publishes topicB to node 3. Node3 then updates and publishes on topicC (which I referred to as feedback) to node2. Now, the loop is completed and this whole process should be repeated.

sandeepROS gravatar image sandeepROS  ( 2021-04-10 04:30:01 -0500 )edit

Ah, okay, I've updated my answer. That should work

parzival gravatar image parzival  ( 2021-04-10 05:22:50 -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-04-09 05:56:12 -0500

Seen: 274 times

Last updated: Apr 10 '21