在roslaunch的.launch xml文件中,包含很多的tag,下面是每个tag使用的介绍。
<launch>
tag
the <launch>
tag is the root element of any roslaunch file. Its sole purpose is to act as a container for the other elements.
①Attributes
deprecated="deprecation message"
ROS 1.1: warn users that roslaunch file is deprecated.
②Elements
<node>
#Launch a node.
<param>
#Set a parameter on the Parameter Server
<remap>
#Declare a name remapping.
<machine>
#Declare a machine to use for launching.
<rosparam>
#Set ROS parameters for the launch using a rosparam file.
<include>
#Include other roslaunch files.
<env>
#Specify an environment variable for launched nodes.
<test>
#Launch a test node (see rostest).
<arg>
#Declare an argument.
<group>
#Group enclosed elements sharing a namespace or remap.
<node>
tag
The <node>
tag specifies a ROS node that you wish to have launched. This is the most common roslaunch tag as it supports the most important features: bringing up and taking down nodes.
roslaunch does not provide any guarantees about what order nodes start in. This is intentional: there is no way to externally know when a node is fully initialized, so all code that is launched must be robust to launching in any order.
例子,
<node name="listener1" pkg="rospy_tutorials" type="listener.py" args="--test" respawn="true" />
Launches the “listener1” node using the listener.py executable from the rospy_tutorials package with the command-line argument –test. If the node dies, it will automatically be respawned.
<node name="bar1" pkg="foo_pkg" type="bar" args="$(find baz_pkg)/resources/map.pgm" />
Launches the bar node from the foo_pkg package. This example uses substitution arguments to pass in a portable reference to baz_pkg/resources/map.pgm.
①Attributes
pkg="mypackage"
#Package of node.
type="nodetype"
#Node type. There must be a corresponding executable with the same name.
name="nodename"
#Node name. NOTE: name cannot contain a namespace. Use the ns attribute instead.
args="arg1 arg2 arg3"(optional)
#Pass arguments to node.
machine="machine-name"(optional, see <machine>)
#Launch node on designated machine.
respawn="true"(optional)
#Restart the node automatically if it quits.
respawn_delay="30" (optional, default 0) New in ROS indigo
#If respawn is true, wait respawn_delay seconds after the node failure is detected
before attempting restart.
required="true"(optional)
#ROS 0.10: If node dies, kill entire roslaunch.
ns="foo"(optional)
#Start the node in the 'foo' namespace.
clear_params="true|false"(optional)
#Delete all parameters in the node's private namespace before launch.
output="log|screen"(optional)
#If 'screen', stdout/stderr from the node will be sent to the screen. If 'log', the
stdout/stderr output will be sent to a log file in $ROS_HOME/log, and stderr will
continue to be sent to screen. The default is 'log'.
cwd="ROS_HOME|node"(optional)
#If 'node', the working directory of the node will be set to the same directory as
the node's executable. In C Turtle, the default is 'ROS_HOME'. In Box Turtle (ROS
1.0.x), the default is 'ros-root'. The use of 'ros-root' is deprecated in C Turtle.
launch-prefix="prefix arguments"(optional)
#Command/arguments to prepend to node's launch arguments. This is a powerful feature
that enables you to enable gdb, valgrind, xterm, nice, or other handy tools. See
Roslaunch Nodes in Valgrind or GDB for examples.
②Elements
You can use the following XML tags inside of a <node>
tag:
<env>
#Set an environment variable for the node.
<remap>
#Set a remapping argument for this node.
<rosparam>
#Load a rosparam file into this node's ~/local namespace.
<param>
#Set a parameter in the node's ~/local namespace.
<machine>
tag
The <machine>
tag declares a machine that you can run ROS nodes on. You do not need this tag if you are launching all the nodes locally. It is mainly used to declare SSH and ROS environment variable settings for remote machines, though you can also use it to declare information about the local machine.
①Attributes
name="machine-name"
#Name to assign to machine. This corresponds to the name used for the machine
attribute for <node> tags.
address="blah.willowgarage.com"
#Network address/hostname of machine.
env-loader="/opt/ros/fuerte/env.sh" New in Fuerte
#Specify environment file on remote machine. Environment file must be a shell script
that sets all required environment variables, then runs exec on the provided
arguments. For an example file, see the env.sh that is provided with debian
installs of ROS Fuerte. See below for an example env-loader.
default="true|false|never" (optional)
#Sets this machine as the default to assign nodes to. The default setting only
applies to nodes defined later in the same scope. NOTE: if there are no default
machines, the local machine is used. You can prevent a machine from being chosen by
setting default="never", in which case the machine can only be explicitly assigned.
user="username" (optional)
#SSH user name for logging into machine. May be omitted if not required.
password="passwhat"(strongly discouraged)
#SSH password. It is highly recommended that you configure SSH keys and SSH agent
instead so you can login with certificates instead.
timeout="10.0" (optional)
#Number of seconds before a roslaunch on this machine is considered as having failed
to launch. By default, this is 10 seconds. While you can use this setting to allow
for slower connections, needing to change this parameter is generally a symptom that
your overall ROS graph will have communication issues.
The following attributes are available in ROS Electric and earlier:
ros-root="/path/to/ros/root/" (optional)
#ROS_ROOT for machine. Defaults to the ROS_ROOT set in the local environment.
ros-package-path="/path1:/path2" (optional)
#ROS_PACKAGE_PATH for machine. Defaults to the ROS_PACKAGE_PATH set in the local environment.
②Elements
Electric and earlier only: You can use the following XML tags inside of a <machine>
tag:
<env>
#Set an environment variable on all processes launched on this machine.
例子,
The syntax of the <machine>
tag is very different in ROS Electric, so please pay attention to the version indicator in the examples below.
Basic (ROS Electric and Previous Only)
The following example below shows configuring a node “footalker” to run another machine. In addition to overriding the ROS_ROOT and ROS_PACKAGE_PATH that the machine will use, the example also sets a LUCKY_NUMBER environment variable on the remote machine.
<launch>
<machine name="foo" address="foo-address" ros-root="/u/user/ros/ros/" ros-package-path="/u/user/ros/ros-pkg" user="someone">
<env name="LUCKY_NUMBER" value="13" />
</machine>
<node machine="foo" name="footalker" pkg="test_ros" type="talker.py" />
</launch>
Basic (ROS Fuerte and later) using env-loader
he following example below shows configuring a node “footalker” to run another machine. It uses the default env-loader file that comes with Fuerte.
<launch>
<machine name="foo" address="foo-address" env-loader="/opt/ros/fuerte/env.sh" user="someone"/>
<node machine="foo" name="footalker" pkg="test_ros" type="talker.py" />
</launch>
Here is an example env-loader script. Replace /opt/ros/fuerte/setup.sh with a different setup file if you wish to use a different environment configuration:
#!/bin/sh
. /opt/ros/fuerte/setup.sh
exec "$@"
Alternatively, if you prefer to source from a rosws workspace:
#!/usr/bin/env bash
source /home/username/path/to/workspace/setup.bash
exec "$@"
<include>
tag
The <include>
tag enables you to import another roslaunch XML file into the current file. It will be imported within the current scope of your document, including <group>
and <remap>
tags. All content in the include file will be imported except for the <master>
tag: the <master>
tag is only obeyed in the top-level file.
①Attributes
file="$(find pkg-name)/path/filename.xml"
#Name of file to include.
ns="foo" (optional)
#Import the file relative to the 'foo' namespace.
clear_params="true|false" (optional Default: false)
#Delete all parameters in the <include>'s namespace before launch. This feature is
very dangerous and should be used with caution. ns must be specified. Default:
false.
pass_all_args="true|false" (optional Default: false)
#If true, then all args set in the current context are added to the child context
that is created for processing the included file. You can do this instead of
explicitly listing each argument that you want to pass down.
②Elements
<env>
#Set an environment variable on across the entire included file.
<arg>
#Pass an argument to the included file.
<remap>
tag
The <remap>
tag allows you to pass in name remapping arguments to the ROS node that you are launching in a more structured manner than setting the args attribute of a <node>
directly. The <remap>
tag applies to all subsequent declarations in its scope (<launch>, <node> or <group>
).
①Attributes
from="original-name"
#Name that you are remapping.
to="new-name"
#Target name.
例子,
For example, you are given a node that says it subscribes to the “chatter” topic, but you only have a node that publishes the “hello” topic. They are the same type, and you want to pipe your “hello” topic into the new node which wants “chatter” by simply:
<remap from="chatter" to="hello"/>
<env>
tag (deprecated)
The <env>
tag is deprecated since Fuerte. Use env-loader instead.
The <env>
tag allows you to set environment variables on nodes that are launched. This tag may only be used within the scope of a <launch>, <include>, <node> or <machine>
tag. When it is used inside of a <launch>
tag, the <env>
tag only applies to nodes declared after.
① Attributes
name="environment-variable-name"
#Environment variable you are setting.
value="environment-variable-value"
#Value to set the environment variable to.
<param>
tag
The <param>
tag defines a parameter to be set on the Parameter Server. Instead of value, you can specify a textfile, binfile or command attribute to set the value of a parameter. The <param>
tag can be put inside of a <node>
tag, in which case the parameter is treated like a private parameter.
You can also set private parameter across a group of nodes by using the ~param syntax (see ROS names) in a <param>
tag. The declared parameter will be set as a local parameter in the <node>
tags that follow that are in the same scope (i.e. group or ns tag).
①Attributes
name="namespace/name"
#Parameter name. Namespaces can be included in the parameter name, but globally
specified names should be avoided.
value="value"(optional)
#Defines the value of the parameter. If this attribute is omitted, binfile, textfile
or command must be specified.
type="str|int|double|bool|yaml"(optional)
#Specifies the type of the parameter. If you don't specify the type, roslaunch will
attempt to automatically determine the type. These rules are very basic:
numbers with '.'s are floating point, integers otherwise;
"true" and "false" are boolean (not case-sensitive).
all other values are strings
textfile="$(find pkg-name)/path/file.txt"(optional)
#The contents of the file will be read and stored as a string. The file must be
locally accessible, though it is strongly recommended that you use the package-
relative $(find)/file.txt syntax to specify the location.
binfile="$(find pkg-name)/path/file"(optional)
#The contents of the file will be read and stored as a base64-encoded XML-RPC binary
object. The file must be locally accessible, though it is strongly recommended that
you use the package-relative $(find)/file.txt syntax to specify the location.
command="$(find pkg-name)/exe '$(find pkg-name)/arg.txt'"(optional)
#The output of the command will be read and stored as a string. It is strongly
recommended that you use the package-relative $(find)/file.txt syntax to specify
file arguments. You should also quote file arguments using single quotes due to XML
escaping requirements.
例子,
<param name="publish_frequency" type="double" value="10.0" />
In order to load a YAML file, you can use:
<rosparam command="load" file="FILENAME" />
But this doesn’t work when using a command which outputs the parameters on stdout. In that case the new param type yaml can be used:
<param name="params_a" type="yaml" command="cat "$(find roslaunch)/test/params.yaml"" />
<rosparam>
tag
The <rosparam>
tag enables the use of rosparam YAML files for loading and dumping parameters from the ROS Parameter Server. It can also be used to remove parameters. The <rosparam>
tag can be put inside of a <node>
tag, in which case the parameter is treated like a private name.
The delete and dump commands run before the load command as well as before any other parameters are uploaded to the Parameter Server. delete and dump commands run in the declared order.
The load command is considered additive: if you declare a dictionary or namespace of parameters, those parameters will be added to any other parameters declared for that namespace. Similarly, load commands can override parameters previously declared.
The <rosparam>
tag can either reference a YAML file or contain raw YAML text. If the YAML text defines a dictionary, the param attribute may be omitted.
①Attributes
command="load|dump|delete" (optional, default=load)
#rosparam command.
file="$(find pkg-name)/path/foo.yaml" (load or dump commands)
#Name of rosparam file.
param="param-name"
#Name of parameter.
ns="namespace" (optional)
#Scope the parameters to the specified namespace.
subst_value=true|false (optional)
#Allows use of substitution args in the YAML text.
例子,
<rosparam command="load" file="$(find rosparam)/example.yaml" />
<rosparam command="delete" param="my/param" />
<rosparam param="a_list">[1, 2, 3, 4]</rosparam>
<rosparam>
a: 1
b: 2
</rosparam>
Substitution allows you to make use of roslaunch args representing all or part of a YAML string. e.g.
<arg name="whitelist" default="[3, 2]"/>
<rosparam param="whitelist" subst_value="True">$(arg whitelist)</rosparam>
They are also useful for embedding $(find …) in yaml strings and to a lesser extent any of the other substitution patterns.
Example of accessing a list in roscpp code:
XmlRpc::XmlRpcValue v;
nh_.param("subscribed_to_nodes", v, v);
for(int i =0; i < v.size(); i++)
{
node_names_.push_back(v[i]);
std::cerr << "node_names: " << node_names_[i] << std::endl;
}
<group>
tag
The <group>
tag makes it easier to apply settings to a group of nodes. It has an ns attribute that lets you push the group of nodes into a separate namespace. You can also use the <remap>
tag to apply remap setting across the group.
①Attributes
ns="namespace" (optional)
#Assign the group of nodes to the specified namespace. The namespace can be global
or relative, though global namespaces are discouraged.
clear_params="true|false" (optional)
#Delete all parameters in the group's namespace before launch. This feature is very
dangerous and should be used with caution. ns must be specified.
②Elements
The <group>
tag is equivalent to the top-level <launch>
tag and simply acts as a container for the tags within. This means that you can use any tag as you would normally use it within a <launch>
tag.
<node>
#Launch a node.
<param>
#Set a parameter on the Parameter Server
<remap>
#Declare a name remapping.
<machine>
#Declare a machine to use for launching.
<rosparam>
#Set ROS parameters for the launch using a rosparam file.
<include>
#Include other roslaunch files.
<env>
#Specify an environment variable for launched nodes.
<test>
#Launch a test node (see rostest).
<arg>
#Declare an argument.
<arg>
tag
The <arg>
tag allows you to create more re-usable and configurable launch files by specifying values that are passed via the command-line, passing in via an <include>
, or declared for higher-level files. Args are not global. An arg declaration is specific to a single launch file, much like a local parameter in a method. You must explicitly pass arg values to an included file, much like you would in a method call. <arg>
can be used in one of three ways:
<arg name="foo" />
#Declares the existence of foo. foo must be passed in either as a command-line
argument (if top-level) or via <include> passing (if included).
<arg name="foo" default="1" />
#Declares foo with a default value. foo can be overriden by command-line argument
(if top-level) or via <include> passing (if included).
<arg name="foo" value="bar" />
#Declares foo with constant value. The value for foo cannot be overridden. This
usage enables internal parameterization of a launch file without exposing that
parameterization at higher levels.
①Attributes
name="arg_name"
#Name of argument.
default="default value" (optional)
#Default value of argument. Cannot be combined with value attribute.
value="value" (optional)
#Argument value. Cannot be combined with default attribute.
doc="description for this arg" (optional) New in Indigo
#Description of the argument.
例子,
Passing an argument to an included file,
my_file.launch:
<include file="included.launch">
<!-- all vars that included.launch requires must be set -->
<arg name="hoge" value="fuga" />
</include>
included.launch:
<launch>
<!-- declare arg to be passed in -->
<arg name="hoge" />
<!-- read value of arg -->
<param name="param" value="$(arg hoge)"/>
</launch>
Passing an argument via the command-line,
roslaunch uses the same syntax as ROS remapping arguments to specify arg values.
$ roslaunch my_file.launch hoge:=my_value (.launch file is available at the current dir)
$ roslaunch %YOUR_ROS_PKG% my_file.launch hoge:=my_value