ROS 2 Launch System

The ROS 2 Launch system

Content Outline

    Introduction


    You are using python to define a description of “actions”, but do not confuse it with action server or clients

    Frontents


    • Python
    • XML
    • YAML

    The Bare Minimum


    from launch import LaunchDescription
    
    def generate_launch_description() -> LaunchDescription:
    
        ld = LaunchDescription()
    
        return ld
    

    Launch “Actions”


    # List of all Launch Actions for Humble and Jazzy
    # from source: https://raw.githubusercontent.com/ros2/launch/humble/launch/launch/actions/__init__.py
    __all__ = [
        'AppendEnvironmentVariable',
        'DeclareLaunchArgument',
        'EmitEvent',
        'ExecuteLocal',
        'ExecuteProcess',
        'GroupAction',
        'IncludeLaunchDescription',
        'LogInfo',
        'OpaqueCoroutine',
        'OpaqueFunction',
        'PopEnvironment',
        'PopLaunchConfigurations',
        'PushEnvironment',
        'PushLaunchConfigurations',
        'ResetEnvironment',
        'ResetLaunchConfigurations',
        'RegisterEventHandler',
        'SetEnvironmentVariable',
        'SetLaunchConfiguration',
        'Shutdown',
        'TimerAction',
        'UnregisterEventHandler',
        'UnsetEnvironmentVariable',
        'UnsetLaunchConfiguration',
    ]
    from launch import LaunchDescription
    from launch.actions import LogInfo
    
    def generate_launch_description() -> LaunchDescription:
    
        ld = LaunchDescription()
    
        ld.add_action(
            LogInfo(msg="Hello Launch")
        )
    
        return ld
    

    ROS Launch Actions


    Node
    ComposableNodeContainer
    LoadComposableNodes
    LifecycleNode
    LifecycleTransition
    PushROSNamespace
    ROSTimer
    SetParameter
    SetParametersFromFile
    SetRemap
    SetROSLogDir
    SetUseSimTime
    

    Reminder:

    ros2 run <package> <executable> <arguments> --ros-args <ros_arguments> -r <remap from `remappings`> -p <param from `parameters`>
    launch_ros.actions.Node(
        package="<package>",
        executable="<executable>"
        exec_name="os_level_process_name"      # defaults to basename of executable
        name="<node_name>"                     # -r (--remap) __node:=<node_name>
        namespace="<your_namespace>",          # -r (--remap) __ns:=/<your_namespace> (the `/` is important)
        arguments=[                            # executable level arguments (if your executable supports them)
          "--config", "/tmp/my.cfg",
          "--rate", "20"
        ]
        ros_arguments=[                        # literally mirror `--ros-args` in the CLI
            "-r", "__ns:=/your_namespace",
            "--log-level", "warn",
            "--enclave", "/fully/qualified/path"
        ],
        parameters=[                           # these are node level parameters. Keep in mind that node parameters are typed
          {"node_param": <typed_value>},       # -p (--param) node_parameter:=<typed_value>
          "/path/with/node_parameter.yaml"     # you can pass path to a yaml file with node parameters
          {"other_param": <typed_value>},      # this `other_param` override the one in yaml (if used after it)
        ],
        remappings=[                           # you can remap anything. Due to name-resolution process, you can:
                                               # topics, services, actions, parameters, node name, namespace
          ('/some_topic', '/some_other_name'), # the full path resolution is /<namespace>/<your_remapping>
        ]
    )


    External Resources