EasyFleet
A simple-by-default framework for multi-robot, multi-capability fleets built on ROS 2
Loading...
Searching...
No Matches
capability_client.hpp
1// Copyright 2026 Intelligent Robotics Lab
2//
3// This file is part of the project EasyFleet
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#ifndef EASYFLEET_CORE__CAPABILITY_CLIENT_HPP_
17#define EASYFLEET_CORE__CAPABILITY_CLIENT_HPP_
18
19#include <chrono>
20#include <functional>
21#include <memory>
22#include <string>
23
24#include "rclcpp/rclcpp.hpp"
25
26#include "easyfleet_core/action_client.hpp"
27
28namespace easyfleet_core
29{
30
32
54template<typename ActionT>
55class CapabilityClient
56{
57public:
59 using SharedPtr = std::shared_ptr<CapabilityClient<ActionT>>;
61 using Goal = typename ActionT::Goal;
63 using Feedback = typename ActionT::Feedback;
65 using Result = typename ActionT::Result;
67 using FeedbackCallback = std::function<void (std::shared_ptr<const Feedback>)>;
68
71
74 struct Response
75 {
77 Outcome outcome{Outcome::ABORTED};
79 typename Result::SharedPtr result;
80 };
81
83 using ResponseCallback = std::function<void (const Response &)>;
84
93 static SharedPtr create(
94 rclcpp::Node & node,
95 const std::string & capability_name,
96 std::chrono::milliseconds default_wait_timeout = std::chrono::seconds(5));
97
98 CapabilityClient(const CapabilityClient &) = delete;
99 CapabilityClient & operator=(const CapabilityClient &) = delete;
100
104 bool wait_for_capability();
108 bool wait_for_capability(std::chrono::milliseconds timeout);
109
116 void request(
117 const Goal & goal,
118 ResponseCallback on_response,
119 FeedbackCallback on_feedback = nullptr);
120
131 const Goal & goal,
132 FeedbackCallback on_feedback = nullptr,
133 std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
134
140 void cancel();
141
142private:
143 explicit CapabilityClient(typename ActionClient<ActionT>::SharedPtr action_client);
144
145 typename ActionClient<ActionT>::SharedPtr action_client_;
146};
147
148} // namespace easyfleet_core
149
150#include "easyfleet_core/detail/capability_client_impl.hpp"
151
152#endif // EASYFLEET_CORE__CAPABILITY_CLIENT_HPP_
std::shared_ptr< ActionClient< ActionT > > SharedPtr
Shared pointer to an ActionClient<ActionT>.
Definition action_client.hpp:51
GoalOutcome
Outcome of a goal, unifying rejection/timeout/unavailability with the normal terminal states of the a...
Definition action_client.hpp:67
void cancel()
Asks the capability to stop whatever it is currently doing (e.g.
Definition capability_client_impl.hpp:88
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
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 tim...
Definition capability_client_impl.hpp:78
std::shared_ptr< CapabilityClient< ActionT > > SharedPtr
Shared pointer to a CapabilityClient<ActionT>.
Definition capability_client.hpp:59
std::function< void(std::shared_ptr< const Feedback >)> FeedbackCallback
Callback invoked with feedback as it arrives for the request.
Definition capability_client.hpp:67
typename ActionT::Goal Goal
Goal type of the wrapped action.
Definition capability_client.hpp:61
typename ActionT::Result Result
Result type of the wrapped action.
Definition capability_client.hpp:65
bool wait_for_capability()
Blocks until the capability is reachable, using the constructor's default_wait_timeout.
Definition capability_client_impl.hpp:50
std::function< void(const Response &)> ResponseCallback
Callback invoked once a request reaches a final outcome.
Definition capability_client.hpp:83
void request(const Goal &goal, ResponseCallback on_response, FeedbackCallback on_feedback=nullptr)
Asks the capability to do something.
Definition capability_client_impl.hpp:62
typename ActionT::Feedback Feedback
Feedback type of the wrapped action.
Definition capability_client.hpp:63
typename ActionClient< ActionT >::GoalOutcome Outcome
Same vocabulary as ActionClient::GoalOutcome.
Definition capability_client.hpp:70
Final outcome of a request, as delivered to a ResponseCallback or returned by request_and_wait().
Definition capability_client.hpp:75
Outcome outcome
How the request ended.
Definition capability_client.hpp:77
Result::SharedPtr result
Action-specific result, if outcome is Outcome::SUCCEEDED.
Definition capability_client.hpp:79