uncrustify ArduPlane/climb_rate.pde
This commit is contained in:
parent
3938011f39
commit
3f54fb67d1
@ -3,58 +3,58 @@
|
|||||||
#if 0 // currently unused
|
#if 0 // currently unused
|
||||||
|
|
||||||
struct DataPoint {
|
struct DataPoint {
|
||||||
unsigned long x;
|
unsigned long x;
|
||||||
long y;
|
long y;
|
||||||
};
|
};
|
||||||
|
|
||||||
DataPoint history[ALTITUDE_HISTORY_LENGTH]; // Collection of (x,y) points to regress a rate of change from
|
DataPoint history[ALTITUDE_HISTORY_LENGTH]; // Collection of (x,y) points to regress a rate of change from
|
||||||
unsigned char hindex; // Index in history for the current data point
|
unsigned char hindex; // Index in history for the current data point
|
||||||
|
|
||||||
unsigned long xoffset;
|
unsigned long xoffset;
|
||||||
unsigned char n;
|
unsigned char n;
|
||||||
|
|
||||||
// Intermediate variables for regression calculation
|
// Intermediate variables for regression calculation
|
||||||
long xi;
|
long xi;
|
||||||
long yi;
|
long yi;
|
||||||
long xiyi;
|
long xiyi;
|
||||||
unsigned long xi2;
|
unsigned long xi2;
|
||||||
|
|
||||||
void add_altitude_data(unsigned long xl, long y)
|
void add_altitude_data(unsigned long xl, long y)
|
||||||
{
|
{
|
||||||
//Reset the regression if our X variable overflowed
|
//Reset the regression if our X variable overflowed
|
||||||
if (xl < xoffset)
|
if (xl < xoffset)
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
//To allow calculation of sum(xi*yi), make sure X hasn't exceeded 2^32/2^15/length
|
//To allow calculation of sum(xi*yi), make sure X hasn't exceeded 2^32/2^15/length
|
||||||
if (xl - xoffset > 131072/ALTITUDE_HISTORY_LENGTH)
|
if (xl - xoffset > 131072/ALTITUDE_HISTORY_LENGTH)
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
if (n == ALTITUDE_HISTORY_LENGTH) {
|
if (n == ALTITUDE_HISTORY_LENGTH) {
|
||||||
xi -= history[hindex].x;
|
xi -= history[hindex].x;
|
||||||
yi -= history[hindex].y;
|
yi -= history[hindex].y;
|
||||||
xiyi -= (long)history[hindex].x * history[hindex].y;
|
xiyi -= (long)history[hindex].x * history[hindex].y;
|
||||||
xi2 -= history[hindex].x * history[hindex].x;
|
xi2 -= history[hindex].x * history[hindex].x;
|
||||||
} else {
|
} else {
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
xoffset = xl;
|
xoffset = xl;
|
||||||
xi = 0;
|
xi = 0;
|
||||||
yi = 0;
|
yi = 0;
|
||||||
xiyi = 0;
|
xiyi = 0;
|
||||||
xi2 = 0;
|
xi2 = 0;
|
||||||
}
|
}
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
history[hindex].x = xl - xoffset;
|
history[hindex].x = xl - xoffset;
|
||||||
history[hindex].y = y;
|
history[hindex].y = y;
|
||||||
|
|
||||||
xi += history[hindex].x;
|
xi += history[hindex].x;
|
||||||
yi += history[hindex].y;
|
yi += history[hindex].y;
|
||||||
xiyi += (long)history[hindex].x * history[hindex].y;
|
xiyi += (long)history[hindex].x * history[hindex].y;
|
||||||
xi2 += history[hindex].x * history[hindex].x;
|
xi2 += history[hindex].x * history[hindex].x;
|
||||||
|
|
||||||
if (++hindex >= ALTITUDE_HISTORY_LENGTH)
|
if (++hindex >= ALTITUDE_HISTORY_LENGTH)
|
||||||
hindex = 0;
|
hindex = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user