EduArt Sensor Ring Library 4.0.0
Loading...
Searching...
No Matches
eduart::sensorring::device::DepthSensor Class Referenceabstract

Base class for any depth-sensing device. More...

#include <DepthSensor.hpp>

Inheritance diagram for eduart::sensorring::device::DepthSensor:
[legend]
Collaboration diagram for eduart::sensorring::device::DepthSensor:
[legend]

Public Types

using MeasurementType = measurement::DepthMeasurement
 Measurement type produced by this sensor category.

Public Member Functions

 DepthSensor (DeviceID id, com::ComInterface *interface, com::ComEndpoint target, DepthSensorConfig config)
 Construct a DepthSensor with Device params, field-of-view and pixel resolution.
virtual const DepthSensorParams & getParams () const =0
 Get the current DepthSensor parameters.
const measurement::DepthMeasurement & getLatestMeasurement () const
 Get the most recent measurement.
subscription::Subscription subscribe (std::function< void(const measurement::DepthMeasurement &)> callback)
 Subscribe to depth measurements from this sensor.
virtual void publishMeasurement ()
 Build a DepthMeasurement from internal state and publish to all subscribers.
Public Member Functions inherited from eduart::sensorring::device::Sensor
 Sensor (DeviceID id, com::ComInterface *interface, com::ComEndpoint target)
 Construct the sensor with identity and communication link.
std::future< bool > measure (std::uint8_t sequence_number)
std::future< bool > fetch ()
std::future< bool > beginMeasurementWait ()
 Begin an asynchronous wait for the next measurement trigger.
void setMeasurementReady (bool success)
 Satisfy the pending measurement-wait future.
std::future< bool > beginDataAvailableWait ()
 Begin an asynchronous wait for new data to become available.
void setDataAvailableReady (bool success)
 Satisfy the pending data-available-wait future.
void resetSensorState ()
 Reset the device to its initialised state, clearing all error flags.
void clearDataFlag ()
 Clear the data-available flag so the device can accept the next measurement cycle.
Public Member Functions inherited from eduart::sensorring::device::Device
 Device (DeviceID id, com::ComInterface *interface, com::ComEndpoint target)
 Construct the device with identity and communication link.
DeviceID getDeviceID () const
 Return the full device identifier (type + index).
unsigned int getHwIdx () const
 Return the zero-based hardware board index on its bus (used for CAN addressing and protocol bitmasks).
void setDeviceIndex (unsigned int index)
 Reassign the logical device index (DeviceID.index) without changing the hardware index.
virtual bool configure ()
 Apply post-reset runtime configuration for this device.
void setBoardContext (const board::SensorBoardParams *board_params)
 Initialize board-level context pointer (non-owning).
const board::SensorBoardParams * getBoardContext () const
 Return the board-level context pointer (non-owning).
void setPoseOffset (const math::Pose &offset)
 Store a pose offset relative to the board centre.
math::Pose getPoseOffset () const
 Return the stored pose offset relative to the board centre.
math::Pose getGlobalPose () const
 Compute and return the global pose in the ring coordinate frame.
Public Member Functions inherited from eduart::sensorring::ActionDispatcher
void setQueue (ActionQueue *queue)
void clearQueue ()
bool isManaged () const
void execute (Action action)
void execute (std::string_view key, Action action)

Protected Member Functions

void updateResolution (double fov_x_deg, double fov_y_deg, unsigned int res_x, unsigned int res_y)
 Update the sensor's FOV and resolution, and recalculate the lookup tables.
virtual void createLookupTable (DepthSensorConfig config, std::vector< double > &lut_x, std::vector< double > &lut_y, std::vector< double > &lut_z)
 Create lookup tables for x and y angles based on FOV and resolution.
void processRawMeasurement (measurement::PointCloud &pcl)
 Calculate the x,y,z coordinates from the raw distance measurements.
Protected Member Functions inherited from eduart::sensorring::device::Sensor
virtual bool sendMeasurementRequest (std::uint8_t sequence_number)=0
virtual bool sendMeasurementTransmissionRequest ()=0
virtual void onResetSensorState ()
virtual void onClearDataFlag ()
Protected Member Functions inherited from eduart::sensorring::device::Device
virtual void comCallback (const com::ComEndpoint source, std::uint8_t command, const std::vector< std::uint8_t > &data)=0

Protected Attributes

