ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Handling long actions in rclpy (with cancellation)

asked 2022-11-17 17:27:11 -0600

clyde gravatar image

The Fibonacci action demo is nice, but it doesn't support cancellation.

I added a custom cancel_callback, called it from ros2 action send_goal, and tried to cancel by hitting ctrl-C, but it doesn't seem to work. I suspect that's because execute_callback is blocking.

What is a preferred pattern for handling long-running actions in rclpy with cancellation? Any examples / demos / tutorials?

Thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-11-19 08:44:25 -0600

clyde gravatar image

Whoops, I looked at the rclpy demos, but forgot about the rclpy examples.

There are several server examples showing how to build long-running action servers that handle cancellation. They work well w/ the client examples, as well as ros2 action send_goal.

In looking at the server code, I see a few patterns:

  • execute_callback contains a call to time.sleep() to simulate a long-running action
  • execute_callback blocks until the goal has been reached, or a cancellation request has been received
  • the trick is to use a MultiThreadedExecutor and a ReentrantCallbackGroup: these allow the server to receive and process cancellation requests while the goal is executing
  • in some cases the execute_callback is marked async, but this doesn't matter, since it never yields (never awaits)

Thanks.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-11-17 17:27:11 -0600

Seen: 647 times

Last updated: Nov 19 '22