Serial Wombat Arduino Library
|
SerialWombatAnalogInput, SerialWombatPulseTimer, SerialWombatResistanceInput and others inherit from this class. More...
#include <SerialWombatAbstractProcessedInput.h>
Public Types | |
enum | Period { PERIOD_1mS = 0, PERIOD_2mS = 1, PERIOD_4mS = 2, PERIOD_8mS = 3, PERIOD_16mS = 4, PERIOD_32mS = 5, PERIOD_64mS = 6, PERIOD_128mS = 7, PERIOD_256mS = 8, PERIOD_512mS = 9, PERIOD_1024mS = 10 } |
enum | OutputValue { RAW = 0, FIRST_ORDER_FILTERED = 1, AVERAGE = 2 } |
enum | Transform { NONE = 0, SCALE_RANGE = 1, LINEAR_MXB = 2 } |
Public Member Functions | |
SerialWombatAbstractProcessedInput (SerialWombatChip &sw) | |
Constructor for the SerialWombatAbstractScaledOutput Class. More... | |
int16_t | writeInverted (bool inverted) |
if enabled subtract the input value from 65535 before doing any other processing. More... | |
int16_t | writeFirstOrderFilteringConstant (uint16_t constant) |
Set a first order filtering constant to be applied to the signal Higher is heavier filtering. More... | |
int16_t | writeAveragingNumberOfSamples (uint16_t numberOfSamples) |
Set a number of samples to average for each update of the downstream signal. More... | |
int16_t | writeExcludeBelowAbove (uint16_t low, uint16_t high) |
Sets input value ranges which are discarded rather than processed. More... | |
int16_t | configureQueue (SerialWombatQueue *queue, Period period, bool queueHighByte=true, bool queueLowByte=true) |
Sets up the queueing feature for this pin mode. Queue must have been initialized prior to this queue. More... | |
int16_t | configureOutputValue (OutputValue outputValue) |
Configures whether the pin's public data value is averaged, filtered, or neither. More... | |
int16_t | writeTransformScaleRange (uint16_t min, uint16_t max) |
Scale incoming values to a range of 0 to 65535. More... | |
int16_t | writeTransformLinearMXB (int32_t m, int32_t b) |
Scale incoming values based on an mx+b linear equation. More... | |
int16_t | configureIntegrator (uint16_t negativeMaxIndex, uint16_t negativeMidIndex, uint16_t negativeDeadZone, uint16_t positiveDeadZone, uint16_t positiveMidIndex, uint16_t positiveMaxIndex, uint16_t midIncrement, uint16_t maxIncrement, uint16_t initialValue, uint8_t updateFrequencyMask=0) |
Sort incoming data into one of 5 ranges, and integrate based on linear interpolation in those ranges. More... | |
int16_t | writeProcessedInputEnable (bool enabled) |
Enables or disables all input processing functions If disabled, the raw input value is placed directly in the pin's 16 bit public data buffer. More... | |
uint16_t | readMinimum (bool resetAfterRead=false) |
Retreive the maximum public data output value since the last call with reset= true. More... | |
uint16_t | readMaximum (bool resetAfterRead=false) |
Retreive the minimum public data output value since the last call with reset= true. More... | |
uint16_t | readAverage () |
Retreive the last completed averaged value. More... | |
uint16_t | readFiltered () |
Retreive the filtered value. More... | |
virtual uint8_t | pin ()=0 |
Used for inheritance. More... | |
virtual uint8_t | swPinModeNumber ()=0 |
Used for ineheritance. More... | |
SerialWombatAnalogInput, SerialWombatPulseTimer, SerialWombatResistanceInput and others inherit from this class.
This class allows a common set of services to be applied to Serial Wombat inputs which inherit from it. These include SerialWombatAnalogInput, SerialWombatPulseTimer, SerialWombatResistanceInput and will include others in the future.
This class is only applicable to the Serial Wombat 18AB firmware.
This class allows various transformations and filters to be performed on incoming measurements within the Serial Wombat firmware using the Serial Wombat chip's cpu cycles. Since this class is processed every 1mS for each pin configured to an input class, it can do tasks like filtering or averaging much more quickly and consistently than could be achieved by sampling the value over I2C or UART and doing the computation on the host device. Minimum and Maximum measured values are also tracked for retreival by the host
Additionally, this class is capable of limiting input (for example any value below 10000 is processed as 10000, and any value above 62331 is processed as 62331), scaling input (e.g. an expected input range of 3000 to 7000 is scaled linearly to the full Serial Wombat Range of 0 to 65535), mx+b linear transformations, exclusion of outlier data (e.g. any value over 50000 is ignored, and the previous valid measurement is substituted in its place).
Inputs can be inverted (scaled from 0-65535 to 65535-0 by substracting the raw value from 65535). This is useful for reversing the direction of things like analog measured potentiometers.
The final output of the SerialWombatAbstractProcessedInput operations can be queued in a User Memory Area queue on a periodic basis. This allows synchronsous sampling and storage of input data for retreival and processing by the host. This allows waveforms to be stored and processed. Sampling period is an enumerated type ranging from 1mS to 1024mS in power of 2 intervals
Data processing happens in the following order each 1mS for any enabled feature:
To use this class first configure the pin to its mode using the normal begin() call for that pin mode (the derived class). Then call any configuratioon commands ( writeInverted, writeTransformLinearMXB, etc) then call writeProcessedInputEnable(true) to enable processing.
|
inline |
Constructor for the SerialWombatAbstractScaledOutput Class.
sw | A reference to a previously declared SerialWombatPin to which the output is connected. |
|
inline |
Sort incoming data into one of 5 ranges, and integrate based on linear interpolation in those ranges.
This funciton is designed to allow a binary or analog input to proportionally increment or decrement a value, such as allowing a joystick to control the position of a servo by changing it over time proportional to the position of the stick.
negativeMaxIndex | Values more negative than this will decrement the output value by maxIncrement per sample. |
negativeMidIndex | Values more negative than this will be linearly scaled with negativeMaxIndex, maxIncrement and midIncrement. |
negativeDeadZone | Values between negativeDeadZone and positiveDeadZone will not affect the output value. Values between negativeDeadZone and negativeMidIndex will be scaled linearly based on 0 and midIncrement |
positiveDeadZone | Values between negativeDeadZone and positiveDeadZone will not affect the output value. Values between positiveDeadZone and positiveMidIndex will be scaled linearly based on 0 and midIncrement |
positiveMidIndex | Values more positive than this will nearly increment the value scaled with negativeMaxIndex, maxIncrement and midIncrement. |
positiveMaxIndex | Values more positive than this will increment the output value by maxIncrement per sample. |
midIncrement | forms a line for scaling between 0 and midIncrement for values between negative or positive deadzone and negative or positive MidIndex |
maxIncrement | forms a line for scaling between midIncrement and maxIncrement for values between negative or positive midIncrement and negative or positive maxIncrement |
initialValue | intial integrator value, |
updateFrequencyMask | When the frame counter and this mask anded = 0, perform integration. For instance 0 = every mS, 0x0F = every 16 mS, 0x1F = every 2mS |
|
inline |
Configures whether the pin's public data value is averaged, filtered, or neither.
outputValue | An enumerated type for filtered, averaged, or raw |
|
inline |
Sets up the queueing feature for this pin mode. Queue must have been initialized prior to this queue.
Allows periodic storage of the public data value into a previously initialized queue in the user memory buffer. The high byte, the low byte, or both can be stored into the queue. This is useful to increase the number of Samples that can be stored and transferred if 8 bit resolution is sufficent.
Note that the sampling period is an enumerated type, not a numerical value
queue | The index into the User Memory Buffer where the queue is located |
period | The sampling period. See the enumerated type for values |
queueHighByte | Whether to put the high byte of the sample into the queue |
queueLowByte | Whether to put the low byte of the sample into the queue |
|
pure virtual |
Used for inheritance.
Implemented in SerialWombatAnalogInput_18AB, SerialWombatPulseTimer_18AB, SerialWombat18CapTouch, SerialWombatQuadEnc_18AB, SerialWombatResistanceInput, SerialWombatUltrasonicDistanceSensor, SerialWombatHSCounter, and SerialWombatProcessedInputPin.
|
inline |
Retreive the last completed averaged value.
|
inline |
Retreive the filtered value.
A 16 bit value representing the First Order IIR filtered result of the input
|
inline |
Retreive the minimum public data output value since the last call with reset= true.
resetAfterRead | If True, minimum value is set to 65535 after read so that subsequent values become minimum. |
|
inline |
Retreive the maximum public data output value since the last call with reset= true.
resetAfterRead | If True, maximum value is set to 0 after read so that subsequent values become maximum. |
|
pure virtual |
Used for ineheritance.
Implemented in SerialWombatAnalogInput_18AB, SerialWombatPulseTimer_18AB, SerialWombat18CapTouch, SerialWombatQuadEnc_18AB, SerialWombatResistanceInput, SerialWombatUltrasonicDistanceSensor, SerialWombatHSCounter, and SerialWombatProcessedInputPin.
|
inline |
Set a number of samples to average for each update of the downstream signal.
The average is a typical average, not a moving average so the more samples comprise the averaged value the less often the downstream value will update.
A | number of samples to include in each output average. Samples are typically taken each mS, although some modes such as SerialWombatUltrasonicDistanceSensor sample at other periods. |
|
inline |
Sets input value ranges which are discarded rather than processed.
Input values that are below the low parameter or above the high parameter are not processed. The last valid input value is repeated instead. This feature is designed to reject outlier values, not to act as a high or low limiting clamp
low | input values below this value will not be processed |
high | input values above this value will not be processsed. |
|
inline |
Set a first order filtering constant to be applied to the signal Higher is heavier filtering.
The filter samples at 1kHz. For a good explanation of 1st order IIR filter calculations, see: https://www.monocilindro.com/2017/04/08/how-to-implement-a-1st-order-iir-filter-in-5-minutes/
Some filter cut-off (3dB down) frequency and constant values:
Filtering adds lag. The higher the filter constant value, the longer it takes for the filter to settle when given a steady input.
constant | The first order filter constant from 0 to 65535. Larger constant is heavier filtering |
|
inline |
if enabled subtract the input value from 65535 before doing any other processing.
inverted | False - input value isn't changed. True- input value is subtracted from 65535 |
|
inline |
Enables or disables all input processing functions If disabled, the raw input value is placed directly in the pin's 16 bit public data buffer.
|
inline |
Scale incoming values based on an mx+b linear equation.
Allows scaling of an input by multiplying by m, dividing by 256, and adding b. The m value can be thought of as a fraction with a divisor of 256. This allows the scaling value to make the input bigger or smaller. After the multiplication, division and addition the result is limited to the range of 0 to 65535. Calling this feature disables writeTransformScaleRange until the pin is reinitialized with begin().
m | A value between -16777215 and +1677215 representing the number of 256th by which to multiply the input |
b | A value between -65535 and 65535 to add to the result of the multiplication |
|
inline |
Scale incoming values to a range of 0 to 65535.
This function allows configuration of an input scaling range that maps to 0-65535.
For example, if a sensor returns a range from 2000 to 5000, setting the minimum to 2000 and maximum to 5000 will cause values below 2000 to be 0, values above 5000 to be 65535, and values in between will be scaled accordingly. This allows a sensor or other input device to scale to the Serial Wombat philosophy of using a 16 bit resolution number to represent the the possible range of values
Calling this feature disables writeTransformLinearMXB until the pin is reinitialized with begin().
min | The minimum value of the input range. Input values less than or equal to that will be scaled to 0 |
max | The maximum value of the input range. Input values greater or equal to that will be scaled to 65535 |