Launchfiles
Launchfiles and ROS
- ROS programs consist of many nodes communicating over topics and services
- For non-trivial programs, manually running nodes using
rosrun
becomes tedious and hard to reproduce - Launchfiles solve this problem by enabling you to specify
- Which nodes are run
- What parameters they use
- What topics are named
- and more!
Using roslaunch
- The command-line tool for using launch files is roslaunch.
- There are two ways of invoking a launchfile:
roslaunch package file.launch [arg_name:=value]...
roslaunch package /path/to/launch/file.launch [arg_name:=value...]
- Here, the launch file at the given location is directly used.
- This method is not used very often
- You can pass arguments to a launch file using the
arg_name:=value
syntax, which is shared with the remapping arguments syntax. roslaunch
automatically startsroscore
, if it is not already running.
Roslaunch options
Note: - roslaunch --help
provides more options
--nodes
shows the nodes that are launched by the launchfile--args = NODE
shows the arguments passed to run the Node--ros-args
You can pass arguments to a launchfile (usingarg_name:=value
) to change the behavior of the launchfile. This flag shows all the possible arguments and their documentation.--files
: Launchfiles can include other launchfiles. This shows which launchfiles a given launchfile includes.--find /node
: Used to find which of the included launchfiles started the node with the given name.
Writing a Launchfile
- The Launchfile format relies on XML along with a special enhanced substitution argument syntax.
- Launchfiles list nodes to be launched; however, the order in which they start is non-deterministic.
- Important Launchfile XML elements:
- <launch> - the root element, every launchfile starts with this
- <node> - Used to run a node.
Attributes:
- pkg: the package the node is in
- type: the name of the node executable file
- name: the basename of the node
- ns: the node's namespace
- output: determine where to send the output to (a log file or the screen)
- required: if the node dies, the whole roslaunch is terminated
- <include> - Lets you include a launchfile in another launchfile
- <remap> - Used for Remapping arguments
- <param> - Sets an individual parameter on the parameter server
- <rosparam> - Controls groups of parameters using
.yaml
files. - <group> - Groups nodes together and allows you to easily apply common settings
- <arg> - Used to specify arguments which can be used to change the behavior of the launchfile from the command-line
- <machine> - Used to specify a remote machine upon which nodes will be run
- <env> - Used to set environment variables for the underlying node
- Conditionals:
- Conditional Attributes All elements have attributes
if
andunless
to be conditionally included.
- Conditional Attributes All elements have attributes
Substitution arguments: The following items can be used within attribute values to perform a computation and expand into the result of that computation The general syntax uses
$()
(just like bash substitution arguments. Within XML, a substitution argument would be used like<tag attribute ="$()" />
.A list of some possible substitution arguments is below:
$(env ENVIRONMENT_VARIABLE)
Expands into the value of the environment variable$(find pkg)$
expands to the location of a given package. Useful for referencing a specific file in another package$(arg myarg)$ expands into the value of =myarg
, as specified by an<arg>
element and passed in on the call toroslaunch
$(eval <expression>)
Runs python code<expression>
and expands to the result of the code evaluation
- roswtf can be used to check launchfiles:
roswtf file.launch
.