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

The simplest possible way to ask a capability to do something. More...

#include <capability_client.hpp>

Classes

struct  Response
 Final outcome of a request, as delivered to a ResponseCallback or returned by request_and_wait(). More...

Public Types

using SharedPtr = std::shared_ptr<CapabilityClient<ActionT>>
 Shared pointer to a CapabilityClient<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 FeedbackCallback = std::function<void (std::shared_ptr<const Feedback>)>
 Callback invoked with feedback as it arrives for the request.
using Outcome = typename ActionClient<ActionT>::GoalOutcome
 Same vocabulary as ActionClient::GoalOutcome.
using ResponseCallback = std::function<void (const Response &)>
 Callback invoked once a request reaches a final outcome.

Public Member Functions

 CapabilityClient (const CapabilityClient &)=delete
CapabilityClient & operator= (const CapabilityClient &)=delete
bool wait_for_capability ()
 Blocks until the capability is reachable, using the constructor's default_wait_timeout.
bool wait_for_capability (std::chrono::milliseconds timeout)
 Blocks until the capability is reachable, or timeout elapses.
void request (const Goal &goal, ResponseCallback on_response, FeedbackCallback on_feedback=nullptr)
 Asks the capability to do something.
Response request_and_wait (const Goal &goal, FeedbackCallback on_feedback=nullptr, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
 Asks the capability to do something and blocks the calling thread until the response is ready (or timeout elapses, if positive).
void cancel ()
 Asks the capability to stop whatever it is currently doing (e.g.

Static Public Member Functions

static SharedPtr create (rclcpp::Node &node, const std::string &capability_name, std::chrono::milliseconds default_wait_timeout=std::chrono::seconds(5))
 Constructs a new client for the capability named capability_name.

Detailed Description

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

The simplest possible way to ask a capability to do something.

Where ActionClient<ActionT> exposes the full action protocol (goal acceptance, per-goal cancellation by id, active goal bookkeeping...), CapabilityClient<ActionT> reduces that to the three things a caller of a capability actually cares about: send a request, optionally observe feedback while it runs, and get the final response. It talks to a capability by name, exactly as advertised by easyfleet_core::Capability (the capability name is the action name).

Usage:

this, "navigation");
if (!nav->wait_for_capability()) { ... not available ... }
nav2_msgs::action::NavigateToPose::Goal goal;
goal.pose = ...;
auto response = nav->request_and_wait(goal);
if (response.outcome == NavClient::Outcome::SUCCEEDED) { ... }
The simplest possible way to ask a capability to do something.
Definition capability_client.hpp:56
static SharedPtr create(rclcpp::Node &node, const std::string &capability_name, std::chrono::milliseconds default_wait_timeout=std::chrono::seconds(5))
Constructs a new client for the capability named capability_name.
Definition capability_client_impl.hpp:33

Member Function Documentation

◆ cancel()

template<typename ActionT>
void cancel ( )

Asks the capability to stop whatever it is currently doing (e.g.

a navigating robot stops moving, a perception stream stops reporting detections). Returns immediately; the pending request's on_response (from request()) or the return of request_and_wait() will resolve with Outcome::CANCELED once the capability has stopped.

◆ create()

template<typename ActionT>
CapabilityClient< ActionT >::SharedPtr create ( rclcpp::Node & node,
const std::string & capability_name,
std::chrono::milliseconds default_wait_timeout = std::chrono::seconds(5) )
static

Constructs a new client for the capability named capability_name.

Parameters
nodeNode on whose behalf the capability is called. Only used to construct the underlying ActionClient (never stored), so a reference – never null, unlike a pointer – is all this needs.
capability_nameName of the capability to call (its action name).
default_wait_timeoutTimeout used by the no-argument overload of wait_for_capability().
Returns
A new CapabilityClient<ActionT>.

◆ request()

template<typename ActionT>
void request ( const Goal & goal,
ResponseCallback on_response,
FeedbackCallback on_feedback = nullptr )

Asks the capability to do something.

Returns immediately; on_response is called exactly once with the final outcome, and on_feedback (if given) once per feedback message while the request is running.

Parameters
goalRequest content to send.
on_responseInvoked once with the final outcome.
on_feedbackInvoked as feedback arrives, if given.

◆ request_and_wait()

template<typename ActionT>
CapabilityClient< ActionT >::Response request_and_wait ( const Goal & goal,
FeedbackCallback on_feedback = nullptr,
std::chrono::milliseconds timeout = std::chrono::milliseconds(0) )

Asks the capability to do something and blocks the calling thread until the response is ready (or timeout elapses, if positive).

Safe to call from any thread.

Parameters
goalRequest content to send.
on_feedbackInvoked as feedback arrives, if given.
timeoutMaximum time to wait for a response; 0 (the default) waits indefinitely.
Returns
The request's final outcome (Outcome::TIMEOUT if timeout elapsed first).

◆ wait_for_capability() [1/2]

template<typename ActionT>
bool wait_for_capability ( )

Blocks until the capability is reachable, using the constructor's default_wait_timeout.

Returns
Whether the capability became reachable before the timeout.

◆ wait_for_capability() [2/2]

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

Blocks until the capability is reachable, or timeout elapses.

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

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