Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] events.process.matches_name() not working. #672

Closed
ZhenshengLee opened this issue Nov 8, 2022 · 1 comment
Closed

[BUG] events.process.matches_name() not working. #672

ZhenshengLee opened this issue Nov 8, 2022 · 1 comment

Comments

@ZhenshengLee
Copy link

Bug report

Required Info:

  • Operating System:
    • Ubuntu22.04
  • Installation type:
    • binary
  • Version or commit hash:
    • apt-newest
  • DDS implementation:
    • rmw_fastrtps_cpp
  • Client library (if applicable):
    • rclcpp and ros2launch

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);

launch activate_drive_emit_event.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 IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import PathJoinSubstitution, TextSubstitution
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
from launch_ros.substitutions import FindPackageShare

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_action = LifecycleNode(
            package='sm_guardian',
            executable='drive_base_node',
            name='drive_base',
            namespace='',
            output='screen')

    drive_base_node_include = IncludeLaunchDescription(
            PythonLaunchDescriptionSource([
                PathJoinSubstitution([
                    FindPackageShare('sm_guardian'),
                    'launch',
                    'drive_base.launch.py'
                ])
            ])
    )

    drive_base_executable = 'drive_base_node'
    drive_base_name = 'drive_base'

    # 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_by_executable = EmitEvent(
        event = ChangeState(
            lifecycle_node_matcher = launch.events.process.matches_executable(drive_base_executable),
            transition_id = lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE,
         )
    )
    drive_base_activate_trans_event_by_name = EmitEvent(
        event = ChangeState(
            lifecycle_node_matcher = launch.events.process.matches_name(drive_base_node_action),
            # lifecycle_node_matcher = launch.events.process.matches_name(drive_base_name),
            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_action)
    ld.add_action(drive_base_node_include)
    ld.add_action(drive_base_activate_trans_event_by_executable)
    # ld.add_action(drive_base_activate_trans_event_by_name)

    return ld

Expected behavior

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

Actual behavior

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

Additional information

matches_executable() works well, see #668

@ZhenshengLee
Copy link
Author

should use this launch_ros.events.lifecycle.matches_node_name

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,
         )
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant