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 {
26 final static int MISSING = 0x7fffffff;
59 double time; /* seconds since boost */
62 * Values for our MP3H6115A pressure sensor
64 * From the data sheet:
66 * Pressure range: 15-115 kPa
67 * Voltage at 115kPa: 2.82
68 * Output scale: 27mV/kPa
71 * 27 mV/kPa * 2047 / 3300 counts/mV = 16.75 counts/kPa
72 * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa
75 static final double counts_per_kPa = 27 * 2047 / 3300;
76 static final double counts_at_101_3kPa = 1674.0;
79 barometer_to_pressure(double count)
81 return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0;
84 public double raw_pressure() {
87 return barometer_to_pressure(pres);
90 public double filtered_pressure() {
91 if (flight_pres == MISSING)
93 return barometer_to_pressure(flight_pres);
96 public double ground_pressure() {
97 if (ground_pres == MISSING)
99 return barometer_to_pressure(ground_pres);
102 public double raw_altitude() {
103 double p = raw_pressure();
106 return AltosConvert.pressure_to_altitude(p);
109 public double ground_altitude() {
110 double p = ground_pressure();
113 return AltosConvert.pressure_to_altitude(p);
116 public double filtered_altitude() {
117 if (height != MISSING && ground_pres != MISSING)
118 return height + ground_altitude();
120 double p = filtered_pressure();
123 return AltosConvert.pressure_to_altitude(p);
126 public double filtered_height() {
127 if (height != MISSING)
130 double f = filtered_altitude();
131 double g = ground_altitude();
132 if (f == MISSING || g == MISSING)
137 public double raw_height() {
138 double r = raw_altitude();
139 double g = ground_altitude();
141 if (r == MISSING || g == MISSING)
146 public double battery_voltage() {
149 return AltosConvert.cc_battery_to_voltage(batt);
152 public double main_voltage() {
155 return AltosConvert.cc_ignitor_to_voltage(main);
158 public double drogue_voltage() {
159 if (drogue == MISSING)
161 return AltosConvert.cc_ignitor_to_voltage(drogue);
164 /* Value for the CC1111 built-in temperature sensor
165 * Output voltage at 0°C = 0.755V
166 * Coefficient = 0.00247V/°C
167 * Reference voltage = 1.25V
169 * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247
170 * = (value - 19791.268) / 32768 * 1.25 / 0.00247
174 thermometer_to_temperature(double thermo)
176 return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247;
179 public double temperature() {
182 return thermometer_to_temperature(temp);
185 double accel_counts_per_mss() {
186 double counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
188 return counts_per_g / 9.80665;
191 public double acceleration() {
192 if (acceleration != MISSING)
195 if (ground_accel == MISSING || accel == MISSING)
197 return (ground_accel - accel) / accel_counts_per_mss();
200 public double accel_speed() {
201 if (speed != MISSING)
203 if (flight_vel == MISSING)
205 return flight_vel / (accel_counts_per_mss() * 100.0);
208 public String state() {
209 return Altos.state_name(state);
212 public static String gets(FileInputStream s) throws IOException {
216 while ((c = s.read()) != -1) {
222 line = line + (char) c;
227 public AltosRecord(AltosRecord old) {
228 version = old.version;
229 callsign = old.callsign;
242 flight_accel = old.flight_accel;
243 ground_accel = old.ground_accel;
244 flight_vel = old.flight_vel;
245 flight_pres = old.flight_pres;
246 ground_pres = old.ground_pres;
247 accel_plus_g = old.accel_plus_g;
248 accel_minus_g = old.accel_minus_g;
249 acceleration = old.acceleration;
252 gps = new AltosGPS(old.gps);
255 public AltosRecord() {
262 state = Altos.ao_flight_startup;
277 acceleration = MISSING;
280 gps = new AltosGPS();