ros2 / launch

Tools for launching multiple processes and for writing tests involving multiple processes.
Apache License 2.0
124 stars 139 forks source link

[QST] Emit events through multiple launches. #668

Open ZhenshengLee opened 1 year ago

ZhenshengLee commented 1 year ago

Bug report

Required Info:

Steps to reproduce issue

the drive_base_node can be seen in https://github.com/micro-ROS/system_modes/blob/master/system_modes_examples/src/drive_base.cpp and adding initial configuration

with

// driver->set_parameter(rclcpp::Parameter("action", "move"));
  driver->trigger_transition(lifecycle_msgs::msg::Transition::TRANSITION_CONFIGURE);

first launch drive_base.launch.py

def generate_launch_description():
    return launch.LaunchDescription([
        launch_ros.actions.LifecycleNode(
            package='sm_guardian',
            executable='drive_base_node',
            name='drive_base',
            namespace='',
            output='screen')
    ])

then launch activate_drive.launch.py

import os

import launch
from launch import LaunchIntrospector

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import EmitEvent
from launch.actions import LogInfo
from launch.actions import RegisterEventHandler
from launch_ros.actions import Node
from launch_ros.actions import LifecycleNode
from launch_ros.actions import SetParameter
from launch_ros.events.lifecycle import ChangeState
from launch_ros.event_handlers import OnStateTransition

import lifecycle_msgs.msg

def generate_launch_description():

    # Set LOG format
    # os.environ['RCUTILS_CONSOLE_OUTPUT_FORMAT'] = '{time}: [{name}] [{severity}]\t{message}'

    # Launch Description
    ld = launch.LaunchDescription()

    drive_base_node = LifecycleNode(
            package='sm_guardian',
            executable='drive_base_node',
            name='drive_base',
            namespace='',
            output='screen')

    drive_base_executable = 'drive_base_node'

    # Make the drive_base node take the 'configure' transition
    drive_base_configure_trans_event = EmitEvent(
        event=ChangeState(
            lifecycle_node_matcher = launch.events.process.matches_executable(drive_base_executable),
            transition_id = lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE,
        )
    )

    # drive_base_set_param = SetParameter('drive_base', )

    # Make the drive_base node take the 'activate' transition
    drive_base_activate_trans_event = EmitEvent(
        event = ChangeState(
            lifecycle_node_matcher = launch.events.process.matches_executable(drive_base_executable),
            transition_id = lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE,
         )
    )

    # Add the actions to the launch description.
    # The order they are added reflects the order in which they will be executed.
    # ld.add_action(drive_base_node)
    ld.add_action(drive_base_activate_trans_event)

    return ld

Expected behavior

the drive_base_node can be activated after the events emitted in activate_drive.launch.py

Actual behavior

the state cannote be activated after launching activate_drive.launch.py

Additional information

actually I do not know if it's a bug report or feature request.

methylDragon commented 1 year ago

Does this work when you use

drive_base_activate_trans_event_by_name = EmitEvent(
        event = ChangeState(
            lifecycle_node_matcher = launch_ros.events.lifecycle.matches_node_name(drive_base_name),
            transition_id = lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE,
         )
    )

?