How to cancel goals from within an action server?
An action server exposes the hook cancel_all_goals()
to clients can clear any running actions. However, how would you do this from within the server itself? I can't find any equivalent method in the SimpleActionServer instance.
I'm trying to write an action server that manages several different "classes" of pre-emptivable actions, and the client doesn't need to be aware of any running actions, so to simplify access, I want the server to automatically cancel any actions its running if a client starts a new one.
I tried instantiated a SimpleActionClient inside the server to connect to itself and cancel_all_goals()
the way a client would, but when I do this the call to cancel_all_goals()
hangs indefinitely, even when there are no actions running.
Asked by Cerin on 2016-05-03 20:53:11 UTC
Answers
As @Javier mentioned in the comments the cancellation of a goal is done automatically. In order to handle multiple action servers at once you have to create a minimalistic SimpleActionClient
for each action server (except for the one that cancels all of the other servers). Such a client will have only one task namely sending an empty goal of type X to the server which processes the respective action. By doing so you are exploiting (in a perfectly decent manner) the automatic preemption of the SimpleActionServer
so each of the other action servers will receive it, do nothing but also cancel the goal each is currently executing. I would suggest (I'm also about to test it with my own code) that you trigger a cancel
request using all the action clients and send to all the respective action servers. The triggering itself needs to be done inside the callback of the action server that needs to cancel all other servers.
Asked by rbaleksandar on 2016-06-27 06:55:19 UTC
Comments
The SimpleActionServer automatically preempts the current goal if a new one arrives. Is this behavior not enough?
Asked by Javier V. Gómez on 2016-05-04 04:04:43 UTC
No. I have a node with multiple action servers, one for each action, so one needs to preempt any action running on other servers.
Asked by Cerin on 2016-05-04 09:11:18 UTC