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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
/*
* Copyright © 2011 Keith Packard <keithp@keithp.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
package org.altusmetrum.micropeak;
import java.io.*;
import org.altusmetrum.altoslib_8.*;
import org.altusmetrum.altosuilib_8.*;
public class MicroStats {
double coast_height;
double coast_time;
double apogee_height;
double apogee_time;
double landed_height;
double landed_time;
double max_speed;
double max_accel;
MicroData data;
void find_landing() {
landed_height = 0;
for (MicroDataPoint point : data.points()) {
landed_height = point.height;
landed_time = point.time;
}
boolean above = false;
for (MicroDataPoint point : data.points()) {
if (point.height > landed_height + 10) {
above = true;
} else {
if (above && point.height < landed_height + 2) {
above = false;
landed_time = point.time;
}
}
}
}
void find_apogee() {
apogee_height = data.apogee_height();
double searched_apogee = 0;
apogee_time = 0;
/* This just finds the apogee time -- we've recorded the
* peak altitude separately in eeprom, and that could
* have occurred after the eeprom was full.
*/
for (MicroDataPoint point : data.points()) {
if (point.height > searched_apogee) {
searched_apogee = point.height;
apogee_time = point.time;
}
}
}
void find_coast() {
coast_height = 0;
coast_time = 0;
for (MicroDataPoint point : data.points()) {
if (point.accel < -9.8)
break;
coast_time = point.time;
coast_height = point.height;
}
}
void find_max_speed() {
max_speed = 0;
for (MicroDataPoint point : data.points()) {
if (point.time > apogee_time)
break;
if (point.speed > max_speed)
max_speed = point.speed;
}
}
void find_max_accel() {
max_accel = 0;
for (MicroDataPoint point : data.points()) {
if (point.time > apogee_time)
break;
if (point.accel > max_accel)
max_accel = point.accel;
}
}
double boost_duration() {
return coast_time;
}
double boost_height() {
return coast_height;
}
double boost_speed() {
return coast_height / coast_time;
}
double boost_accel() {
return boost_speed() / boost_duration();
}
double coast_duration() {
return apogee_time - coast_time;
}
double coast_height() {
return apogee_height - coast_height;
}
double coast_speed() {
return coast_height() / coast_duration();
}
double coast_accel() {
return coast_speed() / coast_duration();
}
double descent_duration() {
return landed_time - apogee_time;
}
double descent_height() {
return apogee_height - landed_height;
}
double descent_speed() {
return descent_height() / descent_duration();
}
public static final int state_startup = -1;
public static final int state_pad = 0;
public static final int state_boost = 1;
public static final int state_coast = 2;
public static final int state_descent = 3;
public static final int state_landed = 4;
static final String state_names[] = {
"pad",
"boost",
"coast",
"descent",
"landed"
};
public int state(double t) {
if (t >= landed_time)
return state_landed;
if (t >= apogee_time)
return state_descent;
if (t >= coast_time)
return state_coast;
if (t >= 0)
return state_boost;
return state_pad;
}
public static String state_name(int state) {
if (state < 0 || state > state_landed)
return "unknown";
return state_names[state];
}
public String state_name(double t) {
return state_name(state(t));
}
public MicroStats(MicroData data) {
this.data = data;
find_coast();
find_apogee();
find_landing();
find_max_speed();
find_max_accel();
}
public MicroStats() {
this(new MicroData());
}
}
|