Easy Navigation
Loading...
Searching...
No Matches
SensorsNode.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_SENSORS__SENSORSNODE_HPP_
20#define EASYNAV_SENSORS__SENSORSNODE_HPP_
21
22#include <mutex>
23#include <unordered_map>
24#include <vector>
25#include <map>
26#include <memory>
27#include <string>
28
29#include "rclcpp/rclcpp.hpp"
30#include "rclcpp/macros.hpp"
31#include "rclcpp_lifecycle/lifecycle_node.hpp"
32#include "sensor_msgs/msg/point_cloud2.hpp"
35#include "pluginlib/class_loader.hpp"
36
37namespace easynav
38{
39
52class SensorsNode : public rclcpp_lifecycle::LifecycleNode
53{
54public:
55 RCLCPP_SMART_PTR_DEFINITIONS(SensorsNode)
56 using CallbackReturnT = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
57
62 explicit SensorsNode(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
63
65 ~SensorsNode();
66
72 CallbackReturnT on_configure(const rclcpp_lifecycle::State & state);
73
79 CallbackReturnT on_activate(const rclcpp_lifecycle::State & state);
80
86 CallbackReturnT on_deactivate(const rclcpp_lifecycle::State & state);
87
93 CallbackReturnT on_cleanup(const rclcpp_lifecycle::State & state);
94
100 CallbackReturnT on_shutdown(const rclcpp_lifecycle::State & state);
101
107 CallbackReturnT on_error(const rclcpp_lifecycle::State & state);
108
113 rclcpp::CallbackGroup::SharedPtr get_real_time_cbg();
114
120 bool cycle_rt(std::shared_ptr<NavState> nav_state, bool trigger = false);
121
125 void cycle(std::shared_ptr<NavState> nav_state);
126
127protected:
129 std::map<std::string, std::vector<std::string>> groups_;
130
138 std::unique_ptr<pluginlib::ClassLoader<PerceptionHandler>> handler_loader_;
139
141 std::vector<std::shared_ptr<PerceptionHandler>> handler_list_;
142
148
149private:
151 void release_handlers();
152
154 enum class DataState : uint8_t {FRESH, NO_DATA, STALE};
155
157 void check_data_age(
158 const std::vector<std::shared_ptr<PerceptionHandler>> & handlers, NavState & nav_state);
159
161 void report_data_age(
162 const std::vector<std::shared_ptr<PerceptionHandler>> & handlers, NavState & nav_state);
163
165 std::vector<DataState> data_states_;
166 bool data_age_reported_ {false};
167
169 rclcpp::CallbackGroup::SharedPtr realtime_cbg_;
170
172 rclcpp_lifecycle::LifecyclePublisher<sensor_msgs::msg::PointCloud2>::SharedPtr percept_pub_;
173
175 sensor_msgs::msg::PointCloud2 perecption_msg_;
176
178 double forget_time_ {1.0};
179
181 std::string tf_prefix_;
182
184 bool groups_initialized = false;
185
191 std::unordered_map<std::string, std::string> type_to_plugin_;
192};
193
194} // namespace easynav
195
196#endif // EASYNAV_SENSORS__SENSORSNODE_HPP_
A blackboard-like structure to hold the current state of the navigation system.
Defines data structures and utilities for representing and processing sensor perceptions.
A generic, type-safe, thread-safe blackboard to hold runtime state.
Definition NavState.hpp:87
Abstract base class for pluginlib-based sensor perception handlers.
Definition Perceptions.hpp:117
CallbackReturnT on_activate(const rclcpp_lifecycle::State &state)
Activate the node.
Definition SensorsNode.cpp:185
CallbackReturnT on_configure(const rclcpp_lifecycle::State &state)
Configure the node.
Definition SensorsNode.cpp:99
void cycle(std::shared_ptr< NavState > nav_state)
Run one non-real-time processing cycle.
Definition SensorsNode.cpp:347
CallbackReturnT on_shutdown(const rclcpp_lifecycle::State &state)
Shutdown the node.
Definition SensorsNode.cpp:215
CallbackReturnT on_cleanup(const rclcpp_lifecycle::State &state)
Cleanup the node.
Definition SensorsNode.cpp:205
SensorsNode(const rclcpp::NodeOptions &options=rclcpp::NodeOptions())
Constructor.
Definition SensorsNode.cpp:46
std::map< std::string, std::vector< std::string > > groups_
Sensor groups (set as group of keys in the NavState).
Definition SensorsNode.hpp:129
bool cycle_rt(std::shared_ptr< NavState > nav_state, bool trigger=false)
Run one real-time sensor processing cycle.
Definition SensorsNode.cpp:242
rclcpp::CallbackGroup::SharedPtr get_real_time_cbg()
Get the callback group for real-time tasks.
Definition SensorsNode.cpp:236
std::mutex handler_list_mutex_
Guards handler_list_ between the RT thread (cycle_rt) and the non-RT thread (on_cleanup),...
Definition SensorsNode.hpp:147
CallbackReturnT on_error(const rclcpp_lifecycle::State &state)
Handle lifecycle transition errors.
Definition SensorsNode.cpp:226
std::unique_ptr< pluginlib::ClassLoader< PerceptionHandler > > handler_loader_
Pluginlib class loader for PerceptionHandler plugins.
Definition SensorsNode.hpp:138
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn CallbackReturnT
Definition SensorsNode.hpp:56
std::vector< std::shared_ptr< PerceptionHandler > > handler_list_
vector of PerceptionHandler instances
Definition SensorsNode.hpp:141
CallbackReturnT on_deactivate(const rclcpp_lifecycle::State &state)
Deactivate the node.
Definition SensorsNode.cpp:195
Definition CircularBuffer.hpp:24
Definition PointPerception.hpp:51