SAE Teensy ECU
IIT SAE Microcontroller programming
Loading...
Searching...
No Matches
Util.h File Reference

Various utility functions. More...

Go to the source code of this file.

Classes

class  AvgVar< T >
 Variable that automaticaly averages itself out when it is set to a value. More...
 
class  AvgVarRef< T >
 Variable that automaticaly averages itself out when it is called, that is, it only updates it's average when the variable is used. More...
 

Macros

#define Euler   exp(1.0)
 Euler's constant.
 
#define clamp(v, m, x)   min(max(v, m), x)
 Clamp function.
 

Functions

double EMAvg (double lastVal, double newVal, int memCount)
 Exponential moving average.
 
template<class T , class A , class B , class C , class D >
cMap (T x, A inMin, B inMax, C outMin, D outMax)
 Map a value from one range to another while clamping the value to boundaries.
 

Detailed Description

Various utility functions.

Author
IR
Version
0.1
Date
2021-10-13

Definition in file Util.h.

Macro Definition Documentation

◆ clamp

#define clamp (   v,
  m,
 
)    min(max(v, m), x)

Clamp function.

Definition at line 23 of file Util.h.

◆ Euler

#define Euler   exp(1.0)

Euler's constant.

Definition at line 18 of file Util.h.

Function Documentation

◆ cMap()

template<class T , class A , class B , class C , class D >
T cMap ( x,
inMin,
inMax,
outMin,
outMax 
)

Map a value from one range to another while clamping the value to boundaries.

Parameters
xThe value to be mapped
inMinThe minimum input value
inMaxThe maximum input value
outMinThe minimum output value
outMaxThe maximum output value
Returns
The mapped value for x

Definition at line 46 of file Util.h.

◆ EMAvg()

double EMAvg ( double  lastVal,
double  newVal,
int  memCount 
)

Exponential moving average.

Parameters
lastValThe last value that was returned
newValThe new value that should be added to the average
memCountThe total number of samples to be averaged
Returns
double The EMA of the last memCount values

Definition at line 14 of file Util.cpp.