Inferensys

Glossary

ROS 2 Launch Argument

A ROS 2 Launch Argument is a variable defined in a launch file that can be set from the command line or programmatically to parameterize the configuration of nodes and their behaviors at startup.
Command center environment coordinating high-volume workflows across multiple systems.
ROS 2 LAUNCH SYSTEM

What is a ROS 2 Launch Argument?

A ROS 2 Launch Argument is a variable defined in a launch file that can be set from the command line or programmatically to parameterize the configuration of nodes and their behaviors at startup.

A ROS 2 Launch Argument is a named, typed variable declared within a Python or XML launch file. It acts as a parameter placeholder that allows users to pass configuration values into the launch system without modifying the file's source code. Arguments are defined with a name, default value, and description, and their values can be overridden via the command line using the syntax arg_name:=value. This mechanism enables dynamic configuration and reuse of the same launch file across different robots, environments, or operational modes.

During launch file execution, declared arguments are substituted wherever their name is referenced, typically to set node parameters, define topic names, or conditionally include other launch descriptions. This creates a declarative interface for system configuration, separating the launch logic from specific runtime values. By using arguments, developers build flexible, maintainable launch systems that support modular composition and command-line automation, which is essential for testing, deployment, and system integration in embodied intelligence applications.

LAUNCH SYSTEM FUNDAMENTALS

Key Characteristics of ROS 2 Launch Arguments

ROS 2 Launch Arguments are variables that parameterize launch file execution, enabling dynamic configuration of nodes, parameters, and system behavior at startup without modifying source code.

01

Definition and Core Purpose

A ROS 2 Launch Argument is a named variable declared within a launch file (Python or XML) whose value can be supplied externally—typically via the command line—to customize the configuration of a robotic application at launch time. Its primary purpose is to create reusable, configurable launch files that avoid hard-coded values, allowing the same file to start systems with different parameters, node configurations, or even different sets of nodes based on conditional logic. This is essential for managing variations across development, simulation, and multiple physical robot deployments.

02

Declaration and Default Values

Arguments are declared in a launch file using specific functions from the launch API. In Python launch files, the DeclareLaunchArgument action is used. Each declaration includes:

  • Name: A string identifier for the argument (e.g., 'use_sim_time').
  • Default Value: The value used if the argument is not provided externally (e.g., default_value='false').
  • Description: An optional human-readable explanation.

Example in Python:

python
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration

launch_arguments = []
launch_arguments.append(DeclareLaunchArgument(
    'robot_model',
    default_value='turtlebot3_burger',
    description='Which robot model to configure.'
))

The argument's value is then accessed elsewhere in the launch file via a LaunchConfiguration substitution.

03

Substitution and Usage in Launch Files

The power of launch arguments is realized through substitutions. The LaunchConfiguration('arg_name') object acts as a placeholder that is resolved to the argument's actual value at execution. These substitutions can be used to dynamically set:

  • Node Parameters: Passing the argument's value to a node's parameter list.
  • Conditional Logic: Using the argument's value in IfCondition or UnlessCondition to include or exclude launch actions.
  • File Paths: Constructing paths to configuration files or URDF models.
  • Remapping Rules: Dynamically remapping topic or service names.

Example of passing an argument to a node parameter:

python
Node(
    package='my_pkg',
    executable='my_node',
    parameters=[{'model_name': LaunchConfiguration('robot_model')}]
)
04

Command-Line Override and Precedence

The defining feature of launch arguments is their ability to be overridden from the command line when invoking the launch file using ros2 launch. The command-line syntax is arg_name:=value. This creates a clear hierarchy of configuration precedence:

  1. Command-Line Value: Highest priority. Directly overrides any default.
  2. Default Value in Launch File: Used if no command-line value is provided.

Example command:

bash
ros2 launch my_robot launch_file.py robot_model:=turtlebot3_waffle use_sim_time:=true

This command starts the system configured for a Waffle model with simulation time enabled, regardless of the defaults in the launch file. This mechanism is critical for rapid testing, A/B comparisons, and deployment scripting.

05

Conditional Launch Logic

