16#ifndef EASYFLEET_CORE__ACTION_SERVER_BASE_HPP_
17#define EASYFLEET_CORE__ACTION_SERVER_BASE_HPP_
20#include <condition_variable>
27#include "rclcpp/rclcpp.hpp"
28#include "rclcpp_action/rclcpp_action.hpp"
30namespace easyfleet_core
64template<
typename ActionT>
71 using Goal =
typename ActionT::Goal;
75 using Result =
typename ActionT::Result;
77 using GoalHandle = rclcpp_action::ServerGoalHandle<ActionT>;
81 using SharedPtr = std::shared_ptr<ActionServerBase<ActionT>>;
83 ActionServerBase(
const ActionServerBase &) =
delete;
84 ActionServerBase & operator=(
const ActionServerBase &) =
delete;
86 virtual ~ActionServerBase();
111 template<typename NodeT>
112 explicit ActionServerBase(
114 const std::
string & action_name,
115 bool default_allow_preemption = true)
117 node.get_node_base_interface(),
118 node.get_node_clock_interface(),
119 node.get_node_logging_interface(),
120 node.get_node_parameters_interface(),
121 node.get_node_waitables_interface(),
123 default_allow_preemption)
135 const rclcpp_action::GoalUUID & uuid,
136 std::shared_ptr<const Goal> goal) = 0;
183 rclcpp::node_interfaces::NodeBaseInterface::
SharedPtr node_base,
184 rclcpp::node_interfaces::NodeClockInterface::
SharedPtr node_clock,
185 rclcpp::node_interfaces::NodeLoggingInterface::
SharedPtr node_logging,
186 rclcpp::node_interfaces::NodeParametersInterface::
SharedPtr node_parameters,
187 rclcpp::node_interfaces::NodeWaitablesInterface::
SharedPtr node_waitables,
188 const std::
string & action_name,
189 bool default_allow_preemption);
191 rclcpp_action::GoalResponse handle_goal(
192 const rclcpp_action::GoalUUID & uuid,
193 std::shared_ptr<const
Goal> goal);
196 void on_parameters_set(const std::vector<rclcpp::Parameter> & params);
199 rclcpp::node_interfaces::NodeBaseInterface::
SharedPtr node_base_;
200 rclcpp::node_interfaces::NodeClockInterface::
SharedPtr node_clock_;
201 rclcpp::node_interfaces::NodeLoggingInterface::
SharedPtr node_logging_;
202 rclcpp::node_interfaces::NodeParametersInterface::
SharedPtr node_parameters_;
203 rclcpp::node_interfaces::NodeWaitablesInterface::
SharedPtr node_waitables_;
205 std::
string action_name_;
206 std::
string robot_name_;
207 std::
string param_name_;
208 std::atomic_bool allow_preemption_{
true};
210 typename rclcpp_action::Server<ActionT>::SharedPtr server_;
211 rclcpp::node_interfaces::PostSetParametersCallbackHandle::SharedPtr param_cb_handle_;
213 mutable std::mutex mutex_;
214 std::condition_variable cv_;
215 std::atomic_bool shutting_down_{
false};
216 std::atomic_bool preempt_requested_{
false};
224#include "easyfleet_core/detail/action_server_base_impl.hpp"
bool is_shutdown_requested() const noexcept
std::shared_ptr< ActionServerBase< ActionT > > SharedPtr
Shared pointer to an ActionServerBase<ActionT>.
Definition action_server_base.hpp:81
const std::string & get_action_name() const noexcept
Fully-qualified name of the action served by this instance.
Definition action_server_base_impl.hpp:109
virtual void on_execute(const GoalHandleSharedPtr goal_handle)=0
Run an accepted goal to completion.
rclcpp::Logger logger() const
ActionT ActionType
The wrapped rclcpp_action action type.
Definition action_server_base.hpp:69
typename ActionT::Goal Goal
Goal type of the wrapped action.
Definition action_server_base.hpp:71
rclcpp_action::ServerGoalHandle< ActionT > GoalHandle
rclcpp_action server-side goal handle type of the wrapped action.
Definition action_server_base.hpp:77
typename ActionT::Result Result
Result type of the wrapped action.
Definition action_server_base.hpp:75
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.
Definition action_server_base_impl.hpp:128
bool is_preempt_requested() const noexcept
Whether a newer goal has been accepted and is waiting to replace the one currently executing.
Definition action_server_base_impl.hpp:140
bool is_preemptable() const noexcept
typename ActionT::Feedback Feedback
Feedback type of the wrapped action.
Definition action_server_base.hpp:73
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 ...
Definition action_server_base_impl.hpp:135
std::shared_ptr< GoalHandle > GoalHandleSharedPtr
Shared pointer to a GoalHandle.
Definition action_server_base.hpp:79
virtual rclcpp_action::GoalResponse on_goal_received(const rclcpp_action::GoalUUID &uuid, std::shared_ptr< const Goal > goal)=0
Validate an incoming goal.