-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkheight.h
90 lines (86 loc) · 1.45 KB
/
checkheight.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#define MOVINGAVG 5
#define ERR_DIFF 1
#define FRACTION 0.6
float arr[MOVINGAVG]={0,0,0,0,0}; // add more zeros here if u are increasing MOVINGAVG
/*
void updateAlt(float alt )
{
for(int i=0;i<MOVINGAVG-1;i++){
arr[i] = arr[i+1];
}
arr[MOVINGAVG-1] = alt;
}
float getFiltered(){
int mean=0;
for(int i=0; i<MOVINGAVG; i++){
mean+= arr[i];
}
mean = mean/MOVINGAVG;
return ( mean );
}
*/
#define ALPHA 0.9
float y = 0;
void updateAlt(float alt )
{
y = y * ( 1 - ALPHA ) + ALPHA * alt ;
for(int i=0;i<MOVINGAVG-1;i++){
arr[i] = arr[i+1];
}
arr[MOVINGAVG-1] = alt;
}
float getFiltered(){
return(y);
}
bool checkAlt(float lessthanAlti) {
float mean = getFiltered();
if( mean > lessthanAlti ){
return false;
}
else{
return true;
}
}
bool movingUp(){
int j = 0;
for(int i=1;i<MOVINGAVG ;i++){
if ( arr[i] > arr[i-1] ){
j++;
}
}
if ( j > FRACTION * MOVINGAVG ){
return true;
}
else {
return false;
}
}
bool movingDown(){
int j = 0;
for(int i=1;i<MOVINGAVG ;i++){
if ( arr[i] < arr[i-1] ){
j++;
}
}
if ( j > FRACTION*MOVINGAVG ){
return true;
}
else {
return false;
}
}
bool notMoving (){
int j = 0;
float filtered_alt = getFiltered();
for(int i=0;i<MOVINGAVG ;i++){
if ( arr[i] < filtered_alt + ERR_DIFF && arr[i] > filtered_alt - ERR_DIFF ){
j++;
}
}
if ( j == MOVINGAVG-1 ){
return true;
}
else {
return false;
}
}