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? */
40 double ground_altitude;
51 double max_acceleration;
65 AltosGreatCircle from_pad;
70 double speak_altitude;
75 return System.currentTimeMillis() / 1000.0;
78 void init (AltosTelemetry cur, AltosTelemetry prev, int prev_npad) {
82 double accel_counts_per_mss;
88 tick_count = data.tick;
89 if (tick_count < prev_data.tick)
91 time_change = (tick_count - prev_data.tick) / 100.0;
93 report_time = aoview_time();
95 ground_altitude = AltosConvert.cc_pressure_to_altitude(data.ground_pres);
96 new_height = AltosConvert.cc_pressure_to_altitude(data.flight_pres) - ground_altitude;
97 height_change = new_height - height;
100 baro_speed = (baro_speed * 3 + (height_change / time_change)) / 4.0;
101 accel_counts_per_mss = ((data.accel_minus_g - data.accel_plus_g) / 2.0) / 9.80665;
102 acceleration = (data.ground_accel - data.flight_accel) / accel_counts_per_mss;
103 speed = data.flight_vel / (accel_counts_per_mss * 100.0);
104 temperature = AltosConvert.cc_thermometer_to_temperature(data.temp);
105 drogue_sense = AltosConvert.cc_ignitor_to_voltage(data.drogue);
106 main_sense = AltosConvert.cc_ignitor_to_voltage(data.main);
107 battery = AltosConvert.cc_battery_to_voltage(data.batt);
108 state = data.state();
109 if (state == AltosTelemetry.ao_flight_pad) {
110 if (data.gps != null && data.gps.gps_locked && data.gps.nsat >= 4) {
112 pad_lat_total += data.gps.lat;
113 pad_lon_total += data.gps.lon;
114 pad_alt_total += data.gps.alt;
116 pad_lat = (pad_lat * 31 + data.gps.lat) / 32.0;
117 pad_lon = (pad_lon * 31 + data.gps.lon) / 32.0;
118 pad_alt = (pad_alt * 31 + data.gps.alt) / 32.0;
120 pad_lat = data.gps.lat;
121 pad_lon = data.gps.lon;
122 pad_alt = data.gps.alt;
126 ascent = (AltosTelemetry.ao_flight_boost <= state &&
127 state <= AltosTelemetry.ao_flight_coast);
129 /* Only look at accelerometer data on the way up */
130 if (ascent && acceleration > max_acceleration)
131 max_acceleration = acceleration;
132 if (ascent && speed > max_speed)
135 if (height > max_height)
137 if (data.gps != null) {
139 if (npad > 0 && gps.gps_locked)
140 from_pad = new AltosGreatCircle(pad_lat, pad_lon, gps.lat, gps.lon);
143 gps_height = gps.alt - pad_alt;
149 public AltosState(AltosTelemetry cur) {
153 public AltosState (AltosTelemetry cur, AltosState prev) {
157 init(cur, prev.data, prev.npad);