Easyuino  1.2.0
Easyuino::DistanceMeterAccurate Class Reference

DistanceMeterAccurate offers an API to interact with an Ultrasonic Module to measure distances considering the current air temperature (due to the effect that the air temperature have in the sound speed in air). More...

#include <DistanceMeterAccurate.h>

Inheritance diagram for Easyuino::DistanceMeterAccurate:
Easyuino::DistanceMeterNonBlock Easyuino::DistanceMeter Easyuino::Device

Public Member Functions

 DistanceMeterAccurate (IN uint8_t triggerPin, IN uint8_t echoPin)
 Constructor. More...
 
 DistanceMeterAccurate (IN uint8_t triggerEchoPin)
 Contructor used with Ultrasonic Modules that have only one pin for trigger and echo. More...
 
 ~DistanceMeterAccurate ()
 Destructor.
 
float getDistanceCentimeters ()
 Gets the last value that the API measured using the Ultrasonic Module. More...
 
void updateDistance (IN float airTemperature=DEFAULT_AIR_TEMPERATURE_CELSIUS, IN TemperatureScale temperatureScale=CELSIUS)
 Updates the distance of the Ultrasonic Module to the objects in a blocking way. More...
 
void updateDistanceNonBlock (IN float airTemperature=DEFAULT_AIR_TEMPERATURE_CELSIUS, IN TemperatureScale temperatureScale=CELSIUS)
 Updates the distance of the Ultrasonic Module to the objects in a non-blocking way. More...
 
- Public Member Functions inherited from Easyuino::DistanceMeterNonBlock
 DistanceMeterNonBlock (IN uint8_t triggerPin, IN uint8_t echoPin)
 Constructor. More...
 
 DistanceMeterNonBlock (IN uint8_t triggerEchoPin)
 Contructor used with Ultrasonic Modules that have only one pin for trigger and echo. More...
 
 ~DistanceMeterNonBlock ()
 Destructor.
 
bool begin ()
 Used to put the device ready to receive requests. More...
 
void end ()
 Used to stop the device API. More...
 
float getDistanceCentimeters ()
 Gets the last value that the API measured using the Ultrasonic Module. More...
 
void updateDistance ()
 Updates the distance of the Ultrasonic Module to the objects in a blocking way. More...
 
virtual void updateDistanceNonBlock ()
 Updates the distance of the Ultrasonic Module to the objects in a non-blocking way. More...
 
- Public Member Functions inherited from Easyuino::DistanceMeter
 DistanceMeter (IN uint8_t triggerPin, IN uint8_t echoPin)
 Constructor. More...
 
 DistanceMeter (IN uint8_t triggerEchoPin)
 Contructor used with Ultrasonic Modules that have only one pin for trigger and echo. More...
 
 ~DistanceMeter ()
 Destructor.
 
float getDistanceInches ()
 Gets the last value that the API measured using the US. More...
 
- Public Member Functions inherited from Easyuino::Device
 Device ()
 Constructor called by every sub-classes.
 
 ~Device ()
 Destroy all the resources associated with the device.
 
bool isInitialized () const
 Verify is the device is initialized and ready to use. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Easyuino::DistanceMeterNonBlock
void executeUpdateDistanceNonBlock ()
 Execute a non-block distance measurement.
 
bool isUpdateDistanceNonBlockTimeout ()
 Verify if there is a non-block measuremenet on going that has already timeouted. More...
 
float calculateDistance (IN float soundSpeedCmPerSec)
 Calculates the distance to the object based on the sound speed in air using the last distance value measured! More...
 
- Protected Member Functions inherited from Easyuino::DistanceMeter
float executeUpdateDistanceBlock (IN float soundSpeed)
 Execute a block distance measurement and calculates the distance based on the sound speed. More...
 
- Protected Attributes inherited from Easyuino::DistanceMeter
uint8_t _triggerPin
 Arduino pin used to trigger the echo wave emission.
 
uint8_t _echoPin
 Arduino pin that is set to LOW by when reflected echo wave arrives.
 
volatile bool _isEchoing
 Used to know if it is in a middle of a measurement.
 
volatile float _distance
 It contains a cached value of the last distance measured. More...
 
- Protected Attributes inherited from Easyuino::Device
bool _isInitialized
 Used to know if the device API is initialized and ready to receive requests.
 

Detailed Description

DistanceMeterAccurate offers an API to interact with an Ultrasonic Module to measure distances considering the current air temperature (due to the effect that the air temperature have in the sound speed in air).

It offers a the same of DistanceMeterNonBlock API plus a possibility to pass the updateDistance() and updateDistanceNonBlock() methods the current air temperature in order to minimize the distance calculation error. If you want know more about sound waves velocity dependency with temperature see https://en.wikipedia.org/wiki/Speed_of_sound.

See also
Limitation: This allows ONLY 2 instances of DistanceMeterAccurate per sketch!!
Limitation: The accuracy of the non-block method is much smaller because it uses interruption mechanism
Devices Supported: HC-SR03, HC-SR04, HC-SR05
Devices Tested: HC-SR04

Constructor & Destructor Documentation

◆ DistanceMeterAccurate() [1/2]

Easyuino::DistanceMeterAccurate::DistanceMeterAccurate ( IN uint8_t  triggerPin,
IN uint8_t  echoPin 
)

Constructor.

Parameters
triggerPinArduino pin connected to the trigger pin of the Ultrasonic Module
echoPinArduino pin connected to the echo pin of the Ultrasonic Module

◆ DistanceMeterAccurate() [2/2]

Easyuino::DistanceMeterAccurate::DistanceMeterAccurate ( IN uint8_t  triggerEchoPin)

Contructor used with Ultrasonic Modules that have only one pin for trigger and echo.

Parameters
triggerEchoPinArduino pin connected to the trigger&echo pin of the Ultrasonic Module

Member Function Documentation

◆ getDistanceCentimeters()

float Easyuino::DistanceMeterAccurate::getDistanceCentimeters ( )
virtual

Gets the last value that the API measured using the Ultrasonic Module.

Returns
distance (Centimeters) The most recent measurement the API have done

Reimplemented from Easyuino::DistanceMeter.

◆ updateDistance()

void Easyuino::DistanceMeterAccurate::updateDistance ( IN float  airTemperature = DEFAULT_AIR_TEMPERATURE_CELSIUS,
IN TemperatureScale  temperatureScale = CELSIUS 
)

Updates the distance of the Ultrasonic Module to the objects in a blocking way.

Parameters
airTemperatureAir temperatures to be used when calculating the distance
temperatureScaleThe temperature scale that is being provided

◆ updateDistanceNonBlock()

void Easyuino::DistanceMeterAccurate::updateDistanceNonBlock ( IN float  airTemperature = DEFAULT_AIR_TEMPERATURE_CELSIUS,
IN TemperatureScale  temperatureScale = CELSIUS 
)

Updates the distance of the Ultrasonic Module to the objects in a non-blocking way.

This means that the call to the method will return immediatly and in the "background" the distance measure will ocurr after a while. When the measurement is concluded and you call getDistanceCentimeters() or getDistanceInches() the new distance value will be returned. While the measurement is on going the distance will be from the last measurement.

Parameters
airTemperatureAir temperatures to be used when calculating the distance
temperatureScaleThe temperature scale that is being provided

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