EasyFleet
A simple-by-default framework for multi-robot, multi-capability fleets built on ROS 2
Loading...
Searching...
No Matches
robot_handle.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_MISSION_MANAGER__ROBOT_HANDLE_HPP_
17#define EASYFLEET_MISSION_MANAGER__ROBOT_HANDLE_HPP_
18
19#include <chrono>
20#include <map>
21#include <memory>
22#include <string>
23#include <vector>
24
25#include "easyfleet_mission_manager/capability_info.hpp"
26#include "easyfleet_mission_manager/capability_state.hpp"
27#include "easyfleet_mission_manager/detail/running_capability.hpp"
28#include "easyfleet_mission_manager/mission_helpers.hpp"
29
30namespace easyfleet
31{
32
33class FleetSession;
34
37
75{
76public:
80 explicit RobotHandle(std::string name);
81
84 const std::string & name() const noexcept;
85
90 bool has_capability(const std::string & capability_type) const;
91
96
125 template<typename ActionT>
126 void run_capability(
127 const std::string & capability_type,
128 const typename ActionT::Goal & goal = typename ActionT::Goal(),
129 std::chrono::seconds timeout = easyfleet_mission_manager::kRunTimeout);
130
133 void stop_capability(const std::string & capability_type);
134
139 bool is_capability_running(const std::string & capability_type) const;
140
146 CapabilityState capability_state(const std::string & capability_type) const;
147
155 bool is_alive(const std::string & capability_type) const;
156
160 void print_capabilities() const;
161
170 const std::vector<easyfleet_mission_manager::CapabilityInfo> & capabilities() const noexcept;
171
172private:
173 friend class FleetSession;
174
180 void attach(FleetSession & session);
181 void set_capabilities(std::vector<easyfleet_mission_manager::CapabilityInfo> capabilities);
182
187 void note_heartbeat(
188 const std::string & capability_type,
189 std::chrono::steady_clock::time_point when);
190
193 void check_timeouts();
194
195 std::string name_;
196 std::vector<easyfleet_mission_manager::CapabilityInfo> capabilities_;
197 std::map<std::string,
198 std::unique_ptr<easyfleet_mission_manager::detail::RunningCapabilityBase>> running_;
199 std::map<std::string, std::chrono::steady_clock::time_point> last_heartbeat_;
200 // Deliberately a raw pointer, not a reference: unlike every other
201 // non-owning back-reference in this codebase, this one is genuinely
202 // nullable (a RobotHandle can exist before attach() ever runs -- e.g.
203 // right after `RobotHandle robot_1("robot_1");`, before it's added to
204 // any FleetSession) *and* set exactly once, later, by attach() -- a
205 // reference member could do neither (never null, never reseatable).
206 FleetSession * session_{nullptr};
207};
208
209} // namespace easyfleet
210
211#endif // EASYFLEET_MISSION_MANAGER__ROBOT_HANDLE_HPP_
Everything talking to a fleet from a mission-control process actually needs, regardless of what decid...
Definition fleet_session.hpp:79
const std::string & name() const noexcept
This robot's identity, as passed to the constructor.
Definition robot_handle.cpp:45
RobotHandle(std::string name)
Constructs a handle for the robot identified by name.
Definition robot_handle.cpp:40
bool is_alive(const std::string &capability_type) const
Whether a heartbeat has been seen recently on /capabilities_status for this capability – continuously...
Definition robot_handle.cpp:81
void stop_capability(const std::string &capability_type)
Asks capability_type to stop whatever it's doing, if anything.
Definition robot_handle.cpp:59
void print_capabilities() const
Prints every discovered capability of this robot, like today's print_capability_info()/print_capabili...
Definition robot_handle.cpp:90
CapabilityState capability_state(const std::string &capability_type) const
Current state of the last run_capability() call for this type (or IDLE if none has been made).
Definition robot_handle.cpp:72
bool has_capability(const std::string &capability_type) const
True if this robot announced an active capability of this type (per the SimpleController's last disco...
Definition robot_handle.cpp:50
void run_capability(const std::string &capability_type, const typename ActionT::Goal &goal=typename ActionT::Goal(), std::chrono::seconds timeout=easyfleet_mission_manager::kRunTimeout)
Sends goal to capability_type and returns immediately – the counterpart to today's blocking easyfleet...
Definition robot_handle_impl.hpp:45
bool is_capability_running(const std::string &capability_type) const
Shorthand for capability_state(capability_type) == CapabilityState::RUNNING.
Definition robot_handle.cpp:67
const std::vector< easyfleet_mission_manager::CapabilityInfo > & capabilities() const noexcept
Every capability this robot announced, as discovered – the full CapabilityInfo (type,...
Definition robot_handle.cpp:101