DepthSensorConfig _config
std::vector< double > _lut_x
std::vector< double > _lut_y
std::vector< double > _lut_z
measurement::DepthMeasurement _latest_measurement
subscription::Publisher< const measurement::DepthMeasurement & > _depth_publisher
Protected Attributes inherited from eduart::sensorring::device::Sensor
DeviceState _state
std::mutex _state_mutex
std::mutex _promise_mutex
std::optional< std::promise< bool > > _data_available_promise
std::optional< std::promise< bool > > _measurement_promise
Protected Attributes inherited from eduart::sensorring::device::Device
DeviceID _id
unsigned int _hw_idx
com::ComInterface * _interface
const board::SensorBoardParams * _board_params = nullptr
math::Pose _offset
subscription::Subscription _com_subscription

Additional Inherited Members

Static Public Member Functions inherited from eduart::sensorring::ActionDispatcher
static void globalExecute (Action action)

Detailed Description

Base class for any depth-sensing device.

Inherits from Sensor (which provides Device identity + measurement sync). Users subscribe to depth measurements via subscribe(). The concrete sensor implementation publishes measurements by calling publishMeasurement() from the state machine thread.

Constructor & Destructor Documentation

◆ DepthSensor()

eduart::sensorring::device::DepthSensor::DepthSensor ( DeviceID id,
com::ComInterface * interface,
com::ComEndpoint target,
DepthSensorConfig config )

Construct a DepthSensor with Device params, field-of-view and pixel resolution.

Parameters
[in]idDevice identifier.
[in]interfaceCommunication interface.
[in]targetCommunication endpoint this device listens to.
[in]configConfiguration options for the depth sensor.

Member Function Documentation

◆ createLookupTable()

virtual void eduart::sensorring::device::DepthSensor::createLookupTable ( DepthSensorConfig config,
std::vector< double > & lut_x,
std::vector< double > & lut_y,
std::vector< double > & lut_z )
protectedvirtual

Create lookup tables for x and y angles based on FOV and resolution.

Parameters
[in]configDepth sensor configuration containing FOV and resolution.
[out]lut_xOutput vector for horizontal angle lookup table. Output length is res_x.
[out]lut_yOutput vector for vertical angle lookup table. Output length is res_y.
[out]lut_zOutput vector for depth lookup table. Output length is res_x * res_y.

◆ getLatestMeasurement()

const measurement::DepthMeasurement & eduart::sensorring::device::DepthSensor::getLatestMeasurement ( ) const

Get the most recent measurement.

Returns
Reference to the latest depth measurement (check header.state for validity).

◆ getParams()

virtual const DepthSensorParams & eduart::sensorring::device::DepthSensor::getParams ( ) const
pure virtual

Get the current DepthSensor parameters.

Returns
current DepthSensor parameters.

Implemented in eduart::sensorring::device::TMF8829_Device, and eduart::sensorring::device::VL53L8CX_Device.

◆ processRawMeasurement()

void eduart::sensorring::device::DepthSensor::processRawMeasurement ( measurement::PointCloud & pcl)
protected

Calculate the x,y,z coordinates from the raw distance measurements.

Uses the internally managed lookup tables (_lut_x/_lut_y), which are updated on construction and via updateResolution().

Parameters
[in,out]pclPoint cloud to operate on. Distance must be populated, x,y,z will be calculated and filled in.

◆ publishMeasurement()

virtual void eduart::sensorring::device::DepthSensor::publishMeasurement ( )
virtual

Build a DepthMeasurement from internal state and publish to all subscribers.

Called by the state machine after a successful measurement fetch.

◆ subscribe()

subscription::Subscription eduart::sensorring::device::DepthSensor::subscribe ( std::function< void(const measurement::DepthMeasurement &)> callback)
inline

Subscribe to depth measurements from this sensor.

Parameters
[in]callbackInvoked with each new measurement.
Returns
RAII Subscription that auto-cancels on destruction.

◆ updateResolution()

void eduart::sensorring::device::DepthSensor::updateResolution ( double fov_x_deg,
double fov_y_deg,
unsigned int res_x,
unsigned int res_y )
protected

Update the sensor's FOV and resolution, and recalculate the lookup tables.

Parameters
[in]fov_x_degNew horizontal field of view in degrees.
[in]fov_y_degNew vertical field of view in degrees.
[in]res_xNew horizontal resolution in pixels (columns).
[in]res_yNew vertical resolution in pixels (rows).

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