ROS 2 Launch Files allow for the simultaneous startup and configuration of multiple ROS 2 nodes. The basic format involves importing necessary packages, creating a generate_launch_description() function, creating a LaunchDescription object, adding actions to the object, and returning the object. Launch files can be used to launch other launch files, execute terminal commands, and define launch configurations. Conditional launches can also be used to launch nodes based on specific argument values.

1. What are Launch Files?

ROS 2 Launch files allow you to start up and configure a number of executables containing ROS 2 nodes simultaneously. The launch system in ROS 2 is responsible for helping the user describe the configuration of their system and then execute it as described. The configuration of the system includes what programs to run, where to run them, what arguments to pass them, and ROS-specific conventions which make it easy to reuse components throughout the system by giving them each a different configuration. It is also responsible for monitoring the state of the processes launched, and reporting and/or reacting to changes in the state of those processes.

Begin with creating a directory to store your launch files. In this example, we will be using our ros_intermediate package.

cd ~/humble_ws/src/ros_intermediate
mkdir launch

Before beginning to create our launch file, we must confirm that the package knows that the launch directory needs to be included. Use the instructions in a. data_files to add the launch/ folder.

2. Basic Format

The basic format of a launch file is relatively simple.

  1. Import necessary packages
  2. Create generate_launch_description() function
  3. Create LaunchDescription object
  4. Add actions to LaunchDescription object
  5. return the LaunchDescription object.

The syntax of the generate_launch_description() function has to be exact, as ROS will look for this exact function definition to call the launch function.

The LaunchDescription object is populated with all your launch attributes. Declare this first, and use the add_action() function to populate it. This will allow your launch file to be much cleaner.

At the end of the function, return the LaunchDescription object to be passed into the launch.

3. Launching Nodes

<aside> 📒 Click on Orange text to learn more about the command

</aside>

ros2 run