0

我正在尝试实现示例仓库中给出的 ROS2 操作客户端和服务器:https ://github.com/ros2/examples/tree ...(server.py 和 client.py)。一切似乎都正常,但在客户端'get_result_callback' 永远不会被调用。在服务器端,我正在使用以下不退出执行回调的函数。

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

我没有更改代码中的任何内容**

这里可能是什么问题?

4

1 回答 1

2

我更换了:

goal_handle.succeed()

goal_handle.set_succeeded()

它按预期工作。

于 2019-05-20T10:10:41.737 回答