|
|
using | ActionType = ActionT |
| | The wrapped rclcpp_action action type.
|
|
using | Goal = typename ActionT::Goal |
| | Goal type of the wrapped action.
|
|
using | Feedback = typename ActionT::Feedback |
| | Feedback type of the wrapped action.
|
|
using | Result = typename ActionT::Result |
| | Result type of the wrapped action.
|
|
using | GoalHandle = rclcpp_action::ServerGoalHandle<ActionT> |
| | rclcpp_action server-side goal handle type of the wrapped action.
|
|
using | GoalHandleSharedPtr = std::shared_ptr<GoalHandle> |
| | Shared pointer to a GoalHandle.
|
|
using | SharedPtr = std::shared_ptr<ActionServerBase<ActionT>> |
| | Shared pointer to an ActionServerBase<ActionT>.
|
|
| template<typename NodeT> |
| | ActionServerBase (NodeT &node, const std::string &action_name, bool default_allow_preemption=true) |
| | Constructs the action server, attached to node under action_name.
|
| virtual rclcpp_action::GoalResponse | on_goal_received (const rclcpp_action::GoalUUID &uuid, std::shared_ptr< const Goal > goal)=0 |
| | Validate an incoming goal.
|
| virtual void | on_execute (const GoalHandleSharedPtr goal_handle)=0 |
| | Run an accepted goal to completion.
|
| virtual rclcpp_action::CancelResponse | on_cancel_requested (const GoalHandleSharedPtr goal_handle) |
| | Decide whether a cancel request (via the action's cancel service) should be accepted.
|
| virtual void | on_preempted (const GoalHandleSharedPtr &preempted_goal_handle) |
| | Optional hook invoked (from the accepting thread, not the worker thread) when a new goal is about to preempt the currently running one.
|
| bool | is_preempt_requested () const noexcept |
| | Whether a newer goal has been accepted and is waiting to replace the one currently executing.
|
| bool | is_shutdown_requested () const noexcept |
| | Whether this object is being destroyed.
|
| rclcpp::Logger | logger () const |
| | Logger of the node hosting this action server.
|
template<typename ActionT>
class easyfleet_core::ActionServerBase< ActionT >
Base class that hides the boilerplate of running a ROS 2 action server.
A node exposes an action by inheriting from ActionServerBase<ActionT> and implementing three hooks: on_goal_received(), on_execute() and, optionally, on_cancel_requested(). Everything else – wiring the rclcpp_action::Server, running goals on a dedicated worker thread, transitioning the goal state machine, and deciding whether an incoming goal is allowed to preempt the one currently running – is handled here.
Preemption is governed by a boolean ROS 2 parameter named "<action_name>.allow_preemption" (with '/' in the action name mapped to '.'), so it can be set at startup and changed at runtime. Only one goal is ever executed at a time:
- If preemption is disallowed and a goal is active, new goals are rejected outright.
- If preemption is allowed, a new goal is accepted immediately and is_preempt_requested() starts returning true for the running goal. A long-running on_execute() implementation is expected to poll it (and is_shutdown_requested()) and return promptly, having settled the goal handle (succeeded/aborted/canceled).
This class is not copyable and does not itself derive from rclcpp::Node, so a node can inherit from several ActionServerBase<ActionT> (one per action) without any diamond-inheritance issues.
It attaches to any node type exposing the standard rclcpp node interfaces (get_node_base_interface(), get_node_clock_interface(), get_node_logging_interface(), get_node_parameters_interface(), get_node_waitables_interface()), which covers both rclcpp::Node and rclcpp_lifecycle::LifecycleNode.
template<typename ActionT>
Run an accepted goal to completion.
Must leave the goal handle in a terminal state (succeed(), abort() or canceled()) before returning. Long-running implementations should periodically check is_preempt_requested(), goal_handle->is_canceling() and is_shutdown_requested() and return promptly when any of them is true. Only settle the goal with canceled() when goal_handle->is_canceling() is true (a client asked for it, so rcl_action has already transitioned the goal to CANCELING); for preemption or shutdown, which happen while the goal is still EXECUTING, use abort() instead – canceled() from EXECUTING is an invalid state transition.
- Parameters
-
| goal_handle | Handle of the accepted goal to run to completion. |
Implemented in ManipulationFakeActionServer, PerceptionFakeActionServer, and EasynavNavigationActionServer.