How to exit from a ROS2 lifecycle launch script? [closed]
Hi,
is there a way to interrupt the execution of a ROS2 launch script?
In my case I have a lifecycle node managed by a lifecycle launch script. I would like to stop the execution of the script if the lifecycle node reaches the finalized state:
[...]
node_finalized_state_handler = RegisterEventHandler(
OnStateTransition(
target_lifecycle_node = node,
goal_state = 'finalized',
entities = [
# Log
LogInfo( msg = "'NODE' reached the 'FINALIZED' state." ),
***** INSERT SOMETHING HERE TO EXIT??? *****
],
)
)
[...]
# Add the actions to the launch description.
# The order they are added reflects the order in which they will be executed.
ld.add_action( node_inactive_from_unconfigured_state_handler )
ld.add_action( node_inactive_from_active_state_handler )
ld.add_action( node_active_state_handler )
ld.add_action( node_finalized_state_handler )
ld.add_action( node )
ld.add_action( node_configure_trans_event)
return ld
I cannot find a solution...
Thank you Walter
Update:
I found the OpaqueFunction
action and it seems that I can use it to call sys.exit
, but the script still remains active because the Node is still running and "waiting" in the finalized
state.
So before using sys.kill
I need to kill the running Node... how?