Ask Your Question
5

Set delay between starting nodes within launch file

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

user23fj239 gravatar image

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

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

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

Is this technically possible?

edit retag flag offensive close merge delete

Comments

1

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 -0500 )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 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
8

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

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

Comments

Thank you! That worked for me!

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

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

tik0 gravatar image

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

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:

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

Content of my_listener.launch

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

Comments

just what is was looking for

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

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

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

Comments

2

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 -0500 )edit

Yes that is correct

l0g1x gravatar imagel0g1x ( 2016-05-06 13:06:07 -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

3 followers

Stats

Asked: 2016-05-01 07:08:15 -0500

Seen: 8,277 times

Last updated: Feb 21