If you pass the argument debug to your launch file roslaunch test.launch debug:=true
within your launch file $(launch-prefix)
will evaluate to gdb -ex run --args
,
otherwise it gets a string with one space inside " "
.
I'll break down these two lines and explain every part of it.
Where to find the sources of my answers?
A launch file in general will launch nodes thats defined in it. It includes other launch files to start a specific part of the system. If you need more information you can check out this source: http://wiki.ros.org/roslaunch/XML Here you find a decent explanation about all possibilities in launch files.
What is the <arg />
tag in ROS launch files for?
For a better reusablility of launch files you can react to command line parameters, which are passed from command line while running roslaunch
.
For example:
example_launch_file.launch
<launch>
<arg name="test" />
<node name="[NODE_NAME]" pkg="[PACKAGE_NAME]" type="[EXECUTABLE_NAME]">
<param name="test_arg_in_node" value="$(arg test)" />
</node>
</launch>
This example launch file will take a test
argument and passes this argument into parameters for the example node.
If you have created the launch file above, you are able to run roslaunch and pass the parameter. Run the following command:
roslaunch example_launch_file.launch test:=TestArgumentValue
Thus within the node a parameter named test_arg_in_node
is valued with TestArgumentValue
First line
<arg unless="$(arg debug)" name="launch-prefix" value=" "/>
unless
is the only attribute which is not mentioned above. This attribute declares the argument as conditioned. So if you pass debug
as true
or 1
the argument launch-prefix
will be NOT set.
Otherwise if debug
is false
or 0
, launch-prefix
evaluates to " "
.
My source for this part of the answer is this page http://wiki.ros.org/roslaunch/XML again and especially chapter 3. if and unless attributes
Second line
<arg if="$(arg debug)" name="launch-prefix" value="gdb -ex run --args"/>
if
is opposite to unless
which means that if $(arg debug)
is true
or 1
, argument launch-prefix
will BE set to "gdb -ex run --args"
.
Additional information
Both if
and unless
expecting one value of this set [true, 1, false, 0]
all other values will lead to an error. This is mentioned on this page as well: http://wiki.ros.org/roslaunch/XML
This line gdb -ex run --args
will bring up the c++ debugging tool gdb if you pass it to a node. In my view this is a topic of its own but in the following link you will get a good starting point: