Page 1 of 1

Launching multiple nodes

PostPosted: Tue 29. Jul 2014, 15:26
by joma
Hello,
I have tried to start multiple ROS nodes to solve a challenge by a launch file. This works well so far.
I'm now facing problems while automatically starting this nodes by /opt/euroc_c2s1/startup script. I replaced "rosrun euroc_c2_demos euroc_c2_demo "$@"" with "roslaunch mypackage mylaunch.launch" in the script. The problem now is that even if my nodes are terminating after all challenges the roslaunch task still keeps running and so the next line in the script given by "rosrun euroc_c2_demos euroc_c2_demo "$@"" is never called.
How is it supposed to start more then one node to solve the tasks by not calling rosrun for every single node from the startup script?
Is there any workaround so that I can use launchfiles instead of starting every single node by hand?

Thanks

Johannes

Posted: Tue 29. Jul 2014, 15:26
by Advertising

Re: Launching multiple nodes

PostPosted: Wed 30. Jul 2014, 09:34
by Peter Lehner
Hello Johannes,

I would suggest to start the launch file in the background. Then start a blocking node via rosrun which waits for some condition (message on a topic / service call) of your other nodes. Once the condition triggers the node terminates and unblocks the script. E.g:

Code: Select all
...
roslaunch your_package your.launch &  # Launching your nodes in the background
rosrun your_package blocking_node # Running the blocking node which waits for the condition
...


blocking_node could then look something like this (message example):

Code: Select all
#!/usr/bin/env python

import rospy
from std_msgs.msg import Empty
   
def blocker():
    rospy.init_node("blocker")
    rospy.wait_for_message("tasks_completed", Empty)
       
if __name__ == '__main__':
    blocker()


The node waits for the first message published to the "tasks_completed" topic and then terminates.

Re: Launching multiple nodes

PostPosted: Fri 1. Aug 2014, 21:11
by joma
Hi,
thanks for the hint. I think this will work for us. I will test it on Monday and give some feedback.

Best Regards
Johannes