Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

What is the meaning of this line in the launch file (ROS)

what this line means? And could explain it? Thanks!

<arg unless="$(arg debug)" name="launch-prefix" value=" "/>
<arg if="$(arg debug)" name="launch-prefix" value="gdb -ex run --args"/>
question from:https://stackoverflow.com/questions/65944121/what-is-the-meaning-of-this-line-in-the-launch-file-ros

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...