Atlas Robotics
ROS2 PackageIntermediate

Launch files in ROS2 — starting multiple nodes at once

Atlasbot · 17/8/2026 · 11 min read

Launch files in ROS2 — starting multiple nodes at once
One launch file starts multiple nodes at the same time

Mecanum Robot or Diff Robot in the project showcase both run many nodes in parallel: motor driver, LiDAR, SLAM, Nav2... Opening each terminal and typing ros2 run for each node is impractical. Launch file solves this problem — declare all the nodes to run, with parameters, in a Python file, started with a command ros2 launch.

Key concepts

Place in folder launch/ of the package, for example launch/bringup.launch.py:

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package="my_cpp_pkg",
            executable="hello_node",
            name="hello_node",
            output="screen",
        ),
        Node(
            package="my_py_pkg",
            executable="hello_node",
            name="hello_node_py",
            output="screen",
        ),
    ])

Powered by:

ros2 launch my_cpp_pkg bringup.launch.py

The function must be named generate_launch_description() — this is the entry point that ros2 launch finds and calls. Each Node(...) element is equivalent to one manual ros2 run <package> <executable> typing.

Just writing the file is not enough — you must declare install to launch the file copied to install/ when building:

install(DIRECTORY launch
  DESTINATION share/${PROJECT_NAME})

For Python package, equivalent in setup.py:

data_files=[
    ("share/" + package_name + "/launch",
     ["launch/bringup.launch.py"]),
],

Summary: Forgetting to declare install(DIRECTORY launch ...) (C++) or data_files (Python) is a very common error — the Python code launches the file with correct syntax but ros2 launch reports "package 'X' not found" because the file has never been copied to install/.

How it works

Pass parameters and include another launch file:

from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    use_sim = DeclareLaunchArgument("use_sim", default_value="false")

    driver_node = Node(
        package="my_cpp_pkg",
        executable="hello_node",
        parameters=[{"use_sim": LaunchConfiguration("use_sim")}],
    )

    nav2 = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(["/path/to/nav2_bringup/launch/bringup_launch.py"])
    )

    return LaunchDescription([use_sim, driver_node, nav2])
  • DeclareLaunchArgument — declares a command line parameter to the launch file itself (ros2 launch my_pkg bringup.launch.py use_sim:=true)
  • IncludeLaunchDescription — embedding another launch file in its entirety — standard way to "assemble" a large launch file (eg system-wide bringup) from many small launch files of each subpackage, instead of copying and pasting the entire node

Technical details

Parameters

Summary of the most commonly used actions when writing launch files:

ActionUsed to
NodeRuns a ROS2 executable
DeclareLaunchArgumentDeclare command line parameters for launch file
IncludeLaunchDescriptionEmbed another launch file
TimerActionDelay running an action by N seconds
LogInfoPrint log to terminal when launching
ExecuteProcessRun any process that is not a ROS2 node (eg shell script)
GroupActionGroup multiple nodes into one namespace or enable/disable condition

Practical applications

The actual launch file architecture of an AMR usually follows a layered model: 1 root launch file bringup.launch.py uses IncludeLaunchDescription to combine many child launch files — sensors.launch.py (launch LiDAR, camera, IMU), navigation.launch.py (Nav2), safety.launch.py (safety monitoring node) — each child launch file can be tested independently set up, and the original launch file uses DeclareLaunchArgument (eg: use_sim_time, enable_camera) so that the same launch file can run both on the real robot and in simulation, the only difference is the parameter value passed at the time of calling the command.

Practical example

$ ros2 launch my_cpp_pkg bringup.launch.py use_sim:=true
Output:
[INFO] [launch]: All log files can be found below /home/user/.ros/log/...
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [hello_node-1]: process started with pid [12345]
[INFO] [hello_node_py-2]: process started with pid [12346]
[hello_node-1] [INFO] [1723000000.111] [hello_node]: hello_node đã khởi động
[hello_node_py-2] [INFO] [1723000000.222] [hello_node_py]: hello_node đã khởi động

The prefix [hello_node-1]/[hello_node_py-2] before each log line helps distinguish the log of each node even though they run in the same terminal — the sequential numbers (-1, -2) are the order of declaration in the launch file, useful when you need to quickly determine which log belongs to which node in a system running dozens of nodes at the same time.

Common mistakes

  • Forgot to declare install(DIRECTORY launch ...) or data_files — as mentioned in the Main Concepts section, this is the most common error that causes ros2 launch not to find the file even though the Python syntax is completely correct.
  • 1 node crash causes the entire launch to be "silent" and difficult to diagnose — if you don't look closely at the log, it's easy to mistakenly think the whole system crashes when actually only 1 node fails and exits early — always check ros2 node list after launch to confirm that enough nodes are running as expected.
  • Misunderstanding LaunchConfiguration automatically changes data type — value passed via command line (use_sim:=true) is always string "true", not automatically changed to bool Python — if code checks if use_sim: in regular Python style without proper casting, the logic can be wrong (the string "false" is still truthy in Python).
  • IncludeLaunchDescription create a cross-include loop — 2 launch files include each other (directly or indirectly through the 3rd file) causing infinite recursion error when parsing — keep the include structure in a clear direction (original launch file includes child launch file, not vice versa).

Conclusion

Launch file is a must-have tool when the robot system exceeds a few nodes — allowing to start, configure parameters, and assemble multiple sub-launch files into a complete system with just 1 command. A layered architecture (root launch includes child launches) is the standard way of organizing a real AMR project that has many independent components. The next article in this section, also the last, is about Parameters — how to pass runtime configuration to each node that the launch file you just learned is often used to set up.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

Launch files in ROS2 — starting multiple nodes at once — Atlas Robotics