[ros2] how to pass commandline arguments to launch files
I want to do something like:
$ ros2 launch foo bar.launch.py arg_name:=arg_value
How do I get and use arg_value
inside the launch file? I cannot find any documentation for how to do this. Seems similar to this question: https://answers.ros.org/question/372544/running-python-launch-files-with-arguments/
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
Asked by Jeffrey Kane Johnson on 2021-03-02 13:48:19 UTC
Answers
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.
Asked by destogl on 2021-03-11 11:01:40 UTC
Comments
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.
Asked by Jeffrey Kane Johnson on 2021-03-11 13:21:54 UTC
I am also searching for this for a few last days... if you find something, please let me know...
Asked by destogl on 2021-03-12 07:26:20 UTC
@destogl Definitely. If I find anything, I'll post it here.
Asked by Jeffrey Kane Johnson on 2021-03-12 07:27:52 UTC
Comments