Ask Your Question

Set delay between starting nodes within launch file

asked 2016-05-01 07:08:15 -0600

user23fj239 gravatar image

updated 2016-05-01 07:08:45 -0600

I would like to put my nodes inside a launch file. The first node need to be up and running before the second node. Is it possible to set some timeout before the second starts. Like usleep(time) in roscpp

<node name="talker" pkg="roscpp_tutorials" type="talker" />
//delay of e.g. 1second
<node name="listener" pkg="roscpp_tutorials" type="listener" />

Is this technically possible?

edit retag flag offensive close merge delete



Ros has no such feature. Why do you need this function? What do you really want to achieve? Having hardcoded dependencies like this is a bad sign. What happens to your second node if the first one has to be restarted?

NEngelhard gravatar imageNEngelhard ( 2016-05-01 08:41:41 -0600 )edit

Thank you, but I do not face dependencies, this was about is it theoretically possible. E.g. holding a presentation and not wanting to go to the pc. I say some stuff about the window popping up of the first node, then after 30s I can gently move over the the second. But this is ok.

user23fj239 gravatar imageuser23fj239 ( 2016-05-01 09:02:46 -0600 )edit

A potential proper solution is for one node to wait until another node is ready before properly starting up, similar to how rosservice call --wait works. You can probably also use a service to indicate whether a node has started up. In fact, it'd probably be nice if nodes by default took a "wait" arg that allows setting dependencies between nodes

Rufus gravatar imageRufus ( 2020-01-09 19:34:12 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2019-02-21 10:35:58 -0600

kushlik gravatar image

I found a one-line solution that does not require any additional packages (it was a bit tricky):

You can make use of launch-prefix feature like so:

<arg name="node_start_delay" default="1.0" />  
<node name="listener" pkg="roscpp_tutorials" type="listener" launch-prefix="bash -c 'sleep $(arg node_start_delay); $0 $@' " />

the problem with using just launch-prefix="sleep 1.0; " was that the node launching command was passed as arguments to 'sleep'

edit flag offensive delete link more


Thank you! That worked for me!

Rosbq gravatar imageRosbq ( 2019-05-29 08:17:18 -0600 )edit

answered 2018-03-19 08:36:23 -0600

tik0 gravatar image

updated 2018-03-19 11:05:55 -0600

You can perform a workaround by putting the delayed node into an extra launch file and run it via timed_roslaunch. Explanation goes here. Script is available here.

In your case:

<node name="talker" pkg="roscpp_tutorials" type="talker" />
<node pkg="timed_roslaunch" type="" args="1 roscpp_tutorials my_listener.launch" name="timed_roslaunch" output="screen" />

Content of my_listener.launch

<node name="listener" pkg="roscpp_tutorials" type="listener" />
edit flag offensive delete link more


just what is was looking for

jeremysmorgan gravatar imagejeremysmorgan ( 2018-12-11 15:04:00 -0600 )edit

answered 2016-05-05 22:06:57 -0600

l0g1x gravatar image

Currently there is no such implementation. However, this was a topic brought up at the last ROS Live meeting, and seems that the idea is to try and allow a user to have more 'coding' freedom from within a launch file. I have seen some workarounds that people have posted in the past, and what they did was created a regular bash script that called roslaunch files from within itself, as it was easier (or maybe currently the only way) to implement a delay between roslaunch starts.

edit flag offensive delete link more



To slightly clarify @l0g1x's answer, he means delaying by adding commands of the form sleep 5 (delay of 5 sec) between the desired roslaunch / rosrun commands in the bash script. (Right?)

spmaniato gravatar imagespmaniato ( 2016-05-06 07:42:09 -0600 )edit

Yes that is correct

l0g1x gravatar imagel0g1x ( 2016-05-06 13:06:07 -0600 )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: 2016-05-01 07:08:15 -0600

Seen: 9,666 times

Last updated: Feb 21 '19