EasyFleet
A simple-by-default framework for multi-robot, multi-capability fleets built on ROS 2
Loading...
Searching...
No Matches
capability_client_impl.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__DETAIL__CAPABILITY_CLIENT_IMPL_HPP_
17#define EASYFLEET_CORE__DETAIL__CAPABILITY_CLIENT_IMPL_HPP_
18
19// Out-of-line member definitions for easyfleet_core::CapabilityClient<ActionT>.
20// Included from the bottom of easyfleet_core/capability_client.hpp. Not meant
21// to be included directly: templates cannot be compiled into easyfleet_core's
22// .cpp/.so, so the implementation lives here to keep the class declaration
23// in capability_client.hpp free of member bodies.
24
25#include <memory>
26#include <string>
27#include <utility>
28
29namespace easyfleet_core
30{
31
32template<typename ActionT>
34 rclcpp::Node & node,
35 const std::string & capability_name,
36 std::chrono::milliseconds default_wait_timeout)
37{
38 return SharedPtr(
39 new CapabilityClient(
40 ActionClient<ActionT>::create(node, capability_name, default_wait_timeout)));
41}
42
43template<typename ActionT>
44CapabilityClient<ActionT>::CapabilityClient(typename ActionClient<ActionT>::SharedPtr action_client)
45: action_client_(std::move(action_client))
46{
47}
48
49template<typename ActionT>
51{
52 return action_client_->wait_for_server();
53}
54
55template<typename ActionT>
56bool CapabilityClient<ActionT>::wait_for_capability(std::chrono::milliseconds timeout)
57{
58 return action_client_->wait_for_server(timeout);
59}
60
61template<typename ActionT>
63 const Goal & goal,
64 ResponseCallback on_response,
65 FeedbackCallback on_feedback)
66{
67 action_client_->send_goal(
68 goal,
69 [on_response](const typename ActionClient<ActionT>::GoalResult & result) {
70 if (on_response) {
71 on_response(Response{result.outcome, result.result});
72 }
73 },
74 on_feedback);
75}
76
77template<typename ActionT>
79 const Goal & goal,
80 FeedbackCallback on_feedback,
81 std::chrono::milliseconds timeout)
82{
83 const auto result = action_client_->send_goal_and_wait(goal, on_feedback, timeout);
84 return Response{result.outcome, result.result};
85}
86
87template<typename ActionT>
89{
90 action_client_->cancel_all_goals();
91}
92
93} // namespace easyfleet_core
94
95#endif // EASYFLEET_CORE__DETAIL__CAPABILITY_CLIENT_IMPL_HPP_
std::shared_ptr< ActionClient< ActionT > > SharedPtr
Shared pointer to an ActionClient<ActionT>.
Definition action_client.hpp:51
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
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
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
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
Result::SharedPtr result
Action-specific result, if outcome is GoalOutcome::SUCCEEDED.
Definition action_client.hpp:85
Final outcome of a request, as delivered to a ResponseCallback or returned by request_and_wait().
Definition capability_client.hpp:75