How to get argument values in ROS2?
Currently I'd like to pass a value from command line to a ROS2 argument like this.
msg_param = DeclareLaunchArgument('msg', default_value='True')
I wish to get the value directly in launch file, just like this:
ros2 launch my_pkg my_launch.launch.py msg:='False', then I could use the value of msg directly. That's False.
I have tried several methods like LaunchConfiguration, LaunchConfiguration.perform(), either there is an error or I couldn't get the actual value of 'msg'. It's always some formats like launch.substitutions.launch_configuration.LaunchConfiguration object at 0x7f5e7c302100
Thank you for sharing !
Is there a tutorial of using
I haven't figured out how to get the string value.
I admit launch substitutions are still a bit fuzzy for me and I'd like to see a better tutorial, so hopefully someone else will chime in to confirm.
But while we wait for that, here's what I do for reference:
I don't think there's any way of directly pulling the value out of a launch configuration, without evaluating it in another Launch object, which provides it with the launch context.
Thank you for your reply. I have tried to use LogInfo and I could see the value from terminal. However, how could I use that value in my launch file?
I also used
LaunchConfiguration('my_param').perform(LaunchContext())
However, it says the value 'my_param' doesn't exist. Probably before it returns LaunchDescription, I'm not able to use it?For reference, can you give more information on what you're trying to do with the value?
I want to get a True or False value passed from command line. Initially, it's a LaunchConfiguration object. I thought I could not be used since I'd like to get the True or False directly not an object. After test, the value would be passed to my program instead of an object.
The problem is solved. I'll close this session.
How did you manage to solve this?