Launch File

Launch files are used to launch a large system with many executables where an executable may contain multiple nodes. From a computing perspective, nodes or executables form a graph because the philosophy of ROS2 is to have independent modules that focus on a single responsibility. The communication between nodes are supported through message passing. From a launch process perspective, the executables and launch files form a tree structure.

Suppose we have a main launch file for our project learn-launch-file. This launch file can launch nodes/executables of the project learn-launch-file and run launch files in other projects. A more concrete example is presented below:

The syntax are different for these two types of tasks. To launch a node, we use the Node class. For example:

from launch_ros.actions import Node
robot_state_publisher = Node(
    package="robot_state_publisher",
    executable="robot_state_publisher",
    name="my_robot_state_publisher",
    output="both",
    parameters=[
        {"use_sim_time": True},
        {"robot_description": robot_model_description},
    ]
)

rviz = Node(
    package="rviz2",
    executable="rviz2",
    condition=IfCondition(LaunchConfiguration("rviz")),
    arguments=["-d", path.join(bringup_package, "config", "slam_and_nav_v1.rviz")]
)

To run another launch file inside our current launch file, we use IncludeLaunchDescription and PythonLaunchDescriptionSource. For example:

from launch.actions import IncludeLaunchDescription
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource

slam_toolbox = IncludeLaunchDescription(
    PythonLaunchDescriptionSource(path.join(get_package_share_directory("slam_toolbox"), "launch", "online_async_launch.py")),
    launch_arguments={
        'use_sim_time': "True",
        'slam_params_file': PathJoinSubstitution([bringup_package, "config", "mapper_params_online_async.yaml"])
    }.items(),
)

Last updated