ros2 / rclpy

rclpy (ROS Client Library for Python)
Apache License 2.0
291 stars 224 forks source link

ActionServer does not publish initial status #1072

Open CraigBuilds opened 1 year ago

CraigBuilds commented 1 year ago

Bug report

Steps to reproduce issue

ros2 run examples_rclpy_minimal_action_server server
ros2 topic echo /fibonacci/_action/status
ros2 action send_goal /fibonacci example_interfaces/action/Fibonacci '{}'

Expected behavior

topic_echo should show status 1 (ACCEPTED) and then status 2 (EXECUTING)

Actual behavior

It jumps straight to EXECUTING

Additional information

This isn't just a problem with topic echo or the example node, I also have the same problem with my HMI (which uses the ActionClient) and my custom ros2 node.

A workaround is (for humble):

def handle_accepted_callback(goal_handle: ServerGoalHandle) -> None:
        goal_handle._action_server._handle.publish_status()

Or (for foxy)

from rclpy.impl.implementation_singleton import rclpy_action_implementation as _rclpy_action

def handle_accepted_callback(goal_handle: ServerGoalHandle) -> None:
        _rclpy_action.rclpy_action_publish_status(goal_handle._action_server._handle)

And then give this callback to the ActionServer

    ActionServer(
       ...
        handle_accepted_callback=handle_accepted_callback,
    )
fujitatomoya commented 7 months ago

Just FYI, ros2 run examples_rclpy_minimal_action_server server is not appropriate example to defer the goal execution, instead we could use ros2 run examples_rclpy_minimal_action_server server_defer which implements handle_accepted_callback.

even with server_defer, we can observe the reported behavior with rolling branch.

### start server_defer
root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 run examples_rclpy_minimal_action_server server_defer 
[INFO] [1709017447.924342939] [minimal_action_server]: Received goal request
[INFO] [1709017447.925014705] [minimal_action_server]: Deferring execution...
[INFO] [1709017450.933514222] [minimal_action_server]: Executing goal...
[INFO] [1709017450.934203963] [minimal_action_server]: Returning result: array('i', [0, 1])

### send goal request
root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 action send_goal /fibonacci example_interfaces/action/Fibonacci '{}'
...

### echo status topic
root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 topic echo /fibonacci/_action/status --flow-style
status_list: [{goal_info: {goal_id: {uuid: [155, 120, 121, 141, 98, 179, 68, 250, 135, 43, 228, 201, 50, 85, 251, 181]}, stamp: {sec: 1709017557, nanosec: 860342776}}, status: 2}]
---
status_list: [{goal_info: {goal_id: {uuid: [155, 120, 121, 141, 98, 179, 68, 250, 135, 43, 228, 201, 50, 85, 251, 181]}, stamp: {sec: 1709017557, nanosec: 860342776}}, status: 4}]
---

i think that action client does not call publish_status() before execution.