Ask Your Question

ros2 access current LaunchConfiguration

asked 2019-05-07 06:36:29 -0600

bergercookie gravatar image

updated 2019-05-08 16:42:32 -0600

William gravatar image

I'm in the middle of migrating a ROS1 app of mine to ROS2 and I'm currently trying to convert a .launch file to a python script.

I want to be able to pass a command line argument to the script and then get its value in the generate_launch_description call.

This is how I currently pass extra arguments to the LaunchDescription:

run_rqt_arg = DeclareLaunchArgument(name="run_rqt",
                                    description="Launch RQT?")
run_rviz_arg = DeclareLaunchArgument(name="run_rviz",
                                     description="Launch RVIZ?")

if run_rqt:
    rqt = Node(...)
if run_rviz:
    rviz = Node(...)

return LaunchDescription(l, run_rqt, run_rviz)

I'm running the launch script via ros2 launch ...

Is the passing of extra arguments handled correctly? How do I fetch the values of these cli args at runtime?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2019-05-08 16:53:57 -0600

William gravatar image

The launch argument's value is stored in the "Launch Configurations", and those can be accessed using a substitution called launch.substitution.LaunchConfiguration(name) -> string.

If you want to do something conditionally based on this, I'd recommend using a launch.Condition which may be passed to any launch.Action, e.g.:

def generate_launch_description():
    run_rqt_arg = DeclareLaunchArgument(
        description="Launch RQT?")
    run_rviz_arg = DeclareLaunchArgument(
        description="Launch RVIZ?")

    rqt = Node(...,
    rviz = Node(...,

    return launch.LaunchDescription([run_rqt_arg, run_rviz_arg, run_rqt, run_rviz])

See also:

edit flag offensive delete link more


Hi William, is this feature (launch.substitution.LaunchConfiguration(name) -> string) still supported in the current dashing version? I have been trying to use launch.substitutions.LaunchConfiguration to access my arguments but it does not return a string. Any ideas on that?

I have also opened a question for this:

relffok gravatar image relffok  ( 2019-12-26 13:16:28 -0600 )edit

This is not supported anymore indeed.

achille gravatar image achille  ( 2021-03-23 18:32:28 -0600 )edit

So this answer is now out-of-date?

M@t gravatar image M@t  ( 2021-07-05 18:52:27 -0600 )edit

answered 2020-08-10 19:04:50 -0600

I was able to evaluate launch arguments in a custom function outside of the LaunchDescription by using the OpaqueFunction launch action feature, see this link:

edit flag offensive delete link more


I had the same issue of evaluating launch arguments. After a bit of struggle, the OpaqueFunction worked better than expected. My code is so much cleaner. Thank you for this!

ROS2 launch package definitely needs some documentation. It is a complete mystery right now. If anyone has questions on how I managed to use OpaqueFunction, I can help you out.

spoluri gravatar image spoluri  ( 2021-08-26 15:01:45 -0600 )edit

answered 2021-07-10 08:56:49 -0600

RobotDreams gravatar image

This is an old question that is still being asked due to lack of examples in the ROS2 tutorial. The best answer I have seen yet is by @djchopp

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools



Asked: 2019-05-07 06:36:29 -0600

Seen: 2,470 times

Last updated: Jul 10 '21