Proper handling of cancelled actionlib goal

asked 2021-01-08 16:43:36 -0500

chives_onion gravatar image

I have an actionlib SimpleActionServer with the purpose of processing sonar data and manual movement commands and selectively republishing the movement commands if the sonar data does not indicate the potential for a collision. Since the server needs to be active for an unspecified amount of time and doesn't have an explicit goal, my current approach is to cancel the goal when I no longer want to be in manual control. Within the goal execution, I subscribe to a custom sonar data topic. I want to unsubscribe from the topic when I cancel the goal to avoid running the callback when the data is not actively in use, but the unregister is never called.

Snippet of the action server:

def execute(self, goal):

    rospy.loginfo("Executing Manual Control Server")
    sub_sonar = rospy.Subscriber("/sonar_triggered", sonarTriggered, self.cb_sonar_adjust)

    while not self.server.is_preempt_requested():
    #I've also tried while self.server.is_active():
        wait for mvmt command, compare to sonar data, publish if OK

    #following lines never run
    rospy.logwarn("exiting manual server execution")

Snippet of my client (which is contained in a FlexBe state)

def on_exit(self, userdata):

    if not self._client.has_result(self._action_topic):
        Logger.loginfo('Cancelled active action goal.')

I know my approach is wrong since it doesn't look like the self.server.is_preempt_requested() takes into account a cancelled goal, but there isn't an equivalent self.server.is_cancelled() for me to use. This may be a XY problem where I'm really looking for a way to execute a function following the main execute of the actionserver, but I don't know enough about actionlib to identify the best path forward. Any tips would be appreciated.

edit retag flag offensive close merge delete


Hi, were you able to solve this issue? I'm stuck here as well

ThreeForElvenKings gravatar image ThreeForElvenKings  ( 2022-10-19 20:23:57 -0500 )edit