EasyFleet
A simple-by-default framework for multi-robot, multi-capability fleets built on ROS 2
Loading...
Searching...
No Matches
ActionClient< ActionT > Class Template Reference

Comfortable wrapper around rclcpp_action::Client<ActionT>. More...

#include <action_client.hpp>

Classes

struct  GoalResult
 Terminal outcome of a goal, as delivered to a ResultCallback or returned by send_goal_and_wait(). More...

Public Types

enum class  GoalOutcome : uint8_t {
  SUCCEEDED , ABORTED , CANCELED , REJECTED ,
  TIMEOUT , SERVER_UNAVAILABLE
}
 Outcome of a goal, unifying rejection/timeout/unavailability with the normal terminal states of the action state machine.
using SharedPtr = std::shared_ptr<ActionClient<ActionT>>
 Shared pointer to an ActionClient<ActionT>.
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 ClientGoalHandle = typename rclcpp_action::Client<ActionT>::GoalHandle
 rclcpp_action goal handle type of the wrapped action.
using FeedbackCallback = std::function<void (std::shared_ptr<const Feedback>)>
 Callback invoked with feedback as it arrives for an in-flight goal.
using ResultCallback = std::function<void (const GoalResult &)>
 Callback invoked once a goal reaches a terminal state.
using GoalResponseCallback
 Callback invoked once the server has accepted or rejected a goal.

Public Member Functions

 ActionClient (const ActionClient &)=delete
ActionClient & operator= (const ActionClient &)=delete
const std::string & get_action_name () const noexcept
 The action name this client was created for.
bool is_server_ready () const
 Whether the action server is currently reachable.
bool wait_for_server ()
 Block until the server is reachable, using the constructor's default_server_timeout.
bool wait_for_server (std::chrono::milliseconds timeout)
 Block until the server is reachable or timeout elapses.
bool send_goal (const Goal &goal, ResultCallback result_callback=nullptr, FeedbackCallback feedback_callback=nullptr, GoalResponseCallback goal_response_callback=nullptr)
 Send a goal without blocking.
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, if positive).
bool cancel_goal (const rclcpp_action::GoalUUID &goal_id)
 Request cancellation of a specific in-flight goal.
void cancel_all_goals ()
 Request cancellation of every goal currently tracked by this client.
std::size_t active_goal_count () const
 Number of goals accepted by the server and not yet in a terminal state.

Static Public Member Functions

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.

Detailed Description

template<typename ActionT>
class easyfleet_core::ActionClient< ActionT >

Comfortable wrapper around rclcpp_action::Client<ActionT>.

Each ActionClient<ActionT> owns a small internal node dedicated to a single action and spins it on a background thread for its entire lifetime. This means callers never have to worry about whether their own node's executor is spinning: goals can be sent, results awaited (even synchronously, via send_goal_and_wait()), and feedback/cancel handled, from any thread, independently of how the owning node is executed.

A node typically owns one ActionClient<ActionT>::SharedPtr per action it talks to, created with create().

Member Typedef Documentation

◆ GoalResponseCallback

template<typename ActionT>
using GoalResponseCallback
Initial value:
std::function<void (bool accepted, const rclcpp_action::GoalUUID & goal_id)>

Callback invoked once the server has accepted or rejected a goal.

Member Function Documentation

◆ active_goal_count()

template<typename ActionT>
std::size_t active_goal_count ( ) const

Number of goals accepted by the server and not yet in a terminal state.

Returns
Number of goals accepted by the server and not yet in a terminal state.

◆ cancel_goal()

template<typename ActionT>
bool cancel_goal ( const rclcpp_action::GoalUUID & goal_id)

Request cancellation of a specific in-flight goal.

Returns false if the goal is unknown (already terminal, or never accepted).

Parameters
goal_idId of the goal to cancel.
Returns
Whether a cancellation request was sent.

◆ create()

template<typename ActionT>
ActionClient< ActionT >::SharedPtr create ( rclcpp::Node & parent_node,
const std::string & action_name,
std::chrono::milliseconds default_server_timeout = std::chrono::seconds(5) )
static

Constructs a new client for action_name, spinning its own internal node in the background.

Parameters
parent_nodeNode on whose behalf the action is called; only used to inherit its namespace and to derive a name for the internal node (never stored), so a reference – never null, unlike a pointer – is all this needs.
action_nameName of the action to call.
default_server_timeoutTimeout used by the no-argument overload of wait_for_server().
Returns
A new ActionClient<ActionT>, already spinning its internal node in the background.

◆ get_action_name()

template<typename ActionT>
const std::string & get_action_name ( ) const
noexcept

The action name this client was created for.

Returns
The action name this client was created for.

◆ is_server_ready()

template<typename ActionT>
bool is_server_ready ( ) const

Whether the action server is currently reachable.

Returns
Whether the action server is currently reachable.

◆ send_goal()

template<typename ActionT>
bool send_goal ( const Goal & goal,
ResultCallback result_callback = nullptr,
FeedbackCallback feedback_callback = nullptr,
GoalResponseCallback goal_response_callback = nullptr )

Send a goal without blocking.

Returns false immediately (without contacting the server) if it is not currently reachable; in that case, result_callback, if any, is invoked synchronously with GoalOutcome::SERVER_UNAVAILABLE.

Parameters
goalGoal to send.
result_callbackInvoked once the goal reaches a terminal state.
feedback_callbackInvoked as feedback arrives for this goal.
goal_response_callbackInvoked once the server accepts/rejects the goal.
Returns
Whether the goal was sent (not whether it was accepted).

◆ send_goal_and_wait()

template<typename ActionT>
ActionClient< ActionT >::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, if positive).

Safe to call from any thread, including one that also spins the owning node: this object spins its own dedicated internal node to drive the exchange.

Parameters
goalGoal to send.
feedback_callbackInvoked as feedback arrives for this goal.
timeoutMaximum time to wait for a terminal state; 0 (the default) waits indefinitely.
Returns
The goal's terminal outcome (GoalOutcome::TIMEOUT if timeout elapsed first).

◆ wait_for_server() [1/2]

template<typename ActionT>
bool wait_for_server ( )

Block until the server is reachable, using the constructor's default_server_timeout.

Returns
Whether the server became reachable before the timeout.

◆ wait_for_server() [2/2]

template<typename ActionT>
bool wait_for_server ( std::chrono::milliseconds timeout)

Block until the server is reachable or timeout elapses.

Parameters
timeoutMaximum time to wait.
Returns
Whether the server became reachable before the timeout.

The documentation for this class was generated from the following files: