|
EasyFleet
A simple-by-default framework for multi-robot, multi-capability fleets built on ROS 2
|
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. | |
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:
| 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.
|
static |
Constructs a new client for the capability named capability_name.
| node | Node 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_name | Name of the capability to call (its action name). |
| default_wait_timeout | Timeout used by the no-argument overload of wait_for_capability(). |
| 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.
| goal | Request content to send. |
| on_response | Invoked once with the final outcome. |
| on_feedback | Invoked as feedback arrives, if given. |
| 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.
| goal | Request content to send. |
| on_feedback | Invoked as feedback arrives, if given. |
| timeout | Maximum time to wait for a response; 0 (the default) waits indefinitely. |
| 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.
| timeout | Maximum time to wait. |