To transition to an aborted state, the goal must be in a preempting or active state, it is currently in state: 2

The topic of this question is the error I am receiving.

I am typing a program which runs the ACTION Server while the robot does a task of wall following. I am not sure why the state of action is at ‘2’ while it should remain in state ‘Active’ or ‘1’ until pre-empted to return a result.
I am not sure even I understand my question.
I am leaving out the import section.
The program below is for the client.

#! /usr/bin/env python
#service calling program

import rospy
import actionlib
from geometry_msgs.msg import Twist
from std_msgs.msg import Empty
from sensor_msgs.msg import LaserScan
from rosject.srv import findwall, findwallRequest
from rosject.msg import OdomRecordActionFeedback, OdomRecordActionResult, OdomRecordActionGoal, OdomRecordAction



rospy.init_node('projectcall')
rospy.wait_for_service('/find_wall')
service_variable = rospy.ServiceProxy('/find_wall', findwall)
obj = findwallRequest()
result = service_variable(obj)
rospy.loginfo('Service FindWall accomplished')
rate = rospy.Rate(1)
PENDING = 0
ACTIVE = 1
DONE = 2
WARN = 3
ERROR = 4

action_server_name = 'record_odom'
client = actionlib.SimpleActionClient(action_server_name, OdomRecordAction)
rospy.loginfo('Waiting for action Server '+action_server_name)
client.wait_for_server()
rospy.loginfo('Action Server Found...'+action_server_name)


def feedback_callback(feedback):
    print('i am printing feedback')
    

def callback(msg):
    # logic for wall following
    client.send_goal(Empty(), feedback_cb=feedback_callback)
    state_result = client.get_state()

    while state_result< DONE:
        rospy.loginfo("Doing Stuff while waiting for the Server to give a result....")
        print("Progrma for wall following continues")
        rate.sleep()
        state_result = client.get_state()
        rospy.loginfo('state result', state_result)
    if state_result == DONE:
        print('Success')
    elif state_result == WARN:
        print('WARNING')
    else:
        print('ERROR')

    rate.sleep()
    
    
    


pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
var = Twist()
sub = rospy.Subscriber('/scan', LaserScan, callback)
rospy.spin()

This program is for the Action Server:

#! /usr/bin/env python

import rospy
import actionlib
from rosject.msg import OdomRecordResult, OdomRecordFeedback, OdomRecordAction
from geometry_msgs.msg import Point
from nav_msgs.msg import Odometry
import math

    
class OdometryClass(object):

    _feedback = OdomRecordFeedback()
    _result= OdomRecordResult()

    def __init__(self):
    # creating action server
        self._as = actionlib.SimpleActionServer('record_odom', OdomRecordAction, self.goal_callback, False)
        self._as.start()
        rospy.init_node('Coordinates', anonymous = True)
        rospy.Subscriber('/odom', Odometry,self.callback)
        #self._pub = rospy.Publisher('cmd_vel',Twist,queue_size=1)
        self.rate = rospy.Rate(1)

    def goal_callback(self,goal):
        print('Goal Recieved')
        rospy.Subscriber('/odom', Odometry,self.callback)
        success = True
        self.i = 0
        while True:

            if self._as.is_preempt_requested():
                success = False
                self._as.set_preempted()
                break
            self.instance_variable.x.append(self.a)
            self.instance_variable.y.append(self.b)
            self.instance_variable.z.append(self.c)

            self._feedback.current_total = math.hypot(self.instance_variable.x[self.i+1]-self.instance_variable.x[self.i], self.instance_variable.y[self.i+1]-self.instance_variable.y[self.i])
            self._as.publish_feedback(self._feedback)
            self.i += 1
            print ('current distance travelled ', self._feedback.current_total)
            self.rate.sleep()
        if not success:
            self._result.list_of_odoms = self.instance_variable
            rospy.loginfo('The list of cordintes', self._result.list_of_odoms )
            self._as.set_succeeded(self._result)

    def callback(self,msg):
        self.instance_variable = Point()
        self.instance_variable.x = [0]
        self.instance_variable.y = [0]
        self.instance_variable.z = [0]
        self.i = 0

        #self._pub.publish(speed)
        while True:
            self.a = msg.pose.pose.position.x
            self.b = msg.pose.pose.position.y
            self.c = msg.pose.pose.position.z
            self.rate.sleep()
    

if __name__ == '__main__':
    rospy.init_node('Coordinates', anonymous = True)
    OdometryClass()
    rospy.spin()

Thank you for the help

Hi Momokiz97, could you refrain the question?

Yours sincerely,
Josh the RAT

Hi @JoshTheRat ,

Welcome to this Community!

The word “refrain” means to avoid. Did you mean “rephrase” or “refine”?

Regards,
Girish

Hi @mamojiz97 ,

Could you edit your programs as a code-block.
Refer code-block: Extended Syntax | Markdown Guide

Regards,
Girish

1 Like