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

[ROS2] what is different between DeclareLaunchArgument and LaunchConfiguration

asked 2019-05-09 20:10:35 -0500

Darby Lim gravatar image

updated 2019-05-09 20:13:00 -0500

I had tested ros2 launch with arguments. The arguments are successfully implemented using only set LaunchConfiguration exclude DeclareLaunchArgument. For example, attached launch files worked excluding DeclareLaunchArgument

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.substitutions import LaunchConfiguration, EnvironmentVariable
from launch.actions import DeclareLaunchArgument
from launch_ros.actions import Node


def generate_launch_description():
    use_sim_time = LaunchConfiguration('use_sim_time', default='false')
    urdf_file_name = 'turtlebot3_' + TURTLEBOT3_MODEL + '.urdf'
    print("urdf_file_name : {}".format(urdf_file_name))

    urdf = os.path.join(get_package_share_directory('turtlebot3_description'), 'urdf', urdf_file_name)

    return LaunchDescription([
        #    'use_sim_time',
        #    default_value='false',
        #    description='Use simulation (Gazebo) clock if true'),

            parameters=[{' use_sim_time': use_sim_time}],

However, most examples of ros2 launch are included DeclareLaunchArgument when user want to use arguments. So, my main questions is What is different btw LaunchConfiguration and DeclareLaunchArgument?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-05-09 20:30:37 -0500

William gravatar image

updated 2019-05-17 15:25:49 -0500

LaunchConfiguration is local to the launch file and scoped.

DeclareLaunchArgument allows you to expose the argument outside of your launch file. Allowing them to be listed, set, or marked as required when a user launches it from the command line (using ros2 launch) or when including it from another launch file (using IncludeLaunchDescription).

A LaunchConfiguration cannot be required to be set when launching or including and it is not possible to set it when launching from the command line. You can set a LaunchConfiguration before including another launch file, but an argument is better if you want it to be reused.


Here's an example I threw together demonstrate based on comments to this answer:

import launch

def generate_launch_description():
    return launch.LaunchDescription([
        launch.actions.DeclareLaunchArgument('msg', default_value='hello world'),

If I try to launch it without arguments (ros2 launch ./ I get:

[INFO] [launch]: Default logging verbosity is set to INFO
[ERROR] [launch]: Caught exception in launch (see debug for traceback): Included launch description missing required argument 'other' (description: 'no description given'), given: []

That's because the other option has no default value and therefore is required.

I actually found out that the --show-arguments option was broken while testing this, so I'm not sure if that's what you ran into, but I open a pr to fix:

With that fix I can check the arguments (ros2 launch -s ./

Arguments (pass arguments as '<name>:=<value>'):

        no description given
        (default: 'hello world')

        no description given

I can run it if I specify other (ros2 launch ./ other:='lorem ipsum'):

[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [launch.actions.log_info]: hello world
[INFO] [launch.actions.log_info]: lorem ipsum
edit flag offensive delete link more


Thank you for comments :) However, if I set LaunchConfiguration excluding DeclareLaunchArgument, I would access launch argument from the command line. If I erase LaunchConfiguration, I would not. Furthermore, I couldn't find any arguments in launch file using -s or --show-arguments after activate DeclareLaunchArgument. I have tested it in Ubuntu18.04 and ROS2 Dashing(master repo)

Darby Lim gravatar image Darby Lim  ( 2019-05-10 03:28:51 -0500 )edit

if I set LaunchConfiguration excluding DeclareLaunchArgument, I would access launch argument from the command line. If I erase LaunchConfiguration, I would not.

I don't understand this, can you try to rephrase it?

William gravatar image William  ( 2019-05-17 14:57:27 -0500 )edit

After fixing a bug I can see the arguments, so maybe you need to give more details? I updated my answer with my demo.

William gravatar image William  ( 2019-05-17 15:26:34 -0500 )edit

Thank you for updates. I could check launch arguments using -s and I clearly understand what is a different of them. Thanks again!

Darby Lim gravatar image Darby Lim  ( 2019-05-22 03:04:26 -0500 )edit

I'm struggling with the concept of substitutions. In my simplified case:

urdf = DeclareLaunchArgument('urdf', default_value='file.urdf')
urdf_file  =  [launch.substitutions.LaunchConfiguration('urdf')]
urdf_path =os.path.join(get_package_share_directory('robot_bringup'), 'urdf', urdf_file)

If launch.substitutions.LaunchConfiguration('urdf') is passed as a list I get a "join() argument must be str or bytes, not 'list'".If I dont, I get join() argument must be str or bytes, not 'LaunchConfiguration' Is there an easy way to get the text value of the argument?

fastestindian gravatar image fastestindian  ( 2019-11-20 16:41:58 -0500 )edit

@fastestindian, Did you resolve it?

fmrico gravatar image fmrico  ( 2020-04-04 02:23:01 -0500 )edit

@fastestindian, It is the wrong way to deal with substitutions, once you have substitution the content of it cannot be used before all substitutions can be resolved. You either have to create a custom substitution or use an existing one:

For your use-case, you can use PathJoinSubstitution, something like:

from launch.substitutions import PathJoinSubstitution


urdf_path = PathJoinSubstitution(get_package_share_directory('robot_bringup'), 'urdf', launch.substitutions.LaunchConfiguration('urdf'))
lukicdarkoo gravatar image lukicdarkoo  ( 2020-08-02 06:48:15 -0500 )edit

Question Tools



Asked: 2019-05-09 20:10:35 -0500

Seen: 9,133 times

Last updated: May 17 '19