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

[ROS2] How to abort an action goal before the server is shutdown?

asked 2023-05-09 08:06:32 -0600

mth_sousa gravatar image

On ROS 1, when I pressed ctrl + C on the action server node, it could abort the goal and notify the action client. How can I replicate this behavior on ROS 2?

The action client gets stuck while waiting for the goal response on ROS 2. I tried to implement a callback using rclcpp::on_shutdown() to end the goal, but I got an error saying only "Asked to publish result for goal that does not exist.".

My action server was implemented using simple_action_server.h on ROS 1.

The on_shutdown() callback code is:

void ActionServer::cleanActionServer(){

    try {
        if (goal_pointer != nullptr){
            action_result->error_code = -99;
            action_result->error_string = "Shutdown";
            goal_pointer->abort(action_result);
        }
    }
    catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << '\n';
    }

    RCLCPP_INFO(rclcpp::get_logger("driver_end"), "Called on shutdown.");
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-05-09 12:57:19 -0600

updated 2023-05-09 12:57:53 -0600

Same kind of idea, but you have to abort the action goal handle, not the server. You can see an example of how we wrote a simplifying wrapper for ROS 2 actions in Nav2 here: https://github.com/ros-planning/navig...

A function for your question you might find interest in is terminate_current.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2023-05-09 08:06:32 -0600

Seen: 1,008 times

Last updated: May 09 '23