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

There's no way to do this (conditionally include a substitution in a list) right now.

You could do something like this:

LaunchDescription([
    launch.actions.DeclareLaunchArgument(
        "my_param",
        default_value=[""],  # default_value=[], has the same problem
        description="optional parameter"
    ),
    launch_ros.actions.Node(
        package="my_package",
        node_executable="my_node",
        arguments=[launch.substitutions.LaunchConfiguration("my_param")],
        condition=launch.conditions.IfCondition(launch.substitutions.LaunchConfiguration("my_param")),
    ),
    launch_ros.actions.Node(
        package="my_package",
        node_executable="my_node",
        arguments=[],
        condition=launch.conditions.UnlessCondition(launch.substitutions.LaunchConfiguration("my_param")),
    ),
])

Which is obviously silly, but it's the only way to express it at the moment.

As a long term solution, I think we either need conditional Substitutions, where maybe they return None if the condition is false, and code that processes lists of substitutions would ignore (just drop) any substitutions that return None.

Then you'd be able to do something like this:

LaunchDescription([
    launch.actions.DeclareLaunchArgument(
        "my_param",
        default_value=[""],  # default_value=[], has the same problem
        description="optional parameter"
    ),
    launch_ros.actions.Node(
        package="my_package",
        node_executable="my_node",
        arguments=[launch.substitutions.LaunchConfiguration("my_param", condition=launch.conditions.IfCondition(launch.substitutions.LaunchConfiguration("my_param"))]
    ),
])

Or some short hand for self-evaluating the substition, e.g.:

LaunchDescription([
    launch.actions.DeclareLaunchArgument(
        "my_param",
        default_value=[""],  # default_value=[], has the same problem
        description="optional parameter"
    ),
    launch_ros.actions.Node(
        package="my_package",
        node_executable="my_node",
        arguments=[launch.substitutions.LaunchConfiguration("my_param", condition=launch.conditions.UnlessEmpty())]
    ),
])

There's no way to do this (conditionally include a substitution in a list) right now.

You could do something like this:

LaunchDescription([
    launch.actions.DeclareLaunchArgument(
        "my_param",
        default_value=[""],  # default_value=[], has the same problem
        description="optional parameter"
    ),
    launch_ros.actions.Node(
        package="my_package",
        node_executable="my_node",
        arguments=[launch.substitutions.LaunchConfiguration("my_param")],
        condition=launch.conditions.IfCondition(launch.substitutions.LaunchConfiguration("my_param")),
    ),
    launch_ros.actions.Node(
        package="my_package",
        node_executable="my_node",
        arguments=[],
        condition=launch.conditions.UnlessCondition(launch.substitutions.LaunchConfiguration("my_param")),
    ),
])

Which is obviously silly, but it's the only way to express it at the moment.

As a long term solution, I think we either need conditional Substitutions, where maybe they return None if the condition is false, and code that processes lists of substitutions would ignore (just drop) any substitutions that return None., or some way to process lists of substitutions conditionally (not sure how that would work off hand).

Then you'd be able to do something like this:

LaunchDescription([
    launch.actions.DeclareLaunchArgument(
        "my_param",
        default_value=[""],  # default_value=[], has the same problem
        description="optional parameter"
    ),
    launch_ros.actions.Node(
        package="my_package",
        node_executable="my_node",
        arguments=[launch.substitutions.LaunchConfiguration("my_param", condition=launch.conditions.IfCondition(launch.substitutions.LaunchConfiguration("my_param"))]
    ),
])

Or some short hand for self-evaluating the substition, substitution, e.g.:

LaunchDescription([
    launch.actions.DeclareLaunchArgument(
        "my_param",
        default_value=[""],  # default_value=[], has the same problem
        description="optional parameter"
    ),
    launch_ros.actions.Node(
        package="my_package",
        node_executable="my_node",
        arguments=[launch.substitutions.LaunchConfiguration("my_param", condition=launch.conditions.UnlessEmpty())]
    ),
])