[ROS2] How to abort an action goal before the server is shutdown?
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 simpleactionserver.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.");
}
Asked by mth_sousa on 2023-05-09 08:06:32 UTC
Answers
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/navigation2/blob/main/nav2_util/include/nav2_util/simple_action_server.hpp
A function for your question you might find interest in is terminate_current
.
Asked by stevemacenski on 2023-05-09 12:57:19 UTC
Comments