ros2 launch lifecycle callback component
It turns out that launching a lifecycle node which is also a component is way harder than expected.
This link shows how to launch a lifecycle, but does not accept a component for the change_state callbacks, obviously. https://raw.githubusercontent.com/ros...
This link is an example of how to launch a component, but does not accept a lifecycle node. https://github.com/astuff/pacmod3/blo...
I tried to add a client node to the launch file which should call the change_state service, but lifecycle nodes are not yet supported in python.
Is there a way to combine the two, so that I can launch a lifecycle component and automatically execute callbacks when it reaches certain states?
Or maybe, can such an event handler be added to an already existing node/service?
register_event_handler_for_talker_reaches_inactive_state = launch.actions.RegisterEventHandler(
launch_ros.event_handlers.OnStateTransition(
target_lifecycle_node=talker_node, goal_state='inactive',
entities=[
launch.actions.LogInfo(
msg="node 'talker' reached the 'inactive' state, 'activating'."),
launch.actions.EmitEvent(event=launch_ros.events.lifecycle.ChangeState(
lifecycle_node_matcher=launch.events.matches_action(talker_node),
transition_id=lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE,
)),
],
)
)