Easy Navigation
Loading...
Searching...
No Matches
SystemNode.hpp
Go to the documentation of this file.
1// Copyright 2025 Intelligent Robotics Lab
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
18
19#ifndef EASYNAV_SYSTEM__SYSTEMNODE_HPP_
20#define EASYNAV_SYSTEM__SYSTEMNODE_HPP_
21
22#include <atomic>
23#include <chrono>
24#include <map>
25#include <mutex>
26#include <optional>
27#include <string>
28#include <vector>
29#include <memory>
30
31#include "rclcpp/rclcpp.hpp"
32#include "rclcpp/macros.hpp"
33#include "rclcpp_lifecycle/lifecycle_node.hpp"
34#include "geometry_msgs/msg/twist.hpp"
35#include "geometry_msgs/msg/twist_stamped.hpp"
36#include "std_msgs/msg/string.hpp"
39#include "easynav_core/SystemActions.hpp"
43#include "easynav_recovery/RecoveryManagerNode.hpp"
47
48namespace easynav
49{
50
56{
58 rclcpp_lifecycle::LifecycleNode::SharedPtr node_ptr;
60 rclcpp::CallbackGroup::SharedPtr realtime_cbg;
61};
62
72class SystemNode : public rclcpp_lifecycle::LifecycleNode, public SystemActions
73{
74public:
75 RCLCPP_SMART_PTR_DEFINITIONS(SystemNode)
76 using CallbackReturnT = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
77
82 explicit SystemNode(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
83
85 ~SystemNode();
86
92 CallbackReturnT on_configure(const rclcpp_lifecycle::State & state);
93
99 CallbackReturnT on_activate(const rclcpp_lifecycle::State & state);
100
106 CallbackReturnT on_deactivate(const rclcpp_lifecycle::State & state);
107
113 CallbackReturnT on_cleanup(const rclcpp_lifecycle::State & state);
114
120 CallbackReturnT on_shutdown(const rclcpp_lifecycle::State & state);
121
127 CallbackReturnT on_error(const rclcpp_lifecycle::State & state);
128
133 rclcpp::CallbackGroup::SharedPtr get_real_time_cbg();
134
139 std::map<std::string, SystemNodeInfo> get_system_nodes();
140
144 void system_cycle_rt();
145
149 void system_cycle();
150
155 [[nodiscard]] std::shared_ptr<NavState> get_nav_state() const {return nav_state_;}
156
159 [[nodiscard]] std::vector<std::string> get_nodes_without_clock();
160
162 static constexpr std::chrono::seconds kClockCheckPeriod {5};
163
169 [[nodiscard]] bool is_shutdown_requested() const {return shutdown_requested_;}
170
172 [[nodiscard]] std::string get_shutdown_reason() const;
173
175 void abort_mission(const std::string & reason) override;
176
178 void hold_mission_progress(bool hold) override;
179
181 void request_shutdown(const std::string & reason) override;
182
185 const std::vector<ParameterChange> & changes, const std::string & reason) override;
186
188 bool request_restore_parameters(const std::string & reason) override;
189
191 [[nodiscard]] const safety::SafetySupervisor & get_safety() const {return safety_;}
192
194 [[nodiscard]] std::string get_configuration_dump();
195
204
206 [[nodiscard]] bool is_reconfigure_pending() const;
207
208private:
210 void clear_cmd_vel();
211
213 void forward_deprecated_use_cmd_vel_stamped();
214
216 void configure_robot_geometry();
217
219 bool check_system_parameters();
220
222 bool check_component_frequencies();
223
225 void cleanup_subnodes();
226
228 std::map<std::string, rclcpp_lifecycle::LifecycleNode::SharedPtr> get_all_nodes();
229
231 void check_clocks();
232
234 std::chrono::steady_clock::time_point activated_at_;
235 std::chrono::steady_clock::time_point next_clock_check_;
236
239
241 std::mutex rt_mutex_;
242
244 bool active_ {false};
245
247 rclcpp::CallbackGroup::SharedPtr realtime_cbg_;
248
250 ControllerNode::SharedPtr controller_node_;
251
253 LocalizerNode::SharedPtr localizer_node_;
254
256 MapsManagerNode::SharedPtr maps_manager_node_;
257
259 PlannerNode::SharedPtr planner_node_;
260
262 SensorsNode::SharedPtr sensors_node_;
263
265 RecoveryManagerNode::SharedPtr recovery_node_;
266
268 std::atomic<bool> shutdown_requested_ {false};
269 std::string shutdown_reason_;
270 mutable std::mutex shutdown_reason_mutex_;
271
273 struct ReconfigureRequest
274 {
275 std::vector<ParameterChange> changes;
276 bool restore {false};
277 std::string reason;
278 };
279 std::optional<ReconfigureRequest> pending_reconfigure_;
280 mutable std::mutex reconfigure_mutex_;
281
283 std::map<std::string, ParameterChange> original_parameters_;
284
286 rclcpp_lifecycle::LifecycleNode::SharedPtr find_node(const std::string & name);
287
290 bool restart_with(const std::vector<ParameterChange> & changes);
291
293 std::shared_ptr<NavState> nav_state_;
294
296 GoalManager::SharedPtr goal_manager_;
297
298
300 rclcpp::Publisher<std_msgs::msg::String>::SharedPtr navstate_pub_;
301};
302
303} // namespace easynav
304
305#endif // EASYNAV_SYSTEM__SYSTEMNODE_HPP_
Declaration of the ControllerNode class, a ROS 2 lifecycle node for speed computation in Easy Navigat...
Declaration of the GoalManager class.
Declaration of the LocalizerNode class, a ROS 2 lifecycle node for localization tasks in Easy Navigat...
Declaration of the MapsManagerNode class, a ROS 2 lifecycle node for map handling in Easy Navigation.
A blackboard-like structure to hold the current state of the navigation system.
Declaration of the PlannerNode class, a ROS 2 lifecycle node for computing navigation paths in Easy N...
Declaration of the SafetySupervisor class.
Declaration of the SensorsNode class, a ROS 2 lifecycle node for sensor fusion tasks in Easy Navigati...
A generic, type-safe, thread-safe blackboard to hold runtime state.
Definition NavState.hpp:87
void hold_mission_progress(bool hold) override
SystemActions: while held, GoalManager takes no goal as reached.
Definition SystemNode.cpp:488
CallbackReturnT on_activate(const rclcpp_lifecycle::State &state)
Activate the node.
Definition SystemNode.cpp:281
std::vector< std::string > get_nodes_without_clock()
EasyNav nodes with use_sim_time whose ROS clock has not started (still at 0): no /clock reaches them,...
Definition SystemNode.cpp:718
CallbackReturnT on_configure(const rclcpp_lifecycle::State &state)
Configure the node.
Definition SystemNode.cpp:113
CallbackReturnT on_shutdown(const rclcpp_lifecycle::State &state)
Shutdown the node.
Definition SystemNode.cpp:433
std::map< std::string, SystemNodeInfo > get_system_nodes()
Get all system nodes managed by this coordinator.
Definition SystemNode.cpp:748
CallbackReturnT on_cleanup(const rclcpp_lifecycle::State &state)
Cleanup the node.
Definition SystemNode.cpp:409
const safety::SafetySupervisor & get_safety() const
Safety mode, memory lock and configuration hash, as of the last configure.
Definition SystemNode.hpp:191
void abort_mission(const std::string &reason) override
SystemActions: aborts the active mission, if any, telling its client why.
Definition SystemNode.cpp:479
std::string get_shutdown_reason() const
Why the shutdown was requested.
Definition SystemNode.cpp:472
std::shared_ptr< NavState > get_nav_state() const
Access to the shared navigation state (for testing and tools).
Definition SystemNode.hpp:155
rclcpp::CallbackGroup::SharedPtr get_real_time_cbg()
Get the real-time callback group.
Definition SystemNode.cpp:654
bool request_reconfigure(const std::vector< ParameterChange > &changes, const std::string &reason) override
SystemActions: pending until apply_pending_reconfigure(); rejected in safety mode.
Definition SystemNode.cpp:508
CallbackReturnT on_error(const rclcpp_lifecycle::State &state)
Handle lifecycle transition error.
Definition SystemNode.cpp:440
bool request_restore_parameters(const std::string &reason) override
SystemActions: pending until apply_pending_reconfigure(); rejected in safety mode.
Definition SystemNode.cpp:520
bool apply_pending_reconfigure()
Applies the pending reconfiguration request, if any, while Active: cycles through unconfigured,...
Definition SystemNode.cpp:549
SystemNode(const rclcpp::NodeOptions &options=rclcpp::NodeOptions())
Constructor.
Definition SystemNode.cpp:46
std::string get_configuration_dump()
Every EasyNav parameter, one "node/parameter=value" per line, sorted.
Definition SystemNode.cpp:275
void system_cycle()
Non-real-time system cycle.
Definition SystemNode.cpp:689
void system_cycle_rt()
Real-time system cycle.
Definition SystemNode.cpp:660
static constexpr std::chrono::seconds kClockCheckPeriod
While Active, how often system_cycle() warns about get_nodes_without_clock().
Definition SystemNode.hpp:162
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn CallbackReturnT
Definition SystemNode.hpp:76
bool is_reconfigure_pending() const
Whether a reconfiguration is pending.
Definition SystemNode.cpp:531
bool is_shutdown_requested() const
Whether the recovery system asked EasyNav to terminate (request_shutdown()).
Definition SystemNode.hpp:169
void request_shutdown(const std::string &reason) override
SystemActions: records that EasyNav must terminate (see is_shutdown_requested()).
Definition SystemNode.cpp:496
CallbackReturnT on_deactivate(const rclcpp_lifecycle::State &state)
Deactivate the node.
Definition SystemNode.cpp:310
What SystemNode does for safety, kept out of the navigation logic.
Definition SafetySupervisor.hpp:79
Definition CircularBuffer.hpp:24
Definition PointPerception.hpp:51
Structure holding runtime information for a subnode.
Definition SystemNode.hpp:56
rclcpp::CallbackGroup::SharedPtr realtime_cbg
Associated real-time callback group.
Definition SystemNode.hpp:60
rclcpp_lifecycle::LifecycleNode::SharedPtr node_ptr
Shared pointer to the managed lifecycle node.
Definition SystemNode.hpp:58