EduArt Sensor Ring Library 3.0.0
Loading...
Searching...
No Matches
BaseSensor.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 EduArt Robotik GmbH
2
9
10#pragma once
11
12#include <cstdint>
13#include <future>
14#include <mutex>
15#include <optional>
16#include <vector>
17
21#include "sensorring/platform/SensorringExport.hpp"
23
24namespace eduart {
25// Forward declaration
26namespace com {
27class ComInterface;
28}
29
30namespace device {
31
38class SENSORRING_EXPORT BaseSensor {
39public:
47 BaseSensor(com::ComInterface* interface, com::ComEndpoint target, unsigned int idx, bool enable);
49 virtual ~BaseSensor();
50
55 unsigned int getIdx() const;
56
61 bool getEnable() const;
62
67 void setEnable(bool enable);
68
74 void setPose(math::Vector3 translation, math::Vector3 rotation);
75
82
87
92 std::future<bool> beginMeasurementWait();
93
98 std::future<bool> beginDataAvailableWait();
99
100protected:
105 void setMeasurementReady(bool success);
106
111 void setDataAvailableReady(bool success);
112
113protected:
119 virtual void onResetSensorState() = 0;
120
126 virtual void onClearDataFlag() = 0;
127
133 virtual void comCallback(const com::ComEndpoint source, const std::vector<std::uint8_t>& data) = 0;
134
136 unsigned int _idx;
140 com::ComInterface* _interface;
141
148
153 mutable std::mutex _state_mutex;
154
156 std::optional<std::promise<bool> > _measurement_promise;
158 std::optional<std::promise<bool> > _data_available_promise;
161 std::mutex _promise_mutex;
162
165};
166
167} // namespace device
168
169} // namespace eduart
Communication endpoint identifier.
Unified device state enum covering lifecycle and runtime health.
DeviceState
Unified lifecycle and runtime state of a device.
Definition DeviceState.hpp:28
Implementation of a matrix of size 3 × 3.
RAII wrapper pairing a SubscriberToken with its cancel function.
Uniquely identifies a communication endpoint by its string ID.
Definition ComEndpoint.hpp:25
bool getEnable() const
Query if the sensor is currently enabled.
void resetSensorState()
Reset error state and internal flags to nominal values.
std::optional< std::promise< bool > > _data_available_promise
Promise for the current data-available-wait cycle; set by callback when "data available" is received.
Definition BaseSensor.hpp:158
DeviceState _error
Current health state of the sensor.
Definition BaseSensor.hpp:138
std::mutex _state_mutex
Definition BaseSensor.hpp:153
std::future< bool > beginMeasurementWait()
Start a measurement-wait cycle and return a future that will be set when the measurement is ready.
virtual void onResetSensorState()=0
Sensor-specific hook invoked from resetSensorState().
math::Matrix3 _rot_m
Rotation matrix derived from the Euler angles.
Definition BaseSensor.hpp:147
void setDataAvailableReady(bool success)
Set the result of the current data-available-wait cycle. Called from derived callbacks when "data ava...
virtual void comCallback(const com::ComEndpoint source, const std::vector< std::uint8_t > &data)=0
Handle an incoming communication message for this sensor.
com::ComInterface * _interface
Communication interface used to talk to the sensor.
Definition BaseSensor.hpp:140
void setEnable(bool enable)
Enable or disable the sensor.
void setPose(math::Vector3 translation, math::Vector3 rotation)
Set the pose of the sensor in the common coordinate frame.
bool _enable_flag
Flag indicating whether the sensor is enabled.
Definition BaseSensor.hpp:150
std::mutex _promise_mutex
Definition BaseSensor.hpp:161
std::future< bool > beginDataAvailableWait()
Start a data-available-wait cycle and return a future that will be set when new data is available.
virtual void onClearDataFlag()=0
Sensor-specific hook invoked from clearDataFlag().
unsigned int _idx
Index of this sensor instance within its group.
Definition BaseSensor.hpp:136
math::Vector3 _translation
Translation of the sensor origin in the common coordinate frame.
Definition BaseSensor.hpp:143
BaseSensor(com::ComInterface *interface, com::ComEndpoint target, unsigned int idx, bool enable)
Construct a base sensor and register it with the communication interface.
void setMeasurementReady(bool success)
Set the result of the current measurement-wait cycle. Called from derived callbacks when ready.
unsigned int getIdx() const
Get the index of this sensor instance.
math::Vector3 _rotation
Rotation of the sensor expressed as Euler angles in degrees.
Definition BaseSensor.hpp:145
virtual ~BaseSensor()
Destructor.
std::optional< std::promise< bool > > _measurement_promise
Promise for the current measurement-wait cycle; set by callback, consumed by wait + get().
Definition BaseSensor.hpp:156
subscription::Subscription _com_subscription
RAII subscription to the communication interface.
Definition BaseSensor.hpp:164
void clearDataFlag()
Clear state for the next measurement cycle. Calls the sensor-specific hook onClearDataFlag().
Move-only RAII wrapper that pairs a SubscriberToken with an unsubscribe callable. Destroying a Subscr...
Definition Subscription.hpp:30
Matrix of size 3 × 3.
Definition Matrix3.hpp:26
Vector of length 3.
Definition Vector3.hpp:25