Launch arguments enable conditional execution of launch actions, allowing a single launch file to describe multiple system configurations. This is achieved using IfCondition and UnlessCondition actions, which evaluate a Boolean expression based on the argument's value.

Common use cases include:

  • Simulation vs. Real Robot: An argument like use_simulator determines whether to spawn a robot in Gazebo or connect to real hardware drivers.
  • Sensor Selection: An argument like lidar_type chooses which driver node and corresponding parameters to launch.
  • Debug Mode: An argument like debug controls whether to launch nodes with additional logging or visualizers.

Example:

python
from launch.conditions import IfCondition

launch_description = LaunchDescription([
    Node(
        condition=IfCondition(LaunchConfiguration('use_gazebo')),
        package='gazebo_ros',
        executable='spawn_entity.py',
        arguments=['-topic', 'robot_description']
    )
])
06

Relationship to ROS Parameters

It is crucial to distinguish Launch Arguments from ROS Parameters, as they operate at different system layers:

  • Launch Argument: A build-time/startup-time construct for the launch system itself. It configures which nodes are launched, with what initial settings, and under which conditions. Its scope is the launch file execution.
  • ROS Parameter: A runtime configuration mechanism managed by a node's parameter server. Nodes can get, set, and be dynamically reconfigured via parameters during their lifecycle.

A typical pattern is to use a launch argument to set the initial value of one or more ROS parameters. For example, a robot_speed_limit launch argument is used to populate a node's max_velocity parameter at startup. After launch, that parameter can still be changed via ros2 param set, independent of the original launch argument.

CONFIGURATION

How ROS 2 Launch Arguments Work

A detailed explanation of ROS 2 launch arguments, which are the primary mechanism for parameterizing robotic system startup.

A ROS 2 Launch Argument is a variable defined within a Python or XML launch file that can be assigned a default value and overridden from the command line or programmatically. This mechanism allows a single launch description to parameterize the configuration of nodes, their parameters, and even the structure of the launch graph itself at execution time. Arguments enable reusable, configurable launch files that adapt to different robots, environments, or operational modes without code duplication.

Arguments are declared with DeclareLaunchArgument and accessed via the LaunchConfiguration substitution. They are resolved during the launch description evaluation phase, before any nodes are instantiated. This design supports complex logic, such as conditional branching and loops within the launch file, based on argument values. Common uses include setting namespace prefixes, selecting sensor configurations, toggling simulation modes, and passing file paths for maps or URDF models to downstream nodes.

ROS 2 LAUNCH ARGUMENT

Common Use Cases and Examples

Launch arguments are the primary mechanism for making ROS 2 launch files reusable and configurable. They allow a single launch description to adapt its behavior for different robots, environments, or operational modes.

01

Hardware-Specific Configuration

Use launch arguments to abstract hardware differences, enabling a single launch file to work across multiple robot models or sensor suites.

  • Robot Model Selection: Pass the robot's name (e.g., robot_model:=turtlebot3_burger) to load the correct URDF, controller configurations, and namespace.
  • Sensor Toggle: Use boolean arguments like use_lidar:=true or use_camera:=false to conditionally launch sensor driver nodes.
  • Device Paths: Set arguments for serial ports or network addresses (e.g., lidar_port:=/dev/ttyUSB0).

This pattern is essential for maintaining a unified codebase across heterogeneous fleets.

02

Environment and Simulation Mode

Arguments control whether the system launches in simulation, on physical hardware, or for specific testing environments.

  • Use Simulation: The canonical argument use_sim_time:=true directs all nodes to use simulated time published on the /clock topic.
  • World Selection: In Gazebo or Ignition, use world:=warehouse to load a specific simulated environment file.
  • Headless Mode: Set gui:=false to launch a physics simulation without a visual client for automated testing.

This allows seamless context switching between development, testing, and deployment.

03

Runtime Performance Tuning

Expose critical performance knobs as launch arguments to optimize system behavior without code changes.

  • Quality of Service (QoS) Profiles: Set arguments like qos_reliability:=reliable for critical control topics or qos_reliability:=best_effort for high-frequency sensor data.
  • Executor Configuration: Control thread pools with arguments like single_threaded_executor:=true for deterministic callback ordering.
  • Buffer Sizes: Configure internal queue depths for publishers and subscribers (e.g., queue_size:=10).

