Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
Public Member Functions | List of all members
EMASonicRanger Class Reference

SonicRanger with EMA-smoothed values. More...

#include <EMASonicRanger.h>

Inheritance diagram for EMASonicRanger:
Inheritance graph

Public Member Functions

 EMASonicRanger (const uint8_t trigPin, const uint8_t echoPin, const uint16_t periodMs=10, const float alpha=0.5, const uint16_t minimumRange=3)
 
void begin ()
 
void update ()
 
uint16_t getRange ()
 
- Public Member Functions inherited from SonicRanger
 SonicRanger (const uint8_t trigPin, const uint8_t echoPin)
 
void begin ()
 
uint16_t getRange ()
 
void setMaxRange (uint16_t cm)
 
void setTimeoutMs (uint16_t ms)
 

Additional Inherited Members

- Static Public Attributes inherited from SonicRanger
static const uint16_t DefaultMaxRangeCm = 200
 
static const uint8_t DefaultTimeoutMs = 15
 

Detailed Description

SonicRanger with EMA-smoothed values.

The update() function should be called frequently to sample the value from the ranger. The getRange() function is then used to fetch the moving average of values from the ranger.

Definition at line 13 of file EMASonicRanger.h.

Constructor & Destructor Documentation

◆ EMASonicRanger()

EMASonicRanger::EMASonicRanger ( const uint8_t  trigPin,
const uint8_t  echoPin,
const uint16_t  periodMs = 10,
const float  alpha = 0.5,
const uint16_t  minimumRange = 3 
)

Constructor.

Parameters
trigPinthe arduino pin conneced to the TRIG pin of the HC-SR04 device
echoPinthe arduino pin conneced to the ECHO pin of the HC-SR04 device
periodMsthe minimum delay between sampling (provided update() is called)
alphathe alpha value used in EMA calculation
minimumRangethe minium range to try to detect (discard samples below this range)

The reason for the mimimum range is that some units exhibit a problem where they randomly report skewing results.

Definition at line 5 of file EMASonicRanger.cpp.

Member Function Documentation

◆ begin()

void EMASonicRanger::begin ( )

Initialization

Typically called from setup() to intialize pins and so on.

Definition at line 13 of file EMASonicRanger.cpp.

Here is the call graph for this function:

◆ getRange()

uint16_t EMASonicRanger::getRange ( )

Fetch exponential moving average

Definition at line 33 of file EMASonicRanger.cpp.

◆ update()

void EMASonicRanger::update ( )

Update the ranger (get range from hardware)

NOTE: this function calls SonicRanger::getRange(), which may take significant time to execute - see SonicRanger::getRange documentation for details.

Definition at line 21 of file EMASonicRanger.cpp.

Here is the call graph for this function:

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