pyrobosim: ROS 2 action clients don't receive cancellation response
The WorldROSWrapper exposes actions and services to the ROS 2 network and makes it possible to request actions or query services. In the case of ROS 2 actions I’ve found, that the individual rclpy.action.ActionServer instances might not be implemented correctly, since action clients are not able to receive a response for a cancellation request.
How to reproduce
-
Start the GUI and the default word running
pyrobosim_ros/examples/demo.py -
Send a simple
Navigateaction request. This is can be done using the terminalros2 action send_goal /execute_action pyrobosim_msgs/action/ExecuteTaskAction "{action: {type: navigate, robot: robot, target_location: bathroom}}" -
Send a cancellation request by interrupting the terminal process pressing
Ctrl+C
Expected output
Usually, the program would print something like this if the cancellation request was sent and the corresponding response received correctly:
Waiting for an action server to become available...
Sending goal:
action:
robot: robot
type: navigate
object: ''
room: ''
source_location: ''
target_location: bathroom
cost: 0.0
has_pose: false
pose:
position:
x: 0.0
y: 0.0
z: 0.0
orientation:
x: 0.0
y: 0.0
z: 0.0
w: 1.0
path:
poses: []
length: 0.0
Goal accepted with ID: 32789fe07b644411b0611d1f0b7e6f02
Canceling goal...
Goal canceled. # <-- This should appear if the cancellation request was accepted and the client received the response.
Actual output
Instead, I receive an error message immediately after I requested to cancel with Ctrl+C.
Waiting for an action server to become available...
Sending goal:
action:
robot: robot
type: navigate
object: ''
room: ''
source_location: ''
target_location: bathroom
cost: 0.0
has_pose: false
pose:
position:
x: 0.0
y: 0.0
z: 0.0
orientation:
x: 0.0
y: 0.0
z: 0.0
w: 1.0
path:
poses: []
length: 0.0
Goal accepted with ID: 32789fe07b644411b0611d1f0b7e6f02
Canceling goal...
Exception while canceling goal: None # <-- Instead, one observes this
Refer to ros2cli/ros2action for more information about the methods that are called during a ros2 action send_goal command.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (15 by maintainers)
Just merged. Thanks again for bringing this up.
I also look forward to seeing what you end up doing on your repo. If you have any usage examples to share, you can add them to https://github.com/sea-bass/pyrobosim/blob/main/docs/source/index.rst#usage-examples
And generally, let me know as anything else comes up.
Small update: I just cloned your pull request #311 and my application (the real one, not the CLI) now works correctly. My client is now able to successfully receive the response to the cancel request and conclude the cancellation on its side.
The actual problem was in fact that
cancel_action_callbackwas blocked byrobot.cancel_actions. So changing this https://github.com/sea-bass/pyrobosim/blob/1d356945c59c2ebaaa1e297d94dea5dc84ccc603/pyrobosim_ros/pyrobosim_ros/ros_interface.py#L436-L440 to this https://github.com/sea-bass/pyrobosim/blob/60c73cb3ef6c3dd3d053dcf2374ba93ac3cbbc83/pyrobosim_ros/pyrobosim_ros/ros_interface.py#L439-L443 did the trick!However, the other change is also needed to correctly respond to the cancellation request on the client side! https://github.com/sea-bass/pyrobosim/blob/60c73cb3ef6c3dd3d053dcf2374ba93ac3cbbc83/pyrobosim_ros/pyrobosim_ros/ros_interface.py#L423-L427
Two birds with one stone!
Thanks for your time! I guess there is still an issue with rclpy or ros2cli but let’s see…
PS: Great work with pyrobosim! It’s awesome to have a lightweight platform for behavior prototyping and demonstration. I’m currently integrating this project in one of my repo’s to allow users to quickly validate their programs and I’m really happy to have come across pyrobosim. So it would be awesome if you could merge this soon 😃
Oof… it also seems to me that it should work. Just note, that there should probably also be some more logic that also determines when a cancel request should be rejected similar to this
https://github.com/sea-bass/pyrobosim/blob/1d356945c59c2ebaaa1e297d94dea5dc84ccc603/pyrobosim/pyrobosim/core/robot.py#L944-L947