16#ifndef EASYFLEET_CORE__ACTION_CLIENT_HPP_
17#define EASYFLEET_CORE__ACTION_CLIENT_HPP_
26#include <unordered_map>
28#include "rclcpp/rclcpp.hpp"
29#include "rclcpp_action/rclcpp_action.hpp"
31namespace easyfleet_core
46template<
typename ActionT>
51 using SharedPtr = std::shared_ptr<ActionClient<ActionT>>;
53 using Goal =
typename ActionT::Goal;
57 using Result =
typename ActionT::Result;
92 std::function<void (
bool accepted,
const rclcpp_action::GoalUUID & goal_id)>;
105 rclcpp::Node & parent_node,
106 const std::string & action_name,
107 std::chrono::milliseconds default_server_timeout = std::chrono::seconds(5));
109 ActionClient(
const ActionClient &) =
delete;
110 ActionClient & operator=(
const ActionClient &) =
delete;
160 std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
166 bool cancel_goal(const rclcpp_action::GoalUUID & goal_id);
178 rclcpp::Node & parent_node,
179 const std::
string & action_name,
180 std::chrono::milliseconds default_server_timeout);
184 std::
string action_name_;
185 std::chrono::milliseconds default_server_timeout_;
188 rclcpp::executors::SingleThreadedExecutor::
SharedPtr executor_;
189 std::thread spin_thread_;
190 typename rclcpp_action::Client<ActionT>::
SharedPtr client_;
192 mutable std::mutex goals_mutex_;
198#include "easyfleet_core/detail/action_client_impl.hpp"
bool wait_for_server()
Block until the server is reachable, using the constructor's default_server_timeout.
Definition action_client_impl.hpp:107
bool is_server_ready() const
Whether the action server is currently reachable.
Definition action_client_impl.hpp:101
std::function< void(const GoalResult &)> ResultCallback
Callback invoked once a goal reaches a terminal state.
Definition action_client.hpp:89
const std::string & get_action_name() const noexcept
The action name this client was created for.
Definition action_client_impl.hpp:95
std::function< void(bool accepted, const rclcpp_action::GoalUUID &goal_id)> GoalResponseCallback
Callback invoked once the server has accepted or rejected a goal.
Definition action_client.hpp:91
std::shared_ptr< ActionClient< ActionT > > SharedPtr
Shared pointer to an ActionClient<ActionT>.
Definition action_client.hpp:51
bool send_goal(const Goal &goal, ResultCallback result_callback=nullptr, FeedbackCallback feedback_callback=nullptr, GoalResponseCallback goal_response_callback=nullptr)
Send a goal without blocking.
Definition action_client_impl.hpp:119
std::size_t active_goal_count() const
Number of goals accepted by the server and not yet in a terminal state.
Definition action_client_impl.hpp:229
GoalResult send_goal_and_wait(const Goal &goal, FeedbackCallback feedback_callback=nullptr, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Send a goal and block the calling thread until it reaches a terminal state (or timeout elapses,...
Definition action_client_impl.hpp:182
typename rclcpp_action::Client< ActionT >::GoalHandle ClientGoalHandle
rclcpp_action goal handle type of the wrapped action.
Definition action_client.hpp:59
bool cancel_goal(const rclcpp_action::GoalUUID &goal_id)
Request cancellation of a specific in-flight goal.
Definition action_client_impl.hpp:207
std::function< void(std::shared_ptr< const Feedback >)> FeedbackCallback
Callback invoked with feedback as it arrives for an in-flight goal.
Definition action_client.hpp:62
typename ActionT::Goal Goal
Goal type of the wrapped action.
Definition action_client.hpp:53
typename ActionT::Result Result
Result type of the wrapped action.
Definition action_client.hpp:57
void cancel_all_goals()
Request cancellation of every goal currently tracked by this client.
Definition action_client_impl.hpp:223
typename ActionT::Feedback Feedback
Feedback type of the wrapped action.
Definition action_client.hpp:55
static SharedPtr create(rclcpp::Node &parent_node, const std::string &action_name, std::chrono::milliseconds default_server_timeout=std::chrono::seconds(5))
Constructs a new client for action_name, spinning its own internal node in the background.
Definition action_client_impl.hpp:36
GoalOutcome
Outcome of a goal, unifying rejection/timeout/unavailability with the normal terminal states of the a...
Definition action_client.hpp:67
Terminal outcome of a goal, as delivered to a ResultCallback or returned by send_goal_and_wait().
Definition action_client.hpp:79
GoalOutcome outcome
How the goal ended.
Definition action_client.hpp:81
rclcpp_action::GoalUUID goal_id
Id of the goal this result belongs to.
Definition action_client.hpp:83
Result::SharedPtr result
Action-specific result, if outcome is GoalOutcome::SUCCEEDED.
Definition action_client.hpp:85