Actions Quiz (Chapter 10)

Hi,
I’m preparing the code for the Chapter 10 Actions Quiz. I did create my custom message and have the action server running (I can see the topics created with rostopic list | grep action), but I see a warning popping up saying:

 [WARN] [1685251092.880672, 2637.044000]: Your executeCallback did not set the goal to a terminal status.  This is a bug in your ActionServer implementation. Fix your code!  For now, the ActionServer will set this goal to aborted

I’ve been reading online but I can’t find a clear solution. I added the set_succeeded method as I read it could be the problem, but had no luck with it.
Here’s the code:

#! /usr/bin/env python
import rospy
import time
import actionlib

from actions_quiz.msg import CustomActionMsgGoal, CustomActionMsgFeedback, CustomActionMsgAction
from std_msgs.msg import Empty

class MoveSquareClass(object):
    
  # create messages that are used to publish feedback/result
    _feedback = CustomActionMsgFeedback()
    _result   = CustomActionMsgGoal()

    def __init__(self):
        # creates the action server
        self._as = actionlib.SimpleActionServer("/action_custom_msg_as", CustomActionMsgAction, self.goal_callback, False)
        self._as.start()
        self.ctrl_c = False
        self.rate = rospy.Rate(10)
     
 
    def goal_callback(self, goal):

        # define the different publishers and messages that will be used
        self._pub_takeoff = rospy.Publisher('/drone/takeoff', Empty, queue_size=1)
        self._takeoff_msg = Empty()
        self._pub_land = rospy.Publisher('/drone/land', Empty, queue_size=1)
        self._land_msg = Empty()

        if goal == 'Take-off':
            self.take_off(self._takeoff_msg)
            rospy.loginfo("Taking off...")
            self._as.set_succeeded(self._result)

        elif goal == 'Land':
            self.land(self._land_msg)
            rospy.loginfo("Landing...")
            self._as.set_succeeded(self._result)

        else:
            rospy.loginfo("Incorrect Goal!")

    def take_off(self):
        # make the drone takeoff
        i=0
        while not i == 3:
            self._pub_takeoff.publish(self._takeoff_msg)
            rospy.loginfo('Taking off...')
            time.sleep(1)
            i += 1

    def land(self):
        while not i == 3:
            self._pub_land.publish(self._land_msg)
            rospy.loginfo('Landing...')
            time.sleep(1)
            i += 1
        
      
if __name__ == '__main__':
  rospy.init_node('action_custom_msg_as')
  MoveSquareClass()
  rospy.spin()

I’m manually calling the service through the topic publisher:

rostopic pub /action_custom_msg_as/goal actions_quiz/CustomActionMsgActionGoal "header:
  seq: 0
  stamp:
    secs: 0
    nsecs: 0
  frame_id: ''
goal_id:
  stamp:
    secs: 0
    nsecs: 0
  id: ''
goal:
  goal: 'Take-off'"

Any help would be appreciated, thanks in advance!

Hi @roduralde93 ,

The problem is in this part of your code:

The set_succeeded() function will set the terminal state of the goal callback.
This function will help the goal callback to finish. So, whatever might be the action’s result, the set_succeeded function should be set.

Specifically, you have forgotten to set the goal as succeeded in the else case.
The problem here is, even if the goal is “incorrect” the action goal callback must end, therefore, you need to set as succeeded - to show that the action failed, set the result parameter as “failed”. By not setting the goal to succeeded state, you are basically blocking the action’s goal callback from completing.

Your Fixes:

  1. Remove the else block. Just have if goal == "Take-off" and else.
    (OR)
  2. Add the set_succeeded line inside the else block.
    (OR)
  3. Just use one set_succeeded line after the if-elif-else block.

I hope you understood this concept.

Regards,
Girish

Indeed, the warning has disappeared. I just moved the set_succeeded out of the if-elif-else block.
I have other doubts, but I’ll create another topic regarding those to keep this one clean.
Thanks!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.