@@ -161,6 +161,16 @@ def _update_state(self, event: _rclpy.GoalEvent) -> None:
161161 if not self ._goal_handle .is_active ():
162162 self ._action_server .notify_goal_done ()
163163
164+ def _set_result (self , response : Optional [ResultT ]) -> None :
165+ # Set result
166+ result_response = self ._action_server ._action_type .Impl .GetResultService .Response ()
167+ result_response .status = self .status
168+ if response is not None :
169+ result_response .result = response
170+ else :
171+ result_response .result = self ._action_server ._action_type .Result ()
172+ self ._action_server ._result_futures [bytes (self .goal_id .uuid )].set_result (result_response )
173+
164174 def execute (
165175 self ,
166176 execute_callback : Optional [Callable [['ServerGoalHandle[GoalT, ResultT, FeedbackT]' ],
@@ -170,7 +180,7 @@ def execute(
170180 # In this case we want to avoid the illegal state transition to EXECUTING
171181 # but still call the users execute callback to let them handle canceling the goal.
172182 if not self .is_cancel_requested :
173- self ._update_state ( _rclpy . GoalEvent . EXECUTE )
183+ self .executing ( )
174184 self ._action_server .notify_execute (self , execute_callback )
175185
176186 def publish_feedback (self , feedback : FeedbackMessage [FeedbackT ]) -> None :
@@ -191,14 +201,20 @@ def publish_feedback(self, feedback: FeedbackMessage[FeedbackT]) -> None:
191201 # Publish
192202 self ._action_server ._handle .publish_feedback (feedback_message )
193203
194- def succeed (self ) -> None :
204+ def executing (self ) -> None :
205+ self ._update_state (_rclpy .GoalEvent .EXECUTE )
206+
207+ def succeed (self , response : Optional [ResultT ] = None ) -> None :
195208 self ._update_state (_rclpy .GoalEvent .SUCCEED )
209+ self ._set_result (response )
196210
197- def abort (self ) -> None :
211+ def abort (self , response : Optional [ ResultT ] = None ) -> None :
198212 self ._update_state (_rclpy .GoalEvent .ABORT )
213+ self ._set_result (response )
199214
200- def canceled (self ) -> None :
215+ def canceled (self , response : Optional [ ResultT ] = None ) -> None :
201216 self ._update_state (_rclpy .GoalEvent .CANCELED )
217+ self ._set_result (response )
202218
203219 def destroy (self ) -> None :
204220 with self ._lock :
@@ -233,7 +249,8 @@ def __init__(
233249 node : 'Node' ,
234250 action_type : Type [Action ],
235251 action_name : str ,
236- execute_callback : Callable [[ServerGoalHandle [GoalT , ResultT , FeedbackT ]], ResultT ],
252+ execute_callback : Optional [Callable [[ServerGoalHandle [GoalT , ResultT , FeedbackT ]],
253+ ResultT ]] = None ,
237254 * ,
238255 callback_group : 'Optional[CallbackGroup]' = None ,
239256 goal_callback : Callable [[CancelGoal .Request ], GoalResponse ] = default_goal_callback ,
@@ -283,7 +300,11 @@ def __init__(
283300 self .register_handle_accepted_callback (handle_accepted_callback )
284301 self .register_goal_callback (goal_callback )
285302 self .register_cancel_callback (cancel_callback )
286- self .register_execute_callback (execute_callback )
303+ if execute_callback :
304+ self .register_execute_callback (execute_callback )
305+ elif handle_accepted_callback is default_handle_accepted_callback :
306+ self ._logger .warning (
307+ 'Not handling nor executing the goal, this server will do nothing' )
287308
288309 # Import the typesupport for the action module if not already done
289310 check_for_type_support (action_type )
0 commit comments