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

[SOLVED] [ROS2 humble linux] Wait until a node has been destroyed in launch_testing

asked 2023-03-31 05:30:53 -0500

LastStarDust gravatar image

updated 2023-03-31 08:22:35 -0500

Hello. This is what I am trying to do:

  1. Create a lifecycle-managed C++ node using launch_testing
  2. Perform a test on the node
  3. Stop the node
  4. Wait until the node has been destroyed
  5. Exit the test

My question is: how would you approach problem 4.?


Here is what I came up with:

  • inside the node under test:

    LifecycleNodeInterface::CallbackReturn on_shutdown(const rclcpp_lifecycle::State& state) {
        RCLCPP_INFO(get_logger(), "on shutdown() is called from state %s.", state.label().c_str());
        std::raise(SIGINT);
        return LifecycleNode::on_shutdown(state);
    }
    
  • inside the test routine:

    proc_info.assertWaitForShutdown(process=node, timeout=60)
    

This is working somehow but it is ugly as hell. Why should I manually raise SIGINT just to destroy a node?

I have tried to use theTRANSITION_DESTROY but run into this bug.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-03-31 08:22:16 -0500

LastStarDust gravatar image

I solved the problem by adding this action to the launch description:

destroy_node = RegisterEventHandler(
    OnStateTransition(
        target_lifecycle_node=node,
        start_state="shuttingdown",
        goal_state="finalized",
        entities=[
            EmitEvent(event=ShutdownProcess(process_matcher=matches_action(node))),
        ],
    )
)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2023-03-31 05:30:53 -0500

Seen: 670 times

Last updated: Mar 31 '23