How to return a result that says that I'm executing in a ros2 ActionServer?

Viewed 196

The code below is the ros2 doc's example callback that's executed in an ActionServer, it returns that the goal was suceeded.

But I want to create something that returns to the client that I'm executing or that's possible just by feedbacks?

def execute_callback(self, goal_handle):
        self.get_logger().info('Executing goal...')

        feedback_msg = Fibonacci.Feedback()
        feedback_msg.partial_sequence = [0, 1]

        for i in range(1, goal_handle.request.order):
            feedback_msg.partial_sequence.append(
                feedback_msg.partial_sequence[i] + feedback_msg.partial_sequence[i-1])
            self.get_logger().info('Feedback: {0}'.format(feedback_msg.partial_sequence))
            goal_handle.publish_feedback(feedback_msg)
            time.sleep(1)

        goal_handle.succeed()

        result = Fibonacci.Result()
        result.sequence = feedback_msg.partial_sequence
        return result

I tried to find a method in the goal_handle that says that the task is just executing but I coudn't find, I found just succeded, abort and canceled.

1 Answers

ROS-ROS2 actions are created to execute a long-running process/task asynchronously. On the server side, you should be publishing feedback during the execution of the long-running task.

On the client-side You can call send_goal_async and spin in a while loop until your goal is done.

You can refer to a sample action that I wrote in here;

Related