Select config file based upon launch argument
I am trying to select between two configuration files based upon a boolean launch file argument. The example below works, but it seems awfully complicated. Is there a simpler way to do this?
def generate_launch_description():
red_arg = launch.actions.DeclareLaunchArgument('red', default_value='false')
launch_description = launch.LaunchDescription([red_arg])
config_file_path = os.path.join(get_package_share_directory('my_package'), 'config')
config_file = launch.substitutions.PythonExpression(
['"', config_file_path, '" + ("/red.yml" if "',
launch.substitutions.LaunchConfiguration("color"), '".lower() == "true" else "/blue.yml")'])
launch_description.add_action(launch.add_action(launch.actions.LogInfo(
msg=('Config file: ', config_file)
my_node = Node(package='my_package', executable='my_executable.py', parameters=[config_file])
launch_description.add_action(my_node)
return launch_description
For readability, the cryptic PythonExpression
evaluates to
"/opt/ros_ws/install/my_package/share/my_package/config" + ("/red.yml" if "<launch arg>".lower() == "true" else "/blue.yml")