This provides operational flexibility to balance latency, reliability, and resource usage.

04

Multi-Robot and Namespacing

Launch arguments are fundamental for instantiating multiple instances of the same robot system in a single ROS graph, preventing topic and parameter collisions.

  • Robot Namespace: The argument robot_namespace:=/robot1 prefixes all node names, topics, and services for that robot instance.
  • Fleet Launch: A master launch file can call include actions in a loop, passing a unique robot_id argument to each included launch description.
  • TF Prefix: Use an argument to set the tf_prefix for a robot's transform frames, ensuring correct coordinate frame isolation.

This pattern is the backbone of scalable multi-robot application deployment.

05

Conditional Logic and Composition

Arguments drive the conditional execution of launch actions, enabling complex, branching launch descriptions.

  • If/Unless Conditions: Use IfCondition and UnlessCondition to include or exclude entire node groups, e.g., launching a mapping stack only if mode:=mapping.
  • Choose/When Conditions: Implement switch-case logic with GroupAction containing PushRosNamespace and node declarations triggered by specific argument values.
  • Composition: Arguments can determine whether nodes are launched as standalone processes or loaded as components into a shared container for lower latency and memory footprint.

This creates intelligent, context-aware startup sequences.

06

Integration with Higher-Order Tools

Launch arguments serve as the clean interface between ROS 2 launch files and external deployment, orchestration, and CI/CD systems.

  • CI/CD Pipelines: Jenkins or GitLab CI jobs pass arguments like test_mode:=true and bag_file:=test.bag to launch integration tests.
  • Orchestrators: Kubernetes deployments or Ansible playbooks set environment-specific arguments (e.g., map_yaml:=/maps/warehouse_v2.yaml).
  • Command-Line Wrappers: Shell scripts or Python tools provide a simplified user interface that internally calls ros2 launch with a curated set of argument values.

This establishes launch files as the definitive, parameterized entry point for the robotic software system.

CONFIGURATION MECHANISMS

Launch Argument vs. ROS Parameter

A comparison of two primary methods for configuring behavior in a ROS 2 system, detailing their distinct purposes, scopes, and lifecycle phases.

FeatureLaunch ArgumentROS Parameter

Primary Purpose

Configure the launch process and file logic

Configure the runtime behavior of a specific node

Definition Scope

Defined within a launch file (Python/XML)

Declared within a node's source code

Value Assignment

Command line, other launch args, or defaults

Launch file, parameter YAML, or dynamic API calls

Accessibility

Only accessible within the launch file's context

Accessible to any node via the parameter service

Runtime Modification

Immutable after launch execution begins

Mutable via the parameter service API

Lifecycle Phase

Used during system initialization and launch

Used during node initialization and ongoing operation

Typical Use Case

Conditionally include nodes, select maps, set robot model

Set control gains, topic names, algorithm thresholds

Data Type Enforcement

String-based; casting performed by user logic

Strictly typed (e.g., integer, double, string, boolean array)

Discovery Mechanism

Listed via launch_arguments and DeclareLaunchArgument

Listed via node.describe_parameters() or ros2 param list

ROS 2 LAUNCH ARGUMENT

Frequently Asked Questions

A ROS 2 Launch Argument is a variable defined in a launch file that can be set from the command line or programmatically to parameterize the configuration of nodes and their behaviors at startup.

A ROS 2 Launch Argument is a named variable declared within a ROS 2 launch file (Python or XML) that allows for the parameterization of node configurations, file paths, and system behaviors at launch time. Unlike runtime ROS Parameters, launch arguments are resolved before nodes are instantiated, enabling dynamic construction of the launch graph based on user input or programmatic logic. They are a core mechanism for creating reusable, configurable launch configurations without modifying source code.

Key characteristics include:

  • Declaration: Defined using DeclareLaunchArgument in Python or the <arg> tag in XML.
  • Resolution: Values can be provided via the command line (e.g., ros2 launch my_package launch_file.py my_arg:=value), from another launch file, or by using default values.
  • Scope: Accessible throughout the launch description for conditional logic, setting parameters, or constructing node arguments.
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.