我正在尝试实现示例回购示例https://github.com/ros2/examples/tree ...(server.py和client.py)中提供的ROS2操作客户端和服务器。一切似乎都正常,但在客户端“ get_result_callback”从未调用过。在服务器端,我正在使用以下函数,该函数不会退出execute回调。
async def execute_callback(self, goal_handle):
"""Executes a goal."""
self.get_logger().info('Executing goal...')
# Append the seeds for the Fibonacci sequence
feedback_msg = Fibonacci.Feedback()
feedback_msg.sequence = [0, 1]
# Start executing the action
for i in range(1, goal_handle.request.order):
if goal_handle.is_cancel_requested:
goal_handle.canceled()
self.get_logger().info('Goal canceled')
return Fibonacci.Result()
# Update Fibonacci sequence
feedback_msg.sequence.append(feedback_msg.sequence[i] + feedback_msg.sequence[i-1])
self.get_logger().info('Publishing feedback: {0}'.format(feedback_msg.sequence))
# Publish the feedback
goal_handle.publish_feedback(feedback_msg)
# Sleep for demonstration purposes
time.sleep(1)
print('before success')
goal_handle.succeed()
print('after success')
# Populate result message
result = Fibonacci.Result()
result.sequence = feedback_msg.sequence
self.get_logger().info('Returning result: {0}'.format(result.sequence))`
结果:
[INFO] [minimal_action_server]: Received goal request
[INFO] [minimal_action_server]: Executing goal...
[INFO] [minimal_action_server]: Publishing feedback: [0, 1, 1]
[INFO] [minimal_action_server]: Publishing feedback: [0, 1, 1, 2]
[INFO] [minimal_action_server]: Publishing feedback: [0, 1, 1, 2, 3]
[INFO] [minimal_action_server]: Publishing feedback: [0, 1, 1, 2, 3, 5]
[INFO] [minimal_action_server]: Publishing feedback: [0, 1, 1, 2, 3, 5, 8]
[INFO] [minimal_action_server]: Publishing feedback: [0, 1, 1, 2, 3, 5, 8, 13]
[INFO] [minimal_action_server]: Publishing feedback: [0, 1, 1, 2, 3, 5, 8, 13, 21]
[INFO] [minimal_action_server]: Publishing feedback: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
[INFO] [minimal_action_server]: Publishing feedback: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
before success
我没有更改代码中的任何内容**
这里可能是什么问题?
答案 0 :(得分:1)
我替换了:
goal_handle.succeed()
使用
goal_handle.set_succeeded()
它按预期工作。