Ros basics exercise 9.13

i keep getting that error and do not know why

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

my server code using python

#! /usr/bin/env python 

import rospy 
import actionlib
from actionlib.msg import TestAction , TestResult , TestFeedback
from geometry_msgs.msg import Twist 
from std_msgs.msg import Empty
import time

class exercise(object):

    result = TestResult()
    feedback = TestFeedback()

    def __init__(self):
      self.server = actionlib.SimpleActionServer("exercise" , TestAction , self.goal_calback , False)
      self.pub = rospy.Publisher("/cmd_vel" , Twist , queue_size=1)
      self.takeoff = rospy.Publisher("/drone/takeoff" , Empty , queue_size=1)
      self.land = rospy.Publisher("/drone/land" , Empty , queue_size=1)
      self.server.start()
      self.move = Twist()


    def goal_calback(self,goal):
        r = rospy.Rate(1)
        success = True
        
        self.feedback.feedback = 1

        rospy.loginfo("exercise action is now executing")
        
        time_ = 3 
        distance = goal.goal
        speed = distance/time_ 
        count = 1 
        
        i = 0 
        start_time = time.time()
        for i in range(4):

            if self.server.is_preempt_requested():
               rospy.loginfo("the goal has been canceled")
               self.server.set_preempted()
               success = False
               break

            self.server.publish_feedback(self.feedback.feedback)
            self.feedback.feedback += 1

            self.takeoff.publish(Empty())

            if count == 1 or count == 3 :
                self.move.linear.x = speed
                self.move.angular.z = 0 
                self.pub.publish(self.move)
                count += 1
                rospy.sleep(3)

            if count == 2 or count == 4 :
                self.move.linear.y = speed
                self.move.angular.z = 0 
                self.pub.publish(self.move)
                count +=1
                rospy.sleep(3)
            
            r.sleep()
        self.land.publish(Empty())
        end_time = time.time()
        if success == True: 
            self.result.result = end_time - start_time
            rospy.loginfo("the operation succed")
            self.server.set_succeeded(self.result)
                 
            


if __name__ == '__main__':
   rospy.init_node("my_server")
   exercise()
   rospy.spin()






            
           
        




Hi @80601 ,

I just see one issue in your program:

self.server.publish_feedback(self.feedback.feedback) # this line is wrong
self.server.publish_feedback(self.feedback) # this line is correct

I see that you have a different movement logic but I see no issues with your Action Server callback’s program flow.
You have this line self.server.set_succeeded(self.result) in your program, so terminal condition is set. However I do not know how your program would work, so must debug if there are issues.

Try the suggested correction above, maybe, that will fix your program.

Regards,
Girish

1 Like

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