Class AnalogDistanceSensor
Defined in File analog_distance_sensor.hpp
Inheritance Relationships
Base Type
public tap::sensors::DistanceSensor
(Class DistanceSensor)
Derived Type
public tap::sensors::SharpIrGP2Y0A41
(Class SharpIrGP2Y0A41)
Class Documentation
-
class AnalogDistanceSensor : public tap::sensors::DistanceSensor
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 \).
Subclassed by tap::sensors::SharpIrGP2Y0A41
Public Functions
-
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:
minDistance – [in] the sensor’s min valid distance
maxDistance – [in] the sensor’s max valid distance
m – [in] the slope of the linear model that describes the relationship between analog input and distance.
b – [in] the y intercept of the linear model that describes the relationship between analog input and distance.
offset – [in] the offset in the non-linear portion of the model.
pin – [in] the analog pin that the sensor is connected to.
-
virtual float read() override
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.
-
virtual bool validReading() const override
Checks if current reading is within bounds.
- Returns:
true
if the reading is within the min and max distance, exclusive. Returnsfalse
otherwise.