@@ -326,7 +326,7 @@ def __init__(self, ros, server_name, action_name):
326
326
327
327
# Intentionally not publishing immediately and instead
328
328
# 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 )
330
330
331
331
def start (self , action_callback ):
332
332
"""Start the action server.
@@ -349,18 +349,22 @@ def _internal_preempt_callback():
349
349
self .on ("cancel" , _internal_preempt_callback )
350
350
351
351
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 ):
352
362
# Status publishing is required for clients to know they've connected
353
363
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 ()
361
365
362
366
# 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 )
364
368
365
369
def _on_goal_message (self , message ):
366
370
will_cancel = False
@@ -428,14 +432,26 @@ def set_succeeded(self, result):
428
432
LOGGER .info ("Action server {} setting current goal to SUCCEEDED" .format (self .server_name ))
429
433
430
434
with self ._lock :
435
+
436
+ self .status_message ["status_list" ] = [
437
+ dict (
438
+ goal_id = self .current_goal ["goal_id" ],
439
+ status = GoalStatus .SUCCEEDED )
440
+ ]
441
+ self ._publish_status ()
442
+ self .status_message ["status_list" ] = []
443
+
431
444
result_message = Message (
432
- {"status" : {"goal_id" : self .current_goal ["goal_id" ], "status" : GoalStatus .SUCCEEDED }, "result" : result }
445
+ {
446
+ "status" : {
447
+ "goal_id" : self .current_goal ["goal_id" ],
448
+ "status" : GoalStatus .SUCCEEDED
449
+ },
450
+ "result" : result
451
+ }
433
452
)
434
-
435
453
self .result_publisher .publish (result_message )
436
454
437
- self .status_message ["status_list" ] = []
438
-
439
455
if self .next_goal :
440
456
self .current_goal = self .next_goal
441
457
self .next_goal = None
@@ -465,11 +481,23 @@ def set_preempted(self):
465
481
LOGGER .info ("Action server {} preempting current goal" .format (self .server_name ))
466
482
467
483
with self ._lock :
484
+
485
+ self .status_message ["status_list" ] = [
486
+ dict (
487
+ goal_id = self .current_goal ["goal_id" ],
488
+ status = GoalStatus .PREEMPTED )
489
+ ]
490
+ self ._publish_status ()
468
491
self .status_message ["status_list" ] = []
492
+
469
493
result_message = Message (
470
- {"status" : {"goal_id" : self .current_goal ["goal_id" ], "status" : GoalStatus .PREEMPTED }}
494
+ {
495
+ "status" : {
496
+ "goal_id" : self .current_goal ["goal_id" ],
497
+ "status" : GoalStatus .PREEMPTED
498
+ }
499
+ }
471
500
)
472
-
473
501
self .result_publisher .publish (result_message )
474
502
475
503
if self .next_goal :
0 commit comments