-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflight_stage.c
79 lines (73 loc) · 1.67 KB
/
flight_stage.c
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define FILE_NAME "data/2021-03-20-serial-4980-flight-0003.csv" // 2021-03-20-serial-4980-flight-0003.csv
float time;
float accel;
float alt;
float velo;
void step(FILE *fp) {
char row[1000];
char *pt;
int i=0;
fgets(row, 1000, fp);
pt = strtok (row,",");
for (i; pt != NULL; i++) {
float a = atof(pt);
switch (i) {
case 4:
time = a;
break;
case 7:
accel = a;
break;
case 9:
alt = a;
break;
case 11:
velo = a;
break;
}
pt = strtok (NULL, ",");
}
}
int main() {
// Setup
FILE *fp;
int apogee = 0;
char row[1000];
fp = fopen(FILE_NAME,"r");
fgets(row, 1000, fp);
// adding variables here so we don't keep looping over them
int waitTillAlt = 200;
float lastVelo = 0;
int a = 0;
int b = 0;
do
{
step(fp);
//TODO: are we at apogee?
// we are going to test when the velocity switches from positive to negative
if (alt < waitTillAlt) {
// do nothing
} else {
// do stuff
if (velo < 0) {
a++;
} else {
b++;
}
if (b > 10) {
a = 0;
b = 0;
}
if (a > 10) {
apogee = 1;
printf("%f", alt);
break;
}
}
printf("Time: %f \t\t\t Apogee? %d\n", time, apogee);
} while (feof(fp) != 1);
return 0;
}