Ask Your Question
0

Launch component into container defined by included launch file

asked 2021-10-07 13:56:28 -0600

fhwedel-hoe gravatar image

Hi

This question can be regarded as an extension of the question https://answers.ros.org/question/3781... and https://answers.ros.org/question/3069....

Situation: I have a "base" launch file which describes a collection of nodes. Some of these nodes are launched in a component container. The base launch file is already fairly complex. I do not want to add to it any further.

Goal: To further expand the project, I want to build upon the base rather than to change it. I want to create a launch file which includes the base launch file and then describes some more nodes to launch. Some of these nodes need to be added to the component container which is described by the included launch file.

This is what I have so far (includes omitted for readability):

base_package_directory = get_package_share_directory('base_package')
base_launch_description = IncludeLaunchDescription(PythonLaunchDescriptionSource(base_package + '/launch/base.py'))
base_container = next(e for e in base_vehicle.get_sub_entities()[0].entities if isinstance(e, ComposableNodeContainer))
additional_node = LoadComposableNodes(
    composable_node_descriptions = [ComposableNode(
        name = 'additional_node',
        package = 'additional_package',
        plugin = 'additional_node',
    )],
    target_container = base_container,
)
return launch.LaunchDescription([base_launch_description, additional_node])

This looks terribly ugly. Also, it results in an error:

RuntimeError: cannot access 'node_name' before executing action

Where node_name is an attribute of the ComposableNodeContainer "base_container".

My guts are telling me "you are doing it wrong" – especially when looking at line 2 and 3. How do I do this right?

Kind regards
Hermann

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2021-10-07 20:20:38 -0600

ChuiV gravatar image

If you know the container name, then you can use that name as the target_container:

...
additional_node = LoadComposableNodes(
    composable_node_descriptions=[ComposableNode(
        name='additional_node',
        package='additional_package',
        plugin='additional_node')],
   target_container='base_container_node_name')

...

edit flag offensive delete link more

Comments

Thank you. :) Small hint for the next one looking at this: It needs to be the "fully qualified" name. In my case, a namespace is involved. The target_container becomes '/whatever_namespace/base_container_node_name'.

fhwedel-hoe gravatar image fhwedel-hoe  ( 2021-10-11 11:14:02 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-10-07 13:56:28 -0600

Seen: 29 times

Last updated: Oct 07 '21