EasyFleet
A simple-by-default framework for multi-robot, multi-capability fleets built on ROS 2
Loading...
Searching...
No Matches
fleet_session.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__FLEET_SESSION_HPP_
17#define EASYFLEET_MISSION_MANAGER__FLEET_SESSION_HPP_
18
19#include <chrono>
20#include <functional>
21#include <memory>
22#include <optional>
23#include <string>
24#include <thread>
25#include <vector>
26
27#include "rclcpp/rclcpp.hpp"
28
29#include "easyfleet_interfaces/msg/capability_status.hpp"
30
31#include "easyfleet_mission_manager/robot_handle.hpp"
32#include "easyfleet_mission_manager/status_markers.hpp"
33
34namespace easyfleet
35{
36
42
78class FleetSession
79{
80public:
81 FleetSession();
82 ~FleetSession();
83
86 void add_robot(RobotHandle & robot);
87
93 const std::vector<std::reference_wrapper<RobotHandle>> & robots() const noexcept;
94
100 std::optional<std::reference_wrapper<RobotHandle>> find_robot(
101 const std::string & name) const noexcept;
102
111 void discover_capabilities(std::chrono::milliseconds window = std::chrono::milliseconds(2500));
112
116 void spin_some();
117
124 void spin_for(std::chrono::milliseconds duration);
125
129 rclcpp::Node::SharedPtr node() const noexcept;
130
134 void shutdown();
135
136private:
137 friend class RobotHandle;
138
142 easyfleet_mission_manager::StatusMarkerPublisher & status_marker_publisher();
143
144 rclcpp::Node::SharedPtr node_;
145 rclcpp::executors::SingleThreadedExecutor executor_;
146 std::thread spin_thread_;
147 std::vector<std::reference_wrapper<RobotHandle>> robots_;
148 std::unique_ptr<easyfleet_mission_manager::StatusMarkerPublisher> status_;
149 rclcpp::Subscription<easyfleet_interfaces::msg::CapabilityStatus>::SharedPtr
150 capability_status_sub_;
151};
152
153} // namespace easyfleet
154
155// Out-of-line definition of RobotHandle::run_capability<ActionT>() -- see
156// detail/robot_handle_impl.hpp's own comment for why it lives here rather
157// than at the bottom of robot_handle.hpp.
158#include "easyfleet_mission_manager/detail/robot_handle_impl.hpp"
159
160#endif // EASYFLEET_MISSION_MANAGER__FLEET_SESSION_HPP_
void discover_capabilities(std::chrono::milliseconds window=std::chrono::milliseconds(2500))
Runs exactly one discovery scan (see today's easyfleet_mission_manager::discover_capabilities(),...
Definition fleet_session.cpp:83
std::optional< std::reference_wrapper< RobotHandle > > find_robot(const std::string &name) const noexcept
Looks up a robot added so far by RobotHandle::name().
Definition fleet_session.cpp:71
rclcpp::Node::SharedPtr node() const noexcept
Underlying node, for anything not yet covered by RobotHandle (matches today's escape hatch of reachin...
Definition fleet_session.cpp:119
void shutdown()
Cancels the executor, joins its background thread, and calls rclcpp::shutdown() – the mission-side mi...
Definition fleet_session.cpp:129
void spin_for(std::chrono::milliseconds duration)
Blocks for exactly duration, still spinning underneath (equivalent to a bounded spin_some() loop) – f...
Definition fleet_session.cpp:111
void spin_some()
One non-blocking spin of the underlying executor's queued work – call this in a while (robot....
Definition fleet_session.cpp:97
void add_robot(RobotHandle &robot)
Adds robot to this session, attaching it so it can be discovered and commanded.
Definition fleet_session.cpp:60
const std::vector< std::reference_wrapper< RobotHandle > > & robots() const noexcept
Every robot added so far, in add_robot() order – for code that needs to enumerate the fleet rather th...
Definition fleet_session.cpp:66
Publishes a floating TEXT_VIEW_FACING marker above each robot's own base_link, showing a short,...
Definition status_markers.hpp:47