[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 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.");
}