ros2 / launch_ros

Tools for launching ROS nodes and for writing tests involving ROS nodes.
Apache License 2.0
59 stars 72 forks source link

Make OnStateTransition work with the new ComposableNode descriptions #41

Open ralph-lange opened 5 years ago

ralph-lange commented 5 years ago

Feature request

Feature description

In Dashing, the ComposableNodeContainer action and the corresponding ComposableNode description were introduced. A ComposableNode description also takes a managed node (aka lifecycle node). However, configuring and activating a lifecycle node by a ComposableNode description (instead of a LifecycleNode action) fails:

on_inactive_node_B_handler = launch.actions.RegisterEventHandler(
        launch_ros.event_handlers.OnStateTransition(
            target_lifecycle_node=node_B,
            goal_state='inactive',
            entities=[configure_node_A]))

> Caught exception in launch (see debug for traceback): OnStateTransition 
  requires a 'LifecycleNode' action as the target

Using a matcher is also not possible but gives an exception.

on_inactive_node_B_handler = launch.actions.RegisterEventHandler(
        launch_ros.event_handlers.OnStateTransition(
            matcher=launch_ros.events.lifecycle.matches_node_name("/example/node_B"),
            goal_state='inactive',
            entities=[configure_node_A]))

> ... return lambda action: action.node_name == node_name
  AttributeError: 'Shutdown' object has no attribute 'node_name'

When calling matches_action with a ComposableNode description is simply does nothing:

    configure_node_B = launch.actions.EmitEvent(
        event=launch_ros.events.lifecycle.ChangeState(
            lifecycle_node_matcher=launch.events.matchers.matches_action(node_B),
            transition_id=lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE,
        )
    )

Probably, the whole matching and event system for lifecycle action and events has to be extended for ComposbleNode descriptions.

As a starting for experiments, you may use the damped_pendulum_with_transport_delay_as_composed_node.launch.py of the fmi_adapter_examples package, cf. https://github.com/boschresearch/fmi_adapter_ros2/blob/0.1.5/fmi_adapter_examples/launch/damped_pendulum_with_transport_delay_as_composed_node.launch.py and remove comments in lines 90 to 103 and 106 to 108.

JWhitleyWork commented 4 years ago

Has there been any movement on this?

vincentrou commented 3 years ago

This issue seems to be linked to this ongoing refactoring : https://github.com/ros2/design/pull/272#issuecomment-669522706

hellantos commented 2 years ago

I have an experimental, heavily refactored prototype for the launch_ros composition part in https://github.com/ipa-cmh/launch_ros_experimental that does enable this. It changes quite a lot of things from an architectural standpoint:

It breaks the existing API, so this probably not mergeable, just wanted to point out it exists.

You can use it like this:


import launch
from launch_ros_experimental.actions import ComposableNode, ComposableNodeContainer, ComposableLifecycleNode
from launch_ros.actions import LifecycleTransition
from lifecycle_msgs.msg import Transition

def generate_launch_description():
    """Generate launch description with multiple components."""
    container = ComposableNodeContainer(
            name='my_container',
            namespace='',
            package='rclcpp_components',
            executable='component_container',
            output='screen',
    )

    node = ComposableNode(
        package='composition',
        component='composition::Talker',
        name='talker',
        target_container='my_container'
    )
    lifecycle_node = ComposableLifecycleNode(
        package='composition',
        component='composition::LifecycleTalker',
        name='lctalker',
        namespace='',
        target_container='my_container'  
    )

    lifecycle_node_1 = ComposableLifecycleNode(
        package='composition',
        component='composition::LifecycleTalker',
        name='lctalker_1',
        namespace='',
        target_container='my_container'  
    )

    lifecycle_transition = LifecycleTransition(
        lifecycle_node_names=['lctalker', 'lctalker_1'],
        transitions_ids=[
            Transition.TRANSITION_CONFIGURE,
            Transition.TRANSITION_ACTIVATE]
    )

    return launch.LaunchDescription([container, node, lifecycle_node, lifecycle_node_1, lifecycle_transition])

For testing you can use https://github.com/ipa-cmh/demos/tree/lifecycle_components which has the composition LifecycleTalker component.

ZhenshengLee commented 1 year ago

https://github.com/ros2/launch/issues/672 is related.

I wonder if I should create all issues in this repo, rather than https://github.com/ros2/launch repo?

ZhenshengLee commented 1 year ago

I have an experimental, heavily refactored prototype for the launch_ros composition part in https://github.com/ipa-cmh/launch_ros_experimental that does enable this.

@ipa-cmh thanks for your repo!

I've tryied your repo in my project.

It seems that your repo doesnot support Foxy version am I right?

Which versions do you plan to support?

Thanks.

ZhenshengLee commented 1 year ago

Also, launch_ros.events.lifecycle.matches_node_name($LifecycleNodeComponent$) doesnot work.

leonce-m commented 8 months ago

Any news on this development? It's been 5 years already and we still can't properly use the launch Event system to manage the lifecycle of composable nodes.