ROS WIKI, actionlib tutorials
I'm following the actionlib_tutorials from the ros wiki page and encounter this error.
" To transition to a succeeded state, the goal must be in a preempting or active state, it is currently in the state 3".
How can I solve it and what's the problem? Thanks in advance!
#! /usr/bin/env python
import rospy
import actionlib
import actionlib_tutorials.msg
class FibonacciAction(object):
_feedback = actionlib_tutorials.msg.FibonacciFeedback()
_result = actionlib_tutorials.msg.FibonacciResult()
def __init__ (self, name):
self._action_name = name
self._as = actionlib.SimpleActionServer(self._action_name, actionlib_tutorials.msg.FibonacciAction, execute_cb =
self.execute_cb, auto_start = False)
self._as.start()
def execute_cb(self, goal):
r = rospy.Rate(1)
success = True
self._feedback.sequence = []
self._feedback.sequence.append(0)
self._feedback.sequence.append(1)
rospy.loginfo('%s: Executing, creating fibonacci sequence of oreder %i with seeds %i, %i' %(self._action_name, goal.order, self._feedback.sequence[0], self._feedback.sequence[1]))
for i in range(1, goal.order):
if self._as.is_preempt_requested():
rospy.loginfo('%s: Preempted' %self._action_name)
self._as.set_preempted()
success = False
break
self._feedback.sequence.append(self._feedback.sequence[i] + self._feedback.sequence[i-1])
self._as.publish_feedback(self._feedback)
r.sleep()
if success:
self._result.sequence = self._feedback.sequence
rospy.loginfo('%s: Succeeded' %self._action_name)
self._as.set_succeeded(self._result)
if __name__ == '__main__':
rospy.init_node('fibonacci')
rospy.loginfo('Starting the node.')
server = FibonacciAction(rospy.get_name())
rospy.spin()
And here is the client code
#! /usr/bin/env python
from __future__ import print_function
import rospy
import actionlib
import actionlib_tutorials.msg
def fibonacci_client():
client = actionlib.SimpleActionClient('fibonacci', actionlib_tutorials.msg.FibonacciAction)
client.wait_for_server()
goal = actionlib_tutorials.msg.FibonacciGoal(order = 20)
client.send_goal(goal)
client.wait_for_result()
return client.get_result()
if __name__ == '__main__':
try:
rospy.init_node('fibonacci_client_node', anonymous = False)
result = fibonacci_client()
print("Result:", ', '.join([str(n) for n in result.sequence]))
except rospy.ROSInterruptException:
print("program interrupted before completion", file=sys.stderr)