1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 12:55:19 +03:00

Relocate common code which can be used by drivers and by main into

'common'.  Cleanup includes.  Fix FY90Q target compilation.
This commit is contained in:
Dominic Clifton 2014-04-17 23:50:13 +01:00
parent d4ebd8a748
commit f06c8bb99b
19 changed files with 41 additions and 36 deletions

49
src/common/maths.c Normal file
View file

@ -0,0 +1,49 @@
#include <stdint.h>
#include <math.h>
#include "maths.h"
int constrain(int amt, int low, int high)
{
if (amt < low)
return low;
else if (amt > high)
return high;
else
return amt;
}
void devClear(stdev_t *dev)
{
dev->m_n = 0;
}
void devPush(stdev_t *dev, float x)
{
dev->m_n++;
if (dev->m_n == 1) {
dev->m_oldM = dev->m_newM = x;
dev->m_oldS = 0.0f;
} else {
dev->m_newM = dev->m_oldM + (x - dev->m_oldM) / dev->m_n;
dev->m_newS = dev->m_oldS + (x - dev->m_oldM) * (x - dev->m_newM);
dev->m_oldM = dev->m_newM;
dev->m_oldS = dev->m_newS;
}
}
float devVariance(stdev_t *dev)
{
return ((dev->m_n > 1) ? dev->m_newS / (dev->m_n - 1) : 0.0f);
}
float devStandardDeviation(stdev_t *dev)
{
return sqrtf(devVariance(dev));
}
float degreesToRadians(int16_t degrees)
{
return degrees * RAD;
}