ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

[ros2] how to pass commandline arguments to launch files

asked 2021-03-02 12:48:19 -0500

updated 2021-03-11 12:24:50 -0500

I want to do something like:

$ ros2 launch foo arg_name:=arg_value

How do I get and use arg_valueinside the launch file? I cannot find any documentation for how to do this. Seems similar to this question:

To be clear, I do not want to set a node's parameter value. I just want to pass in a value for use inside the launch file. I'm looking for the functionality that the <arg>tag provides in ROS 1 xml launch files:

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-03-11 10:01:40 -0500

Hi Jeffrey,

To use parameter "param_name" here an example launch file:

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

from launch_ros.actions import Node

def generate_launch_description():
    declared_arguments = []
        'param_name', default_value='param_default_value',
        description='Description about praram_name parameter.'))

    param_name = LaunchConfiguration('param_name')

    my_node = Node(
        parameters=[{'param_name': param_name}],
             'stdout': 'screen',
             'stderr': 'screen',

    return LaunchDescription(
        declared_arguments +

As far as I know, there is no possibility to get the "param_value" in the launch file other than using substitutions.

edit flag offensive delete link more



Thanks, but this doesn't answer the question. I'm not setting a node parameter, I just want to pass in a value to the launch script from the command line. I've edited the question to try to make it clearer.

Jeffrey Kane Johnson gravatar image Jeffrey Kane Johnson  ( 2021-03-11 12:21:54 -0500 )edit

I am also searching for this for a few last days... if you find something, please let me know...

destogl gravatar image destogl  ( 2021-03-12 06:26:20 -0500 )edit

@destogl Definitely. If I find anything, I'll post it here.

Jeffrey Kane Johnson gravatar image Jeffrey Kane Johnson  ( 2021-03-12 06:27:52 -0500 )edit

Question Tools



Asked: 2021-03-02 12:48:19 -0500

Seen: 615 times

Last updated: Mar 11 '21