Skip to content

Commit

Permalink
Allow setting result in cancel and abort as well
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Clephas <[email protected]>
  • Loading branch information
Timple committed Apr 14, 2024
1 parent e7b1ed5 commit 0cf2d64
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions rclpy/rclpy/action/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0cf2d64

Please sign in to comment.