2 * Copyright © 2010 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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 * Track flight state from telemetry data stream
24 import altosui.AltosTelemetry;
25 import altosui.AltosGPS;
27 public class AltosState {
29 AltosTelemetry prev_data;
36 boolean ascent; /* going up? */
38 double ground_altitude;
49 double max_acceleration;
53 AltosGPSTracking gps_tracking;
65 AltosGreatCircle from_pad;
70 double speak_altitude;
75 return System.currentTimeMillis() / 1000.0;
78 public AltosState (AltosTelemetry cur, AltosTelemetry prev, int prev_npad) {
83 double accel_counts_per_mss;
89 tick_count = data.tick;
90 if (tick_count < prev_data.tick)
92 time_change = (tick_count - prev_data.tick) / 100.0;
94 report_time = aoview_time();
96 ground_altitude = AltosConvert.cc_pressure_to_altitude(data.ground_pres);
97 new_height = AltosConvert.cc_pressure_to_altitude(data.flight_pres) - ground_altitude;
98 height_change = new_height - height;
101 baro_speed = (baro_speed * 3 + (height_change / time_change)) / 4.0;
102 accel_counts_per_mss = ((data.accel_minus_g - data.accel_plus_g) / 2.0) / 9.80665;
103 acceleration = (data.ground_accel - data.flight_accel) / accel_counts_per_mss;
104 speed = data.flight_vel / (accel_counts_per_mss * 100.0);
105 temperature = AltosConvert.cc_thermometer_to_temperature(data.temp);
106 drogue_sense = AltosConvert.cc_ignitor_to_voltage(data.drogue);
107 main_sense = AltosConvert.cc_ignitor_to_voltage(data.main);
108 battery = AltosConvert.cc_battery_to_voltage(data.batt);
109 state = data.state();
110 if (state == AltosTelemetry.ao_flight_pad) {
111 if (data.gps.gps_locked && data.gps.nsat >= 4) {
113 pad_lat_total += data.gps.lat;
114 pad_lon_total += data.gps.lon;
115 pad_alt_total += data.gps.alt;
117 pad_lat = (pad_lat * 31 + data.gps.lat) / 32.0;
118 pad_lon = (pad_lon * 31 + data.gps.lon) / 32.0;
119 pad_alt = (pad_alt * 31 + data.gps.alt) / 32.0;
121 pad_lat = data.gps.lat;
122 pad_lon = data.gps.lon;
123 pad_alt = data.gps.alt;
127 ascent = (AltosTelemetry.ao_flight_boost <= state &&
128 state <= AltosTelemetry.ao_flight_coast);
130 /* Only look at accelerometer data on the way up */
131 if (ascent && acceleration > max_acceleration)
132 max_acceleration = acceleration;
133 if (ascent && speed > max_speed)
136 if (height > max_height)
138 gps.gps_locked = data.gps.gps_locked;
139 gps.gps_connected = data.gps.gps_connected;
140 if (data.gps.gps_locked) {
144 from_pad = new AltosGreatCircle(pad_lat, pad_lon, gps.lat, gps.lon);
147 gps_height = gps.alt - pad_alt;
153 public AltosState(AltosTelemetry cur) {
157 public AltosState (AltosTelemetry cur, AltosState prev) {
158 this(cur, prev.data, prev.npad);
161 gps_valid = prev.gps_valid;
163 if (gps_tracking == null)
164 gps_tracking = prev.gps_tracking;