Skip to content

Commit 967eeeb

Browse files
author
Pedro Miguel Melo
committed
Publishing missing status messages for SUCCEEDED and PREEMPTED cases.
1 parent e8dbbd3 commit 967eeeb

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

src/roslibpy/actionlib.py

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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,26 @@ def set_succeeded(self, result):
428432
LOGGER.info("Action server {} setting current goal to SUCCEEDED".format(self.server_name))
429433

430434
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+
431444
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+
}
433452
)
434-
435453
self.result_publisher.publish(result_message)
436454

437-
self.status_message["status_list"] = []
438-
439455
if self.next_goal:
440456
self.current_goal = self.next_goal
441457
self.next_goal = None
@@ -465,11 +481,23 @@ def set_preempted(self):
465481
LOGGER.info("Action server {} preempting current goal".format(self.server_name))
466482

467483
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()
468491
self.status_message["status_list"] = []
492+
469493
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+
}
471500
)
472-
473501
self.result_publisher.publish(result_message)
474502

475503
if self.next_goal:

0 commit comments

Comments
 (0)