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

Revision history [back]

click to hide/show revision 1
initial version

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(
        name="run_rqt",
        default_value="True",
        description="Launch RQT?")
    run_rviz_arg = DeclareLaunchArgument(
        name="run_rviz",
        default_value="True",
        description="Launch RVIZ?")

    rqt = Node(...,
        condition=launch.conditions.IfCondition(launch.LaunchConfiguration("run_rqt")))
    rviz = Node(...,
        condition=launch.conditions.IfCondition(launch.LaunchConfiguration("run_rviz")))

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

See also:

  • https://github.com/ros2/launch/blob/d9def23d24b500c7c4b10f79297059b793b27152/launch/launch/actions/declare_launch_argument.py#L35-L37
  • https://github.com/ros2/launch/blob/d9def23d24b500c7c4b10f79297059b793b27152/launch/launch/action.py#L58