Evaluation order
roslaunch evaluates the XML file in a single pass. Includes are processed in depth-first traversal order. Tags are evaluated serially and the last setting wins. Thus, if there are multiple settings of a parameter, the last value specified for the parameter will be used.
最后设置的参数值会覆盖前面设置的 。
Relying on the override behavior can be brittle. There is no guarantee that an override is specified correctly (e.g. if a parameter name is changed in an included file). Instead, it is recommended that override behavior be done using $(arg)/ settings.
substitution args
参数替换
Roslaunch tag attributes can make use of substitution args, which roslaunch will resolve prior to launching nodes. The currently supported substitution args are:
$(env ENVIRONMENT_VARIABLE)
#Substitute the value of a variable from the current environment. The launch will
fail if environment variable is not set. This value cannot be overridden by <env>
tags.
$(optenv ENVIRONMENT_VARIABLE) $(optenv ENVIRONMENT_VARIABLE default_value)
#Substitute the value of an environment variable if it is set. If default_value is
provided, it will be used if the environment variable is not set. If default_value
is not provided, an empty string will be used. default_value can be multiple words
separated by spaces.
#Examples:
<param name="foo" value="$(optenv NUM_CPUS 1)" />
<param name="foo" value="$(optenv CONFIG_PATH /home/marvin/ros_workspace)" />
<param name="foo" value="$(optenv VARIABLE ros rocks)" />
$(find pkg)
#e.g. $(find rospy)/manifest.xml. Specifies a package-relative path. The filesystem
path to the package directory will be substituted inline. Use of package-relative
paths is highly encouraged as hard-coded paths inhibit the portability of the launch
configuration. Forward and backwards slashes will be resolved to the local
filesystem convention.
$(anon name)
#e.g. $(anon rviz-1). Generates an anonymous id based on name. name itself is a
unique identifier: multiple uses of $(anon foo) will create the same "anonymized"
name. This is used for <node> name attributes in order to create nodes with
anonymous names, as ROS requires nodes to have unique names.
#For example:
<node name="$(anon foo)" pkg="rospy_tutorials" type="talker.py" />
<node name="$(anon foo)" pkg="rospy_tutorials" type="talker.py" />
$(arg foo)
#$(arg foo) evaluates to the value specified by an <arg> tag. There must be a corresponding <arg> tag in the same launch file that declares the arg.
For example:
<param name="foo" value="$(arg my_foo)" />
Will assign the my_foo argument to the foo parameter.
Another example:
<node name="add_two_ints_server" pkg="beginner_tutorials" type="add_two_ints_server" />
<node name="add_two_ints_client" pkg="beginner_tutorials" type="add_two_ints_client" args="$(arg a) $(arg b)" />
Will launch both the server and client from the <add_two_ints> example, passing as
parameters the value a and b. The resulting launch project can be called as follows:
roslaunch beginner_tutorials launch_file.launch a:=1 b:=5
$(eval <expression>)
#$(eval <expression>) allows to evaluate arbitrary complex python expressions.
For example:
<param name="circumference" value="$(eval 2.* 3.1415 * arg('radius'))"/>
Will compute the circumference from the radius argument and assign the result to an
appropriate parameter.
Note: As a limitation, $(eval) expressions need to span the whole attribute string. A
mixture of other substitution args with eval within a single string is not possible:
<param name="foo" value="$(arg foo)$(eval 6*7)bar"/>
To remedy this limitation, all substitution commands are available as functions within
eval as well:
"$(eval arg('foo') + env('PATH') + 'bar' + find('pkg')"
For your convenience, arguments are also implicitly resolved, i.e. the following two
expressions are identical:
"$(eval arg('foo'))"
"$(eval foo)"
$(dirname)
#$(dirname) returns the absolute path to the directory of the launch file in which
it appears. This can be used in conjunction with eval and if/unless to modify
behaviour based on the installation path, or simply as a convenience for referencing launch or yaml files relative to the current file rather than relative to a
package root (as with $(find PKG)).
For example:
<include file="$(dirname)/other.launch" />
Will expect to find other.launch in the same directory as the launch file which it
appears in.
Substitution args are currently resolved on the local machine. In other words, environment variables and ROS package paths will be set to their values in your current environment, even for remotely launched processes.
if and unless attributes
All tags support if and unless attributes, which include or exclude a tag based on the evaluation of a value. “1” and “true” are considered true values. “0” and “false” are considered false values. Other values will error.
if=value (optional)
#If value evaluates to true, include tag and its contents.
unless=value (optional)
#Unless value evaluates to true (which means if value evaluates to false), include
tag and its contents.
<group if="$(arg foo)">
<!-- stuff that will only be evaluated if foo is true -->
</group>
<param name="foo" value="bar" unless="$(arg foo)" /> <!-- This param won't be set when "unless" condition is met -->
Tag Reference
.launch文件中包含的tag有:
<launch>
<node>
<machine>
<include>
<remap>
<env>
<param>
<rosparam>
<group>
<test>
<arg>
后面一节是具体每个tag的用法。