Smartcar Shield
Public Member Functions | List of all members
DistanceSensor Interface Referenceabstract

#include <DistanceSensor.hpp>

Inheritance diagram for DistanceSensor:
Inheritance graph
Collaboration diagram for DistanceSensor:
Collaboration graph

Public Member Functions

virtual ~DistanceSensor ()=default
 
virtual unsigned int getDistance ()=0
 Gets the distance measured by the sensor in centimeters. More...
 
virtual unsigned int getMedianDistance (uint8_t iterations)=0
 Gets the median distance from the specified number of measurements. More...
 

Detailed Description

A parent class for all sensors that conduct distance measurements.

Definition at line 20 of file DistanceSensor.hpp.

Constructor & Destructor Documentation

◆ ~DistanceSensor()

virtual DistanceSensor::~DistanceSensor ( )
virtualdefault

Member Function Documentation

◆ getDistance()

virtual unsigned int DistanceSensor::getDistance ( )
pure virtual

Gets the distance measured by the sensor in centimeters.

Calling this might trigger a new measurement by the sensor.

Returns
0 if an error has occured, otherwise the measured distance in centimeters

Example:

unsigned int distance = sensor.getDistance();

Implemented in SR04, SRF08, GP2D120, GP2Y0A02, and GP2Y0A21.

Here is the caller graph for this function:

◆ getMedianDistance()

virtual unsigned int DistanceSensor::getMedianDistance ( uint8_t  iterations)
pure virtual

Gets the median distance from the specified number of measurements.

Parameters
iterationsNumber of measurements to conduct (at most kMaxMedianMeasurements)
Returns
The median of the conducted measurements or an error value if the number of iterations is 0 or larger than kMaxMedianMeasurements

Example:

// Get the median of `10` measurements
unsigned int distance = sensor.getMedianDistance(10);

Implemented in SRF08, SR04, and InfraredAnalogSensor.


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