ros2 / rclcpp

rclcpp (ROS Client Library for C++)
Apache License 2.0
553 stars 418 forks source link

Implement SimpleActionServer and SimpleAction Client #759

Closed orduno closed 1 year ago

orduno commented 5 years ago

Feature request

Feature description

ROS2 is missing an rclcpp_action::SimpleActionServer that is equivalent to ROS1 actionlib::SimpleActionServer, same for the action client.

ROS2 does come with some basic examples for implementing action clients and servers, but these don't fully implement the ROS1 SimpleActionServer policy.

orduno commented 5 years ago

We've created a simple action server for nav2.

jacobperron commented 5 years ago

@orduno The link appears to be broken.

I'm happy to iterate with you if you would like to work on getting this into rclcpp_action.

orduno commented 5 years ago

@jacobperron Ups should work now.

Yes, let's work together to get something into rclcpp_action.

Here's the PR with some additional details.

mkhansenbot commented 5 years ago

I think this is needed. @jacobperron - have you looked at what we have in nav2? We could submit this here instead.

As a side note, I think this would be useful for projects like MoveIt2, I know MoveIt uses SimpleActionClient & Server. @davetcoleman, care to comment on that?

jacobperron commented 5 years ago

I'm not convinced that we need a separate entity like "SimpleActionServer" to achieve what we want. IIUC, what we want is a single goal policy (described here). For better semantics, I would use the name single-goal action server.

Depending on ones use-case, achieving this policy is fairly straight-forward (without much boilerplate). For example, I've recently added what is effectively a single-goal action server to turtlesim. When the action server is created we make it so all goal requests and cancel requests are accepted:

https://github.com/ros/ros_tutorials/blob/cd34759c848955c0d4e3a2e500481d86f1affc62/turtlesim/src/turtle.cpp#L68-L81

And in the accepted callback, we add two lines (plus a log statement) to abort any current goal:

https://github.com/ros/ros_tutorials/blob/cd34759c848955c0d4e3a2e500481d86f1affc62/turtlesim/src/turtle.cpp#L138-L142

This is similar to what is done in nav2's SimpleActionServer, except in the turtlesim scenario we don't need to worry about locks since it uses a single threaded executor.

I can think of some improvements we could make to the existing action server API related to a single-goal policy:

I think the first two improvements are easy wins. The third points deserves a little more thought, and is probably worth waiting to see what changes happen to executors (@wjwwood let me know if you agree). Depending on the complexity, it may make sense to add a concept of a single-goal (or N-goal) action server.

Let me know if I'm missing other features from ROS 1's SimpleActionServer that should be considered.

Also, correct me if I'm wrong, but it doesn't seem like we need to worry about adding an equivalent for "SimpleActionClient".

jacobperron commented 5 years ago

Expose an API for the server to preempt itself (ie. transition to canceling state).

See proposed API in https://github.com/ros2/rclcpp/pull/884

wjwwood commented 5 years ago

The third points deserves a little more thought, and is probably worth waiting to see what changes happen to executors (@wjwwood let me know if you agree).

I think that's right, changing the executors to not require a single executor per node would allow the action server to create it's own executor by default and spin it in a thread (giving you nice behavior out of the box) without fear of interfering with other stuff in the node. Advanced users could still control which executor is used in the action server/client with an option.

DLu commented 1 year ago

As @awesomebytes points out, I made C++/Python Simple Action interfaces here: https://github.com/DLu/simple_actions

Announcement

mjcarroll commented 1 year ago

I think that @DLu's contribution fulfills this request, so I'm going to close this out, with https://github.com/DLu/simple_actions being a good path forward for people looking for SimpleActionServer or SimpleActionClient capabilities.

Thanks for the contribution!