In the below code , when a cancel request has been called the server just breaks out of the for loop and doesn’t return result to action_server/result topic or client . Is there a way to return the result ?
def goal_callback(self, goal):
# this callback is called when the action server is called.
# this is the function that computes the Fibonacci sequence
# and returns the sequence to the node that called the action server
# helper variables
r = rospy.Rate(1)
success = True
# append the seeds for the fibonacci sequence
self._feedback.sequence = []
self._feedback.sequence.append(0)
self._feedback.sequence.append(1)
# publish info to the console for the user
rospy.loginfo('"fibonacci_as": Executing, creating fibonacci sequence of order %i with seeds %i, %i' % ( goal.order, self._feedback.sequence[0], self._feedback.sequence[1]))
# starts calculating the Fibonacci sequence
fibonacciOrder = goal.order
for i in range(1, fibonacciOrder):
# check that preempt (cancelation) has not been requested by the action client
if self._as.is_preempt_requested():
rospy.loginfo('The goal has been cancelled/preempted')
# the following line, sets the client in preempted state (goal cancelled)
self._as.set_preempted()
success = False
# we end the calculation of the Fibonacci sequence
break
# builds the next feedback msg to be sent
self._feedback.sequence.append(self._feedback.sequence[i] + self._feedback.sequence[i-1])
# publish the feedback
self._as.publish_feedback(self._feedback)
# the sequence is computed at 1 Hz frequency
r.sleep()
# at this point, either the goal has been achieved (success==true)
# or the client preempted the goal (success==false)
# If success, then we publish the final result
# If not success, we do not publish anything in the result
if success:
self._result.sequence = self._feedback.sequence
rospy.loginfo('Succeeded calculating the Fibonacci of order %i' % fibonacciOrder )
self._as.set_succeeded(self._result)