ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

How to exit from a ROS2 lifecycle launch script? [closed]

asked 2018-11-07 09:30:11 -0500

Myzhar gravatar image

updated 2018-11-08 02:43:07 -0500

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?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Myzhar
close date 2018-11-15 07:47:41.136970

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-11-08 12:21:18 -0500

William gravatar image

I would recommend you emit the shutdown event, e.g.:

https://github.com/ros2/launch/blob/a...

edit flag offensive delete link more

Comments

1

Good, it works. Thank you :)

Myzhar gravatar image Myzhar  ( 2018-11-09 08:21:11 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2018-11-07 09:30:11 -0500

Seen: 2,525 times

Last updated: Nov 08 '18