From 26a7fdc7845b3979f9ca2dff907e090a9718ce1e Mon Sep 17 00:00:00 2001 From: Tim Clephas Date: Wed, 14 Feb 2024 17:56:20 +0100 Subject: [PATCH] Allow setting result in cancel and abort as well Signed-off-by: Tim Clephas --- rclpy/rclpy/action/server.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/rclpy/rclpy/action/server.py b/rclpy/rclpy/action/server.py index e79af03be..106e0ed7c 100644 --- a/rclpy/rclpy/action/server.py +++ b/rclpy/rclpy/action/server.py @@ -120,6 +120,16 @@ def _update_state(self, event): if not self._goal_handle.is_active(): self._action_server.notify_goal_done() + def _set_result(self, response): + # Set result + result_response = self._action_server._action_type.Impl.GetResultService.Response() + result_response.status = self.status + if response is not None: + result_response.result = response + else: + result_response.result = self._action_server._action_type.Result() + self._action_server._result_futures[bytes(self.goal_id.uuid)].set_result(result_response) + def execute(self, execute_callback=None): # It's possible that there has been a request to cancel the goal prior to executing. # In this case we want to avoid the illegal state transition to EXECUTING @@ -151,21 +161,15 @@ def executing(self): def succeed(self, response=None): self._update_state(_rclpy.GoalEvent.SUCCEED) + self._set_result(response) - # Set result - result_response = self._action_server._action_type.Impl.GetResultService.Response() - result_response.status = self.status - if response is not None: - result_response.result = response - else: - result_response.result = self._action_server._action_type.Result() - self._action_server._result_futures[bytes(self.goal_id.uuid)].set_result(result_response) - - def abort(self): + def abort(self, response=None): self._update_state(_rclpy.GoalEvent.ABORT) + self._set_result(response) - def canceled(self): + def canceled(self, response=None): self._update_state(_rclpy.GoalEvent.CANCELED) + self._set_result(response) def destroy(self): with self._lock: