2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altoslib_11;
23 public class AltosFlightStats {
24 public double max_height;
25 public double max_gps_height;
26 public double max_speed;
27 public double max_acceleration;
28 public double[] state_speed = new double[AltosLib.ao_flight_invalid + 1];
29 public double[] state_accel = new double[AltosLib.ao_flight_invalid + 1];
30 public double[] state_start = new double[AltosLib.ao_flight_invalid + 1];
31 public double[] state_end = new double[AltosLib.ao_flight_invalid + 1];
32 public String product;
33 public String firmware_version;
36 public int year, month, day;
37 public int hour, minute, second;
38 public double boost_time;
39 public double landed_time;
40 public double lat, lon;
41 public double pad_lat, pad_lon;
42 public boolean has_flight_data;
43 public boolean has_gps;
44 public boolean has_gps_sats;
45 public boolean has_gps_detail;
46 public boolean has_flight_adc;
47 public boolean has_battery;
48 public boolean has_rssi;
49 public boolean has_imu;
50 public boolean has_mag;
51 public boolean has_orient;
52 public int num_igniter;
54 double landed_time(AltosFlightSeries series) {
55 double landed_state_time = AltosLib.MISSING;
57 if (series.state_series != null) {
58 for (AltosTimeValue state : series.state_series) {
59 if (state.value == AltosLib.ao_flight_landed) {
60 landed_state_time = state.time;
66 if (landed_state_time == AltosLib.MISSING && series.height_series != null)
67 landed_state_time = series.height_series.get(series.height_series.size()-1).time;
69 double landed_height = AltosLib.MISSING;
71 if (series.height_series != null) {
72 for (AltosTimeValue height : series.height_series) {
73 landed_height = height.value;
74 if (height.time >= landed_state_time)
79 if (landed_height == AltosLib.MISSING)
80 return AltosLib.MISSING;
84 double landed_time = AltosLib.MISSING;
86 if (series.height_series != null) {
87 for (AltosTimeValue height : series.height_series) {
88 if (height.value > landed_height + 10) {
91 if (above && Math.abs(height.value - landed_height) < 2) {
93 landed_time = height.time;
99 if (landed_time == AltosLib.MISSING)
100 landed_time = landed_state_time;
104 double boost_time(AltosFlightSeries series) {
105 double boost_time = AltosLib.MISSING;
106 double boost_state_time = AltosLib.MISSING;
108 if (series.state_series != null) {
109 for (AltosTimeValue state : series.state_series) {
110 if (state.value >= AltosLib.ao_flight_boost && state.value <= AltosLib.ao_flight_landed) {
111 boost_state_time = state.time;
116 if (series.accel_series != null) {
117 for (AltosTimeValue accel : series.accel_series) {
119 boost_time = accel.time;
120 if (boost_state_time != AltosLib.MISSING && accel.time >= boost_state_time)
124 if (boost_time == AltosLib.MISSING)
125 boost_time = boost_state_time;
130 public AltosFlightStats(AltosFlightSeries series) {
131 AltosCalData cal_data = series.cal_data;
135 boost_time = boost_time(series);
136 landed_time = landed_time(series);
138 if (series.state_series != null){
139 boolean fixed_boost = false;
140 boolean fixed_landed = false;
141 for (AltosTimeValue state : series.state_series) {
142 if ((int) state.value == AltosLib.ao_flight_boost)
143 if (boost_time != AltosLib.MISSING) {
144 state.time = boost_time;
147 if ((int) state.value == AltosLib.ao_flight_landed)
148 if (landed_time != AltosLib.MISSING) {
149 state.time = landed_time;
155 year = month = day = AltosLib.MISSING;
156 hour = minute = second = AltosLib.MISSING;
157 serial = flight = AltosLib.MISSING;
158 lat = lon = AltosLib.MISSING;
159 has_flight_data = false;
161 has_gps_sats = false;
162 has_flight_adc = false;
169 for (int s = 0; s < AltosLib.ao_flight_invalid + 1; s++)
170 state_speed[s] = state_accel[s] = state_start[s] = state_end[s] = AltosLib.MISSING;
172 if (series.state_series != null) {
173 for (AltosTimeValue state : series.state_series) {
174 int s = (int) state.value;
176 if (s < AltosLib.ao_flight_startup && AltosLib.ao_flight_landed < s)
179 if (s == AltosLib.ao_flight_boost)
180 state_start[s] = boost_time;
182 state_start[s] = series.state_series.time_of(s);
184 if (s == AltosLib.ao_flight_main)
185 state_end[s] = landed_time;
187 state_end[s] = series.state_series.time_of(s+1);
189 if (series.speed_series != null)
190 state_speed[s] = series.speed_series.average(state_start[s], state_end[s]);
192 if (series.accel_series != null)
193 state_accel[s] = series.accel_series.average(state_start[s], state_end[s]);
197 product = cal_data.product;
198 firmware_version = cal_data.firmware_version;
199 serial = cal_data.serial;
200 flight = cal_data.flight;
202 has_battery = series.battery_voltage_series != null;
203 has_flight_adc = series.main_voltage_series != null;
204 has_rssi = series.rssi_series != null;
205 has_flight_data = series.pressure_series != null;
207 AltosGPS gps = series.cal_data.gps_pad;
217 lat = pad_lat = gps.lat;
218 lon = pad_lon = gps.lon;
219 for (AltosGPSTimeValue gtv : series.gps_series) {
221 if (gps.locked && gps.nsat >= 4) {
229 max_height = AltosLib.MISSING;
230 if (series.height_series != null)
231 max_height = series.height_series.max().value;
232 max_speed = AltosLib.MISSING;
233 if (series.speed_series != null) {
234 AltosTimeValue tv = series.speed_series.max(state_start[AltosLib.ao_flight_boost], state_start[AltosLib.ao_flight_drogue]);
236 tv = series.speed_series.max();
238 max_speed = tv.value;
240 max_acceleration = AltosLib.MISSING;
241 if (series.accel_series != null) {
242 AltosTimeValue tv = series.accel_series.max(state_start[AltosLib.ao_flight_boost], state_start[AltosLib.ao_flight_drogue]);
244 tv = series.accel_series.max();
246 max_acceleration = tv.value;
248 max_gps_height = AltosLib.MISSING;
249 if (series.gps_height != null) {
250 AltosTimeValue tv = series.gps_height.max();
252 max_gps_height = tv.value;