libstp
Robotics library for Botball
Loading...
Searching...
No Matches
libstp::sensors::ir::IRSensor Class Reference

#include <IRSensor.hpp>

Inheritance diagram for libstp::sensors::ir::IRSensor:
[legend]
Collaboration diagram for libstp::sensors::ir::IRSensor:
[legend]

Public Member Functions

 IRSensor (const int &port)
bool isCalibrated () const
bool calibrate (const std::vector< float > &values)
void setCalibration (float newBlackThreshold, float newWhiteThreshold)
bool isOnWhite () const
virtual bool isOnBlack ()
float probabilityOfBlack () const
float probabilityOfWhite () const
Public Member Functions inherited from libstp::hal::analog::AnalogSensor
 AnalogSensor (int port)
 Create an analog sensor bound to a platform-defined port index.
virtual ~AnalogSensor ()
virtual int read () const
 Read the current raw analog value from the selected platform.

Static Public Member Functions

static float mean (const std::vector< float > &v)
static float stddev (const std::vector< float > &v)
static float variance (const std::vector< float > &v, float m)

Public Attributes

float whiteThreshold
float blackThreshold
float whiteMean = 0.0f
float blackMean = 0.0f
float whiteStdDev = 1.0f
float blackStdDev = 1.0f
Public Attributes inherited from libstp::hal::analog::AnalogSensor
int port

Detailed Description

Reflectance sensor with black/white threshold classification helpers.

The class extends the generic HAL analog sensor with calibration state derived from observed black and white samples.

Definition at line 19 of file IRSensor.hpp.

Constructor & Destructor Documentation

◆ IRSensor()

libstp::sensors::ir::IRSensor::IRSensor ( const int & port)
explicit

Construct an IR sensor on port.

On construction the sensor automatically applies any stored calibration for its port from the process-wide CalibrationStore (set "default_port<port>"). When no stored calibration is found the sensor stays uncalibrated and any black/white query will throw until it is calibrated.

Member Function Documentation

◆ calibrate()

bool libstp::sensors::ir::IRSensor::calibrate ( const std::vector< float > & values)

Update thresholds and distribution statistics from raw readings.

◆ isCalibrated()

bool libstp::sensors::ir::IRSensor::isCalibrated ( ) const
nodiscard

Return true once thresholds have been established (stored, loaded or live).

◆ isOnBlack()

virtual bool libstp::sensors::ir::IRSensor::isOnBlack ( )
virtual

Return true when the current reading is classified as black.

◆ isOnWhite()

bool libstp::sensors::ir::IRSensor::isOnWhite ( ) const

Return true when the current reading is classified as white.

◆ mean()

float libstp::sensors::ir::IRSensor::mean ( const std::vector< float > & v)
static

Compute the arithmetic mean of a sample set.

◆ probabilityOfBlack()

float libstp::sensors::ir::IRSensor::probabilityOfBlack ( ) const

Estimate how likely the current reading belongs to the black cluster.

◆ probabilityOfWhite()

float libstp::sensors::ir::IRSensor::probabilityOfWhite ( ) const

Estimate how likely the current reading belongs to the white cluster.

◆ setCalibration()

void libstp::sensors::ir::IRSensor::setCalibration ( float newBlackThreshold,
float newWhiteThreshold )

Replace the classification thresholds without recomputing sample statistics.

◆ stddev()

float libstp::sensors::ir::IRSensor::stddev ( const std::vector< float > & v)
static

Compute the sample standard deviation of a sample set.

◆ variance()

float libstp::sensors::ir::IRSensor::variance ( const std::vector< float > & v,
float m )
static

Compute the variance of a sample set around a known mean.

Member Data Documentation

◆ blackMean

float libstp::sensors::ir::IRSensor::blackMean = 0.0f

Definition at line 25 of file IRSensor.hpp.

◆ blackStdDev

float libstp::sensors::ir::IRSensor::blackStdDev = 1.0f

Definition at line 27 of file IRSensor.hpp.

◆ blackThreshold

float libstp::sensors::ir::IRSensor::blackThreshold

Definition at line 23 of file IRSensor.hpp.

◆ whiteMean

float libstp::sensors::ir::IRSensor::whiteMean = 0.0f

Definition at line 24 of file IRSensor.hpp.

◆ whiteStdDev

float libstp::sensors::ir::IRSensor::whiteStdDev = 1.0f

Definition at line 26 of file IRSensor.hpp.

◆ whiteThreshold

float libstp::sensors::ir::IRSensor::whiteThreshold

Definition at line 22 of file IRSensor.hpp.


The documentation for this class was generated from the following file:
  • /home/runner/work/raccoon-lib/raccoon-lib/modules/libstp-sensor-ir/include/IRSensor.hpp