0
$\begingroup$

party developed node that uses an argument on startup (and no parameters). I have a launch file that loads an YAML and uses it to feed the parameters to several nodes being launched. One of the configurations in that YAML file is the argument I need to pass to that 3rd-party node.

Currently, what I do, is to use an opaque function to process the YAML file and retrieve that configuration (it is not a ros__parameters) so as to pass it as an argument to the node in the launch file. Does this make sense, or is there a better way to deal with this need?

I am using a Python-based launch file with SimpleLauncher, but using normal LaunchDescription would be an option to.

The yaml file has this contents:

stage:
  world_package: "worlds"
  world_file: "stage_worlds/map_laser_with_landmarks2.world"
  ros__parameters:
    use_sim_time: True

The launch file has the following:

from simple_launch import SimpleLauncher
import yaml
import os


sl = SimpleLauncher(use_sim_time=True)

# Declare arguments
sl.declare_arg('params_file',
               sl.find('tw07', 'params.yaml', 'config'),
               description='(Optional) Complete path to the parameters file')
sl.declare_arg('start_stage', True,
               description='If True, the Stage simulator is started')


def launch_opaque_setup():

    with sl.group(if_arg='start_stage'):
        # Get the YAML configuration file
        params = sl.arg('params_file')
        with open(params, 'r') as file:
            params_raw = yaml.safe_load(file)

        # Get the world file from the parameters file
        world_pkg = params_raw['stage']['world_package']
        world_path = params_raw['stage']['world_file']
        world_dir, world_filename = os.path.split(world_path)

        # Stage simulator
        sl.node('stage_ros', 'stageros',
                arguments=sl.find(world_pkg, world_filename, world_dir))


    return sl.launch_description()


generate_launch_description = \
    sl.launch_description(opaque_function=launch_opaque_setup)
$\endgroup$
2
  • $\begingroup$ Hi! Please add the relevant part of your launch file to the post. Moreover, could you clarify what is the problem with the method you are using? If I understood correctly, it works just as you want, but you find the implementation too hackish. Am I right? $\endgroup$
    – Luca
    Mar 18 at 10:52
  • $\begingroup$ Hi @Luca , thanks for your comment. I added the yam and launch files. Indeed, I was hoping that using "Substitutions" there was some way to do this without processing the YAML myself. $\endgroup$
    – hugo
    Mar 18 at 15:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.