如何返回一个结果表明我正在 ros2 ActionServer 中执行?

发布于 2025-01-19 09:37:14 字数 934 浏览 2 评论 0原文

下面的代码是ROS2 DOC的示例回调,该回调已在Actieserver中执行,它返回了该目标已成功。

但是我想创建一些返回我正在执行的客户的东西,或者仅通过反馈而做出可能?

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

我试图在goal_handle中找到一种方法,该方法说任务只是执行,但我找不到,我发现刚刚成功,流产和取消。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷弦 2025-01-26 09:37:14

创建 ROS-ROS2 操作是为了异步执行长时间运行的流程/任务。在服务器端,您应该在执行长时间运行的任务期间发布反馈

在客户端,您可以调用 send_goal_async 并在 while 循环中旋转,直到完成您的目标。

您可以参考我在此处编写的示例操作;

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;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文