@@ -326,7 +326,7 @@ def __init__(self, ros, server_name, action_name):
326326
327327 # Intentionally not publishing immediately and instead
328328 # waiting one interval for the first message
329- self .ros .call_later (self .STATUS_PUBLISH_INTERVAL , self ._publish_status )
329+ self .ros .call_later (self .STATUS_PUBLISH_INTERVAL , self ._periodic_publish_status )
330330
331331 def start (self , action_callback ):
332332 """Start the action server.
@@ -349,18 +349,22 @@ def _internal_preempt_callback():
349349 self .on ("cancel" , _internal_preempt_callback )
350350
351351 def _publish_status (self ):
352+ current_time = time .time ()
353+ secs = int (math .floor (current_time ))
354+ nsecs = int (round (1e9 * (current_time - secs )))
355+
356+ self .status_message ["header" ]["stamp" ]["secs" ] = secs
357+ self .status_message ["header" ]["stamp" ]["nsecs" ] = nsecs
358+
359+ self .status_publisher .publish (self .status_message )
360+
361+ def _periodic_publish_status (self ):
352362 # Status publishing is required for clients to know they've connected
353363 with self ._lock :
354- current_time = time .time ()
355- secs = int (math .floor (current_time ))
356- nsecs = int (round (1e9 * (current_time - secs )))
357-
358- self .status_message ["header" ]["stamp" ]["secs" ] = secs
359- self .status_message ["header" ]["stamp" ]["nsecs" ] = nsecs
360- self .status_publisher .publish (self .status_message )
364+ self ._publish_status ()
361365
362366 # Invoke again in the defined interval
363- self .ros .call_later (self .STATUS_PUBLISH_INTERVAL , self ._publish_status )
367+ self .ros .call_later (self .STATUS_PUBLISH_INTERVAL , self ._periodic_publish_status )
364368
365369 def _on_goal_message (self , message ):
366370 will_cancel = False
@@ -428,14 +432,14 @@ def set_succeeded(self, result):
428432 LOGGER .info ("Action server {} setting current goal to SUCCEEDED" .format (self .server_name ))
429433
430434 with self ._lock :
431- result_message = Message (
432- {"status" : {"goal_id" : self .current_goal ["goal_id" ], "status" : GoalStatus .SUCCEEDED }, "result" : result }
433- )
435+ status = dict (goal_id = self .current_goal ["goal_id" ], status = GoalStatus .SUCCEEDED )
436+ self .status_message ["status_list" ] = [status ]
437+ self ._publish_status ()
438+ self .status_message ["status_list" ] = []
434439
440+ result_message = Message ({"status" : status , "result" : result })
435441 self .result_publisher .publish (result_message )
436442
437- self .status_message ["status_list" ] = []
438-
439443 if self .next_goal :
440444 self .current_goal = self .next_goal
441445 self .next_goal = None
@@ -465,11 +469,12 @@ def set_preempted(self):
465469 LOGGER .info ("Action server {} preempting current goal" .format (self .server_name ))
466470
467471 with self ._lock :
472+ status = dict (goal_id = self .current_goal ["goal_id" ], status = GoalStatus .PREEMPTED )
473+ self .status_message ["status_list" ] = [status ]
474+ self ._publish_status ()
468475 self .status_message ["status_list" ] = []
469- result_message = Message (
470- {"status" : {"goal_id" : self .current_goal ["goal_id" ], "status" : GoalStatus .PREEMPTED }}
471- )
472476
477+ result_message = Message ({"status" : status })
473478 self .result_publisher .publish (result_message )
474479
475480 if self .next_goal :
0 commit comments