3.12. Launch Files#

Launch files are exactly what they seem to be, files that are used for the intiiation of a ROS2 program. They are a way for the user to describe the configuration of their system and run it in the way that it was described in the file. Some information that launch files include are:

  • What programs to run.

  • Where to run said programs.

  • What arguments to pass into said programs (to initialize parameters).

  • ROS-specific conventions that make it a deal easier to reuse system components with different configurations.

Launch files also have the responsibility to monitor any process or program that has been launched. They report and, subsequently, react to any sudden changes that may arise during launch. They also have the ability to stop and trigger certain nodes at certain times. Launch files are usually written in Python, XML, or YAML, and you will become familiar with these programs later on.

3.13. TurtleSim Launch File Example#

Below is an example of a launch file for TurtleSim:

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='turtlesim',
            namespace='turtlesim1',
            executable='turtlesim_node',
            name='sim'
        ),
        Node(
            package='turtlesim',
            namespace='turtlesim2',
            executable='turtlesim_node',
            name='sim'
        ),
        Node(
            package='turtlesim',
            executable='mimic',
            name='mimic',
            remappings=[
                ('/input/pose', '/turtlesim1/turtle1/pose'),
                ('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
            ]
        )
    ])

This code can be broken up into different sections.

  • Imports: Pull in some predefined launch models for Python.

  • Actions: The first and second nodes in the launch description call for the launch of two TurtleSim windows. The third node calls for the launch for the TurtleSim remaps.

Once this is all written, one would run this file in the command prompt and launch TurtleSim.

3.14. Review Quiz#