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 int[] state_count = new int[AltosLib.ao_flight_invalid + 1];
31 public double[] state_start = new double[AltosLib.ao_flight_invalid + 1];
32 public double[] state_end = new double[AltosLib.ao_flight_invalid + 1];
33 public String product;
34 public String firmware_version;
37 public int year, month, day;
38 public int hour, minute, second;
39 public double boost_time;
40 public double landed_time;
41 public double lat, lon;
42 public double pad_lat, pad_lon;
43 public boolean has_flight_data;
44 public boolean has_gps;
45 public boolean has_gps_sats;
46 public boolean has_gps_detail;
47 public boolean has_flight_adc;
48 public boolean has_battery;
49 public boolean has_rssi;
50 public boolean has_imu;
51 public boolean has_mag;
52 public boolean has_orient;
53 public int num_igniter;
55 double landed_time(AltosFlightSeries series) {
56 double landed_state_time = AltosLib.MISSING;
58 if (series.state_series != null) {
59 for (AltosTimeValue state : series.state_series) {
60 if (state.value == AltosLib.ao_flight_landed) {
61 landed_state_time = state.time;
67 if (landed_state_time == AltosLib.MISSING && series.height_series != null)
68 landed_state_time = series.height_series.get(series.height_series.size()-1).time;
70 double landed_height = AltosLib.MISSING;
72 if (series.height_series != null) {
73 for (AltosTimeValue height : series.height_series) {
74 landed_height = height.value;
75 if (height.time >= landed_state_time)
80 if (landed_height == AltosLib.MISSING)
81 return AltosLib.MISSING;
85 double landed_time = AltosLib.MISSING;
87 if (series.height_series != null) {
88 for (AltosTimeValue height : series.height_series) {
89 if (height.value > landed_height + 10) {
92 if (above && Math.abs(height.value - landed_height) < 2) {
94 landed_time = height.time;
100 if (landed_time == AltosLib.MISSING)
101 landed_time = landed_state_time;
105 double boost_time(AltosFlightSeries series) {
106 double boost_time = AltosLib.MISSING;
107 double boost_state_time = AltosLib.MISSING;
109 if (series.state_series != null) {
110 for (AltosTimeValue state : series.state_series) {
111 if (state.value >= AltosLib.ao_flight_boost && state.value <= AltosLib.ao_flight_landed) {
112 boost_state_time = state.time;
117 if (series.accel_series != null) {
118 for (AltosTimeValue accel : series.accel_series) {
120 boost_time = accel.time;
121 if (boost_state_time != AltosLib.MISSING && accel.time >= boost_state_time)
125 if (boost_time == AltosLib.MISSING)
126 boost_time = boost_state_time;
131 public AltosFlightStats(AltosFlightSeries series) {
132 AltosCalData cal_data = series.cal_data;
136 boost_time = boost_time(series);
137 landed_time = landed_time(series);
139 if (series.state_series != null){
140 boolean fixed_boost = false;
141 boolean fixed_landed = false;
142 for (AltosTimeValue state : series.state_series) {
143 if ((int) state.value == AltosLib.ao_flight_boost)
144 if (boost_time != AltosLib.MISSING) {
145 state.time = boost_time;
148 if ((int) state.value == AltosLib.ao_flight_landed)
149 if (landed_time != AltosLib.MISSING) {
150 state.time = landed_time;
154 if (!fixed_boost && boost_time != AltosLib.MISSING)
155 series.state_series.add(boost_time, AltosLib.ao_flight_boost);
156 if (!fixed_landed && landed_time != AltosLib.MISSING)
157 series.state_series.add(landed_time, AltosLib.ao_flight_landed);
160 System.out.printf("boost time %g landed %g\n", boost_time, landed_time);
162 year = month = day = AltosLib.MISSING;
163 hour = minute = second = AltosLib.MISSING;
164 serial = flight = AltosLib.MISSING;
165 lat = lon = AltosLib.MISSING;
166 has_flight_data = false;
168 has_gps_sats = false;
169 has_flight_adc = false;
176 for (int s = AltosLib.ao_flight_startup; s <= AltosLib.ao_flight_landed; s++) {
179 if (s == AltosLib.ao_flight_boost)
180 state_start[s] = boost_time;
181 else if (series.state_series != null)
182 state_start[s] = series.state_series.time_of(s);
184 state_start[s] = AltosLib.MISSING;
186 if (s == AltosLib.ao_flight_main)
187 state_end[s] = landed_time;
188 else if (series.state_series != null)
189 state_end[s] = series.state_series.time_of(s+1);
191 state_end[s] = AltosLib.MISSING;
193 System.out.printf("state %s start %g end %g\n", AltosLib.state_name(s), state_start[s], state_end[s]);
195 if (state_end[s] > landed_time)
196 state_end[s] = landed_time;
198 if (series.speed_series != null)
199 state_speed[s] = series.speed_series.average(state_start[s], state_end[s]);
201 if (series.accel_series != null)
202 state_accel[s] = series.accel_series.average(state_start[s], state_end[s]);
205 product = cal_data.product;
206 firmware_version = cal_data.firmware_version;
207 serial = cal_data.serial;
208 flight = cal_data.flight;
210 has_battery = series.battery_voltage_series != null;
211 has_flight_adc = series.main_voltage_series != null;
212 has_rssi = series.rssi_series != null;
213 has_flight_data = series.pressure_series != null;
215 AltosGPS gps = series.cal_data.gps_pad;
225 lat = pad_lat = gps.lat;
226 lon = pad_lon = gps.lon;
227 for (AltosGPSTimeValue gtv : series.gps_series) {
229 if (gps.locked && gps.nsat >= 4) {
237 max_height = AltosLib.MISSING;
238 if (series.height_series != null)
239 max_height = series.height_series.max().value;
240 max_speed = AltosLib.MISSING;
241 if (series.speed_series != null) {
242 AltosTimeValue tv = series.speed_series.max(state_start[AltosLib.ao_flight_boost], state_start[AltosLib.ao_flight_drogue]);
244 tv = series.speed_series.max();
246 max_speed = tv.value;
248 max_acceleration = AltosLib.MISSING;
249 if (series.accel_series != null) {
250 AltosTimeValue tv = series.accel_series.max(state_start[AltosLib.ao_flight_boost], state_start[AltosLib.ao_flight_drogue]);
252 tv = series.accel_series.max();
254 max_acceleration = tv.value;
256 max_gps_height = AltosLib.MISSING;
257 if (series.gps_height != null) {
258 AltosTimeValue tv = series.gps_height.max();
260 max_gps_height = tv.value;