Ask Your Question

Revision history [back]

It seems that a neater solution is on the way:
https://github.com/ros2/launch/pull/453

Once the PR changes are available upstream, you will be able to do something like:

import launch
from launch.actions import LogInfo, DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch.conditions import LaunchConfigurationEquals


def generate_launch_description():
    return launch.LaunchDescription([
        DeclareLaunchArgument('bag_version', default_value='v1'),
        LogInfo(msg=LaunchConfiguration('bag_version')),
        LogInfo(msg='Version 1', condition=LaunchConfigurationEquals('bag_version', 'v1')),
        LogInfo(msg='Version 2', condition=LaunchConfigurationEquals('bag_version', 'v2'))
    ])

Before the LaunchConfigurationEquals condition is available I guess your best bet is to copy the condition locally: https://github.com/ros2/launch/blob/master/launch/launch/conditions/launch_configuration_equals.py
and change the import once it becomes available upstream.

Or, to stick with the solution you have now.