UP | HOME

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:
    1. roslaunch package file.launch [arg_name:=value]...
    2. 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 starts roscore, if it is not already running.

Roslaunch options

Note: - roslaunch --help provides more options

  1. --nodes shows the nodes that are launched by the launchfile
  2. --args = NODE shows the arguments passed to run the Node
  3. --ros-args You can pass arguments to a launchfile (using arg_name:=value) to change the behavior of the launchfile. This flag shows all the possible arguments and their documentation.
  4. --files: Launchfiles can include other launchfiles. This shows which launchfiles a given launchfile includes.
  5. --find /node: Used to find which of the included launchfiles started the node with the given name.

Writing a Launchfile

  1. The Launchfile format relies on XML along with a special enhanced substitution argument syntax.
  2. Launchfiles list nodes to be launched; however, the order in which they start is non-deterministic.
  3. 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
  4. Conditionals:
  5. 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:

    1. $(env ENVIRONMENT_VARIABLE) Expands into the value of the environment variable
    2. $(find pkg)$ expands to the location of a given package. Useful for referencing a specific file in another package
    3. $(arg myarg)$ expands into the value of =myarg, as specified by an <arg> element and passed in on the call to roslaunch
    4. $(eval <expression>) Runs python code <expression> and expands to the result of the code evaluation
  6. roswtf can be used to check launchfiles: roswtf file.launch.

References

Author: Matthew Elwin.