ros2 launch: How to select parameters yaml file depending on parameter?
I want to use a parameter (ns) to select the yaml file to load for parameters. I have a hard time finding how to do it... Is there a better way to do it?
I want to do something like:
def generate_launch_description():
ns_arg = DeclareLaunchArgument("ns", default_value=TextSubstitution(text="/dji0"))
location_arg = DeclareLaunchArgument("location", default_value=TextSubstitution(text="granso"))
location_config = os.path.join(
get_package_share_directory('lrs_wdb'),
'config',
f'location_{LaunchConfiguration('location')}.yaml'
)
return LaunchDescription([
ns_arg,
Node(
package='lrs_wdb',
output='screen',
emulate_tty=True,
namespace=LaunchConfiguration('ns'),
executable='wdb',
name='wdb',
parameters=[location_config]
)
])
But this is not working since "LaunchConfiguration('ns')" is an object. And googling it I did not find a strightforward way to get the value. So any suggestions how to solve this? I could use an environment variable I suppose but I do not think that is a good solution since for example ns is specified with a parameter.