WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
clockwerk::PersistenceTracker< T, N > Class Template Reference

Track the persistence of a threshold. More...

#include <PersistenceTracker.hpp>

Public Member Functions

 PersistenceTracker (uint8 required=N)
 ~PersistenceTracker ()
void pushValue (T value)
 Add a value to the persistence tracker.
bool greaterThan (T value)
 Checks if the required number of values tracked is greater than the input.
bool lessThan (T value)
 Checks if the required number of values tracked is less than the input.
bool inRange (T min, T max)
 Check if required values lie inside range between min and max.
bool outsideRange (T min, T max)
 Check if required values lie outside range between min and max.

Protected Attributes

CircularBuffer< T, N > _values
uint8 _required = 0

Detailed Description

template<typename T, uint8 N>
class clockwerk::PersistenceTracker< T, N >

Track the persistence of a threshold.

The Persistence Tracker is a simple class designed to make tracking values for which some persistence is required to trigger an event (i.e. we want to see pressure greater than some threshold twice before we deploy main chute, etc.)

The class takes two templated parameters, the type T and the number of values to track, N, at declaration. On construction, the class takes an optional input, which is the number of required values which must meet the "tested" threshold, defined by the functions herein. The default behavior is that all N values must meet the threshold.

The class comes with a number of functions, lessThan, greaterThan, etc. which are called for comparison and return simple booleans.

Simple example: PersistenceTracker<float, 3> tester; tester.pushValue(1.0); tester.pushValue(2.1); tester.pushValue(3.0); tester.greaterThan(0.0) --> Will return true tester.greaterThan(2.0) --> Will return false tester.pushValue(2.0) --> At this point 1.0 falls off tester.greaterThan(2.0) --> Will now return true

Example with reduced test: PersistenceTracker<float, 3> tester(2); --> Requires 2/3 values meet test tester.pushValue(1.0); tester.pushValue(2.1); tester.pushValue(3.0); tester.greaterThan(0.0) --> Will return true tester.greaterThan(2.0) --> Will return true in this case tester.pushValue(0.0) --> At this point 1.0 falls off tester.pushValue(0.0) --> At this point 2.1 falls off tester.greaterThan(2.0) --> Will now return false (1/3 greater than)

Constructor & Destructor Documentation

◆ PersistenceTracker()

template<typename T, uint8 N>
clockwerk::PersistenceTracker< T, N >::PersistenceTracker ( uint8 required = N)
inline

◆ ~PersistenceTracker()

template<typename T, uint8 N>
clockwerk::PersistenceTracker< T, N >::~PersistenceTracker ( )
inline

Member Function Documentation

◆ greaterThan()

template<typename T, uint8 N>
bool clockwerk::PersistenceTracker< T, N >::greaterThan ( T value)

Checks if the required number of values tracked is greater than the input.

Parameters
valueThe check point. Check is true greater than and is not inclusive of value
Returns
True if required values are greater than value. False otherwise

◆ inRange()

template<typename T, uint8 N>
bool clockwerk::PersistenceTracker< T, N >::inRange ( T min,
T max )

Check if required values lie inside range between min and max.

Parameters
minThe bottom check point. Check is not inclusive of value
maxThe top check point. Check is not inclusive of value
Returns
True if required values are in range. False otherwise

◆ lessThan()

template<typename T, uint8 N>
bool clockwerk::PersistenceTracker< T, N >::lessThan ( T value)

Checks if the required number of values tracked is less than the input.

Parameters
valueThe check point. Check is true less than and is not inclusive of value
Returns
True if required values are less than value. False otherwise

◆ outsideRange()

template<typename T, uint8 N>
bool clockwerk::PersistenceTracker< T, N >::outsideRange ( T min,
T max )

Check if required values lie outside range between min and max.

Parameters
minThe bottom check point. Check is not inclusive of value
maxThe top check point. Check is not inclusive of value
Returns
True if required values are outside range. False otherwise

◆ pushValue()

template<typename T, uint8 N>
void clockwerk::PersistenceTracker< T, N >::pushValue ( T value)
inline

Add a value to the persistence tracker.

Parameters
valueThe value to add

Member Data Documentation

◆ _required

template<typename T, uint8 N>
uint8 clockwerk::PersistenceTracker< T, N >::_required = 0
protected

◆ _values

template<typename T, uint8 N>
CircularBuffer<T, N> clockwerk::PersistenceTracker< T, N >::_values
protected

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