EduArt Sensor Ring Library 3.0.0
Loading...
Searching...
No Matches
eduart::device::BaseSensor Class Referenceabstract

Abstract base class for sensors. More...

#include <BaseSensor.hpp>

Inheritance diagram for eduart::device::BaseSensor:
[legend]
Collaboration diagram for eduart::device::BaseSensor:
[legend]

Public Member Functions

 BaseSensor (com::ComInterface *interface, com::ComEndpoint target, unsigned int idx, bool enable)
 Construct a base sensor and register it with the communication interface.
virtual ~BaseSensor ()
 Destructor.
unsigned int getIdx () const
 Get the index of this sensor instance.
bool getEnable () const
 Query if the sensor is currently enabled.
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.
void resetSensorState ()
 Reset error state and internal flags to nominal values.
void clearDataFlag ()
 Clear state for the next measurement cycle. Calls the sensor-specific hook onClearDataFlag().
std::future< bool > beginMeasurementWait ()
 Start a measurement-wait cycle and return a future that will be set when the measurement is ready.
std::future< bool > beginDataAvailableWait ()
 Start a data-available-wait cycle and return a future that will be set when new data is available.

Protected Member Functions

void setMeasurementReady (bool success)
 Set the result of the current measurement-wait cycle. Called from derived callbacks when ready.
void setDataAvailableReady (bool success)
 Set the result of the current data-available-wait cycle. Called from derived callbacks when "data available" is received.
virtual void onResetSensorState ()=0
 Sensor-specific hook invoked from resetSensorState().
virtual void onClearDataFlag ()=0
 Sensor-specific hook invoked from clearDataFlag().
virtual void comCallback (const com::ComEndpoint source, const std::vector< std::uint8_t > &data)=0
 Handle an incoming communication message for this sensor.

Protected Attributes

unsigned int _idx
 Index of this sensor instance within its group.
DeviceState _error
 Current health state of the sensor.
com::ComInterface * _interface
 Communication interface used to talk to the sensor.
math::Vector3 _translation
 Translation of the sensor origin in the common coordinate frame.
math::Vector3 _rotation
 Rotation of the sensor expressed as Euler angles in degrees.
math::Matrix3 _rot_m
 Rotation matrix derived from the Euler angles.
bool _enable_flag
 Flag indicating whether the sensor is enabled.
std::mutex _state_mutex
std::optional< std::promise< bool > > _measurement_promise
 Promise for the current measurement-wait cycle; set by callback, consumed by wait + get().
std::optional< std::promise< bool > > _data_available_promise
 Promise for the current data-available-wait cycle; set by callback when "data available" is received.
std::mutex _promise_mutex
subscription::Subscription _com_subscription
 RAII subscription to the communication interface.

Detailed Description

Abstract base class for sensors.

Provides state tracking, pose handling and notification hooks for derived sensors.

Constructor & Destructor Documentation

◆ BaseSensor()

eduart::device::BaseSensor::BaseSensor ( com::ComInterface * interface,
com::ComEndpoint target,
unsigned int idx,
bool enable )

Construct a base sensor and register it with the communication interface.

Parameters
[in]interfaceCommunication interface used to exchange messages with the sensor.
[in]targetEndpoint on the interface this sensor listens to.
[in]idxIndex of the sensor instance.
[in]enableInitial enabled state of the sensor.

Member Function Documentation

◆ beginDataAvailableWait()

std::future< bool > eduart::device::BaseSensor::beginDataAvailableWait ( )

Start a data-available-wait cycle and return a future that will be set when new data is available.

Returns
Future that will hold true when new data has been signalled as available.

◆ beginMeasurementWait()

std::future< bool > eduart::device::BaseSensor::beginMeasurementWait ( )

Start a measurement-wait cycle and return a future that will be set when the measurement is ready.

Returns
Future that will hold true when the measurement has been fetched successfully.

◆ comCallback()

virtual void eduart::device::BaseSensor::comCallback ( const com::ComEndpoint source,
const std::vector< std::uint8_t > & data )
protectedpure virtual

Handle an incoming communication message for this sensor.

Parameters
[in]sourceEndpoint that sent the message.
[in]dataMessage payload.

◆ getEnable()

bool eduart::device::BaseSensor::getEnable ( ) const

Query if the sensor is currently enabled.

Returns
true if the sensor is enabled.

◆ getIdx()

unsigned int eduart::device::BaseSensor::getIdx ( ) const

Get the index of this sensor instance.

Returns
Sensor index.

◆ onClearDataFlag()

virtual void eduart::device::BaseSensor::onClearDataFlag ( )
protectedpure virtual

Sensor-specific hook invoked from clearDataFlag().

Implementations should clear any additional flags related to buffered data.

◆ onResetSensorState()

virtual void eduart::device::BaseSensor::onResetSensorState ( )
protectedpure virtual

Sensor-specific hook invoked from resetSensorState().

Implementations should reset any additional state related to errors or measurements.

◆ resetSensorState()

void eduart::device::BaseSensor::resetSensorState ( )

Reset error state and internal flags to nominal values.

Calls the sensor-specific hook onResetSensorState().

◆ setDataAvailableReady()

void eduart::device::BaseSensor::setDataAvailableReady ( bool success)
protected

Set the result of the current data-available-wait cycle. Called from derived callbacks when "data available" is received.

Parameters
[in]successtrue if data available was signalled successfully.

◆ setEnable()

void eduart::device::BaseSensor::setEnable ( bool enable)

Enable or disable the sensor.

Parameters
[in]enableNew enabled state. Set to true to enable the sensor, false to disable it.

◆ setMeasurementReady()

void eduart::device::BaseSensor::setMeasurementReady ( bool success)
protected

Set the result of the current measurement-wait cycle. Called from derived callbacks when ready.

Parameters
[in]successtrue if measurement was fetched successfully.

◆ setPose()

void eduart::device::BaseSensor::setPose ( math::Vector3 translation,
math::Vector3 rotation )

Set the pose of the sensor in the common coordinate frame.

Parameters
[in]translationTranslation of the sensor origin.
[in]rotationRotation as Euler angles in degrees.

Member Data Documentation

◆ _promise_mutex

std::mutex eduart::device::BaseSensor::_promise_mutex
protected

Protects promise lifecycles (create in batch thread, set in callback thread).

Note
Locking order: acquire _state_mutex before _promise_mutex.

◆ _state_mutex

std::mutex eduart::device::BaseSensor::_state_mutex
mutableprotected

Mutex protecting sensor state mutations.

Note
Locking order: acquire _state_mutex before _promise_mutex.

The documentation for this class was generated from the following file: