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];
35 public int year, month, day;
36 public int hour, minute, second;
37 public double lat, lon;
38 public double pad_lat, pad_lon;
39 public boolean has_flight_data;
40 public boolean has_gps;
41 public boolean has_gps_sats;
42 public boolean has_gps_detail;
43 public boolean has_flight_adc;
44 public boolean has_battery;
45 public boolean has_rssi;
46 public boolean has_imu;
47 public boolean has_mag;
48 public boolean has_orient;
49 public int num_igniter;
51 double landed_time(AltosFlightSeries series) {
52 double landed_state_time = AltosLib.MISSING;
54 for (AltosTimeValue state : series.state_series) {
55 if (state.value == AltosLib.ao_flight_landed) {
56 landed_state_time = state.time;
61 if (landed_state_time == AltosLib.MISSING)
62 landed_state_time = series.height_series.get(series.height_series.size()-1).time;
64 double landed_height = AltosLib.MISSING;
65 for (AltosTimeValue height : series.height_series) {
66 if (height.time >= landed_state_time) {
67 landed_height = height.value;
72 if (landed_height == AltosLib.MISSING)
73 return AltosLib.MISSING;
77 double landed_time = AltosLib.MISSING;
79 for (AltosTimeValue height : series.height_series) {
80 if (height.value > landed_height + 10) {
83 if (above && Math.abs(height.value - landed_height) < 2) {
85 landed_time = height.time;
92 double boost_time(AltosFlightSeries series) {
93 double boost_time = AltosLib.MISSING;
94 double boost_state_time = AltosLib.MISSING;
96 for (AltosTimeValue state : series.state_series) {
97 if (state.value >= AltosLib.ao_flight_boost && state.value <= AltosLib.ao_flight_landed) {
98 boost_state_time = state.time;
102 for (AltosTimeValue accel : series.accel_series) {
104 boost_time = accel.time;
105 if (boost_state_time != AltosLib.MISSING && accel.time >= boost_state_time)
112 public AltosFlightStats(AltosFlightSeries series) throws InterruptedException, IOException {
113 AltosCalData cal_data = series.cal_data;
114 double boost_time = boost_time(series);
116 double landed_time = landed_time(series);
120 year = month = day = AltosLib.MISSING;
121 hour = minute = second = AltosLib.MISSING;
122 serial = flight = AltosLib.MISSING;
123 lat = lon = AltosLib.MISSING;
124 has_flight_data = false;
126 has_gps_sats = false;
127 has_flight_adc = false;
134 for (int s = AltosLib.ao_flight_startup; s <= AltosLib.ao_flight_landed; s++) {
137 if (s == AltosLib.ao_flight_boost)
138 state_start[s] = boost_time;
140 state_start[s] = series.state_series.time_of(s);
141 if (s == AltosLib.ao_flight_main)
142 state_end[s] = landed_time;
144 state_end[s] = series.state_series.time_of(s+1);
146 if (series.speed_series != null)
147 state_speed[s] = series.speed_series.average(state_start[s], state_end[s]);
149 if (series.accel_series != null)
150 state_accel[s] = series.accel_series.average(state_start[s], state_end[s]);
153 serial = cal_data.serial;
154 flight = cal_data.flight;
156 has_battery = series.battery_voltage_series != null;
157 has_flight_adc = series.main_voltage_series != null;
158 has_rssi = series.rssi_series != null;
159 has_flight_data = series.pressure_series != null;
161 AltosGPS gps = series.cal_data.gps_pad;
171 lat = pad_lat = gps.lat;
172 lon = pad_lon = gps.lon;
173 for (AltosGPSTimeValue gtv : series.gps_series) {
175 if (gps.locked && gps.nsat >= 4) {
183 max_height = AltosLib.MISSING;
184 if (series.height_series != null)
185 max_height = series.height_series.max();
186 max_speed = AltosLib.MISSING;
187 if (series.speed_series != null) {
188 max_speed = series.speed_series.max(state_start[AltosLib.ao_flight_boost], state_start[AltosLib.ao_flight_drogue]);
189 if (max_speed == AltosLib.MISSING)
190 max_speed = series.speed_series.max();
192 max_acceleration = AltosLib.MISSING;
193 if (series.accel_series != null) {
194 max_acceleration = series.accel_series.max(state_start[AltosLib.ao_flight_boost], state_start[AltosLib.ao_flight_drogue]);
195 if (max_acceleration == AltosLib.MISSING)
196 max_acceleration = series.accel_series.max();
198 max_gps_height = AltosLib.MISSING;
199 if (series.gps_height != null)
200 max_gps_height = series.gps_height.max();