29#ifndef EASYNAV_COMMON_TYPES__PERCEPTIONS_HPP_
30#define EASYNAV_COMMON_TYPES__PERCEPTIONS_HPP_
34#include "rclcpp/time.hpp"
35#include "rclcpp_lifecycle/lifecycle_node.hpp"
89template<
typename T = PerceptionBase>
90inline std::vector<std::shared_ptr<T>>
93 static_assert(std::is_base_of_v<PerceptionBase, T>,
94 "T must inherit from PerceptionBase");
96 std::vector<std::shared_ptr<T>> out;
97 out.reserve(src.size());
99 for (
const auto & h : src) {
100 if (!h.perception) {
continue;}
102 if constexpr (std::is_same_v<T, PerceptionBase>) {
104 out.push_back(h.perception);
107 if (
auto p = std::dynamic_pointer_cast<T>(h.perception)) {
108 out.push_back(std::move(p));
128 virtual std::shared_ptr<PerceptionBase>
create(
const std::string & sensor_id) = 0;
142 rclcpp_lifecycle::LifecycleNode & node,
143 const std::string & topic,
144 const std::string & type,
145 std::shared_ptr<PerceptionBase> target,
146 rclcpp::CallbackGroup::SharedPtr cb_group) = 0;
154 virtual std::string
group()
const = 0;
Abstract base class for representing a single sensor perception.
Definition Perceptions.hpp:45
virtual ~PerceptionBase()=default
bool valid
Whether the perception contains valid data.
Definition Perceptions.hpp:56
rclcpp::Time stamp
Timestamp of the perception (ROS time).
Definition Perceptions.hpp:50
bool new_data
Whether the data has changed since the last observation.
Definition Perceptions.hpp:59
std::string frame_id
Coordinate frame associated with the perception.
Definition Perceptions.hpp:53
Abstract base interface for group-specific perception handlers.
Definition Perceptions.hpp:121
virtual std::shared_ptr< PerceptionBase > create(const std::string &sensor_id)=0
Creates a new instance of a perception object managed by this handler.
virtual ~PerceptionHandler()=default
virtual rclcpp::SubscriptionBase::SharedPtr create_subscription(rclcpp_lifecycle::LifecycleNode &node, const std::string &topic, const std::string &type, std::shared_ptr< PerceptionBase > target, rclcpp::CallbackGroup::SharedPtr cb_group)=0
Creates a subscription that processes messages into PerceptionBase instances.
virtual std::string group() const =0
Returns the group identifier associated with this handler.
Definition CircularBuffer.hpp:28
std::shared_ptr< PerceptionBase > PerceptionBasePtr
Shared pointer alias to PerceptionBase.
Definition Perceptions.hpp:64
std::vector< std::shared_ptr< T > > get_perceptions(const std::vector< PerceptionPtr > &src)
Extracts a homogeneous collection of perceptions of type T from a heterogeneous vector.
Definition Perceptions.hpp:91
Represents a perception entry with its state and ROS subscription.
Definition Perceptions.hpp:72
rclcpp::SubscriptionBase::SharedPtr subscription
ROS 2 subscription to the sensor topic that provides data.
Definition Perceptions.hpp:77
PerceptionBasePtr perception
Shared pointer to the current perception object.
Definition Perceptions.hpp:74