ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Better late than never! I came across a similar issue and have implemented a convenient solution. Hopefully many more people can use it, as I find it to be very helpful!
How to use it?
Save the script shown below to a file named "timed_roslaunch.sh". Put it in a scripts/ subfolder of your catkin package. Make it executable using chmod +x. And use it either through command line or a launch file. The scripts help (./timed_roslaunch.sh -h) is shown below:
This script can delay the launch of a roslaunch file
Place it in the 'scripts' folder of your catkin package
and make sure that the file is executable (chmod +x timed_roslaunch.sh)
Run it from command line:
Use: ./timed_roslaunch.sh [number of seconds to delay] [rospkg] [roslaunch file] [arguments (optional)]
Or: rosrun [yourpackage] time_roslaunch.sh [number of seconds to delay] [rospkg] [roslaunch file] [arguments (optional)]
Example: ./timed_roslaunch.sh 2 turtlebot_navigation amcl_demo.launch initial_pose_x:=17.0 initial_pose_y:=17.0
Or run it from another roslaunch file:
<launch>
<arg name="initial_pose_y" default="17.0" />
<node pkg="semantic_turtle_test" type="timed_roslaunch.sh"
args="2 turtlebot_navigation amcl_demo.launch initial_pose_x:=17.0 initial_pose_y:=$(arg initial_pose_y)"
name="timed_roslaunch" output="screen">
</node>
</launch>
The script or use this link.
#!/bin/bash
#
# Script to delay the launch of a roslaunch file
#
# Koen Lekkerkerker
# Thu 24 Apr 2014
#
# Use: ./timed_roslaunch.sh [number of seconds to delay] [rospkg] [roslaunch file]
#
function showHelp(){
echo
echo "This script can delay the launch of a roslaunch file"
echo "Place it in the 'scripts' folder of your catkin package"
echo "and make sure that the file is executable (chmod +x timed_roslaunch.sh)"
echo
echo "Run it from command line:"
echo
echo "Use: ./timed_roslaunch.sh [number of seconds to delay] [rospkg] [roslaunch file] [arguments (optional)]"
echo "Or: rosrun [yourpackage] time_roslaunch.sh [number of seconds to delay] [rospkg] [roslaunch file] [arguments (optional)]"
echo "Example: ./timed_roslaunch.sh 2 turtlebot_navigation amcl_demo.launch initial_pose_x:=17.0 initial_pose_y:=17.0"
echo
echo "Or run it from another roslaunch file:"
echo
echo '<launch>'
echo ' <arg name="initial_pose_y" default="17.0" />'
echo ' <node pkg="semantic_turtle_test" type="timed_roslaunch.sh"'
echo ' args="2 turtlebot_navigation amcl_demo.launch initial_pose_x:=17.0 initial_pose_y:=$(arg initial_pose_y)"'
echo ' name="timed_roslaunch" output="screen">'
echo ' </node>'
echo '</launch>'
}
if [ "$1" = "-h" ]; then
showHelp
else
echo "start wait for $1 seconds"
sleep $1
echo "end wait for $1 seconds"
shift
echo "now running 'roslaunch $@'"
roslaunch $@
fi
Now why did I need it?
My problem was that when I have launch script to launch a fairly large project. Gazebo simulates a world with a simulated turtlebot and gmapping is used for mapping it. It seems that gazebo returns laser measurements before the whole world is spawn. The robot is in a corridor, but as the walls are spawned later than the laser, the first laser measurements give a full free circle. As gmapping already processed these measurements, gmapping incorrectly mapped this circle as free space.
See screenshot: