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.
22 import java.util.HashMap;
25 public class AltosRecord implements Comparable <AltosRecord> {
26 final static int MISSING = 0x7fffffff;
28 static final int seen_flight = 1;
29 static final int seen_sensor = 2;
30 static final int seen_temp_volt = 4;
31 static final int seen_deploy = 8;
32 static final int seen_gps_time = 16;
33 static final int seen_gps_lat = 32;
34 static final int seen_gps_lon = 64;
35 static final int seen_companion = 128;
73 double time; /* seconds since boost */
81 String firmware_version;
83 AltosRecordCompanion companion;
85 * Values for our MP3H6115A pressure sensor
87 * From the data sheet:
89 * Pressure range: 15-115 kPa
90 * Voltage at 115kPa: 2.82
91 * Output scale: 27mV/kPa
94 * 27 mV/kPa * 2047 / 3300 counts/mV = 16.75 counts/kPa
95 * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa
98 static final double counts_per_kPa = 27 * 2047 / 3300;
99 static final double counts_at_101_3kPa = 1674.0;
102 barometer_to_pressure(double count)
104 return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0;
107 public double raw_pressure() {
110 return barometer_to_pressure(pres);
113 public double filtered_pressure() {
114 if (flight_pres == MISSING)
116 return barometer_to_pressure(flight_pres);
119 public double ground_pressure() {
120 if (ground_pres == MISSING)
122 return barometer_to_pressure(ground_pres);
125 public double raw_altitude() {
126 double p = raw_pressure();
129 return AltosConvert.pressure_to_altitude(p);
132 public double ground_altitude() {
133 double p = ground_pressure();
136 return AltosConvert.pressure_to_altitude(p);
139 public double filtered_altitude() {
140 if (height != MISSING && ground_pres != MISSING)
141 return height + ground_altitude();
143 double p = filtered_pressure();
146 return AltosConvert.pressure_to_altitude(p);
149 public double filtered_height() {
150 if (height != MISSING)
153 double f = filtered_altitude();
154 double g = ground_altitude();
155 if (f == MISSING || g == MISSING)
160 public double raw_height() {
161 double r = raw_altitude();
162 double g = ground_altitude();
164 if (r == MISSING || g == MISSING)
169 public double battery_voltage() {
172 return AltosConvert.cc_battery_to_voltage(batt);
175 public double main_voltage() {
178 return AltosConvert.cc_ignitor_to_voltage(main);
181 public double drogue_voltage() {
182 if (drogue == MISSING)
184 return AltosConvert.cc_ignitor_to_voltage(drogue);
187 /* Value for the CC1111 built-in temperature sensor
188 * Output voltage at 0°C = 0.755V
189 * Coefficient = 0.00247V/°C
190 * Reference voltage = 1.25V
192 * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247
193 * = (value - 19791.268) / 32768 * 1.25 / 0.00247
197 thermometer_to_temperature(double thermo)
199 return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247;
202 public double temperature() {
205 return thermometer_to_temperature(temp);
208 double accel_counts_per_mss() {
209 double counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
211 return counts_per_g / 9.80665;
214 public double acceleration() {
215 if (acceleration != MISSING)
218 if (ground_accel == MISSING || accel == MISSING)
220 return (ground_accel - accel) / accel_counts_per_mss();
223 public double accel_speed() {
224 if (speed != MISSING)
226 if (flight_vel == MISSING)
228 return flight_vel / (accel_counts_per_mss() * 100.0);
231 public String state() {
232 return Altos.state_name(state);
235 public static String gets(FileInputStream s) throws IOException {
239 while ((c = s.read()) != -1) {
245 line = line + (char) c;
250 public int compareTo(AltosRecord o) {
251 return tick - o.tick;
254 public AltosRecord(AltosRecord old) {
255 version = old.version;
257 callsign = old.callsign;
270 flight_accel = old.flight_accel;
271 ground_accel = old.ground_accel;
272 flight_vel = old.flight_vel;
273 flight_pres = old.flight_pres;
274 ground_pres = old.ground_pres;
275 accel_plus_g = old.accel_plus_g;
276 accel_minus_g = old.accel_minus_g;
277 acceleration = old.acceleration;
280 gps = new AltosGPS(old.gps);
282 companion = old.companion;
287 public AltosRecord() {
295 state = Altos.ao_flight_startup;
310 acceleration = MISSING;
313 gps = new AltosGPS();