Ask Your Question
2

[ros2] how to pass commandline arguments to launch files

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

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

I want to do something like:

$ ros2 launch foo bar.launch.py 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: https://answers.ros.org/question/3725...

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: http://wiki.ros.org/roslaunch/XML/arg

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

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

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 = []
    declared_arguments.append(DeclareLaunchArgument(
        'param_name', default_value='param_default_value',
        description='Description about praram_name parameter.'))

    param_name = LaunchConfiguration('param_name')

    my_node = Node(
        package='controller_manager',
        executable='ros2_control_node',
        parameters=[{'param_name': param_name}],
        output={
             'stdout': 'screen',
             'stderr': 'screen',
         },
    )

    return LaunchDescription(
        declared_arguments +
        [
            my_node,
        ])

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

Comments

1

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 -0600 )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 -0600 )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 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

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

Seen: 127 times

Last updated: Mar 11 '21