Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
tap::sensors::AnalogDistanceSensor Class Reference

#include <analog_distance_sensor.hpp>

Inheritance diagram for tap::sensors::AnalogDistanceSensor:
Collaboration diagram for tap::sensors::AnalogDistanceSensor:

Public Member Functions

 AnalogDistanceSensor (Drivers *drivers, float minDistance, float maxDistance, float m, float b, float offset, gpio::Analog::Pin pin)
 
float read () override
 
bool validReading () const override
 
- Public Member Functions inherited from tap::sensors::DistanceSensor
 DistanceSensor (float minDistance, float maxDistance)
 
virtual ~DistanceSensor ()=default
 
virtual void init ()=0
 
float getMinDistance () const
 
float getMaxDistance () const
 
float getDistance () const
 

Additional Inherited Members

- Protected Attributes inherited from tap::sensors::DistanceSensor
float distance
 Distance from sensor.
 
float minDistance
 Lower boundary for reliable readings.
 
float maxDistance
 Upper boundary for reliable readings.
 

Detailed Description

Basic analog IR Sensor.

  • The distance conversion can be tweaked depending on the sensor.
  • Min and max distance are in cm.

See here (https://i.stack.imgur.com/babQg.png) for a graph of what an IR sensor should look like. Datasheets will have specifics for what the distance curve should look like. Thsi class gives a general curve fit that first calculates a linear fit from the raw voltage of the form $ y=mx+b $ and then the output is put into the equation $ dist = \frac{1}{linear} + offset $.

Constructor & Destructor Documentation

◆ AnalogDistanceSensor()

tap::sensors::AnalogDistanceSensor::AnalogDistanceSensor ( Drivers drivers,
float  minDistance,
float  maxDistance,
float  m,
float  b,
float  offset,
gpio::Analog::Pin  pin 
)

Constructor to initialize the analog IR boundary, distance conversion, and analog pin.

Parameters
[in]minDistancethe sensor's min valid distance
[in]maxDistancethe sensor's max valid distance
[in]mthe slope of the linear model that describes the relationship between analog input and distance.
[in]bthe y intercept of the linear model that describes the relationship between analog input and distance.
[in]offsetthe offset in the non-linear portion of the model.
[in]pinthe analog pin that the sensor is connected to.

Member Function Documentation

◆ read()

float tap::sensors::AnalogDistanceSensor::read ( )
overridevirtual

Reads the sensor, updates the current distance, and returns this reading.

Returns
the updated value. May or may not be valid. If it is not valid, -1 is returned.

Implements tap::sensors::DistanceSensor.

◆ validReading()

bool tap::sensors::AnalogDistanceSensor::validReading ( ) const
overridevirtual

Checks if current reading is within bounds.

Returns
true if the reading is within the min and max distance, exclusive. Returns false otherwise.

Implements tap::sensors::DistanceSensor.


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