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 {
49 double time; /* seconds since boost */
52 * Values for our MP3H6115A pressure sensor
54 * From the data sheet:
56 * Pressure range: 15-115 kPa
57 * Voltage at 115kPa: 2.82
58 * Output scale: 27mV/kPa
61 * 27 mV/kPa * 2047 / 3300 counts/mV = 16.75 counts/kPa
62 * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa
65 static final double counts_per_kPa = 27 * 2047 / 3300;
66 static final double counts_at_101_3kPa = 1674.0;
69 barometer_to_pressure(double count)
71 return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0;
74 public double raw_pressure() {
75 return barometer_to_pressure(pres);
78 public double filtered_pressure() {
79 return barometer_to_pressure(flight_pres);
82 public double ground_pressure() {
83 return barometer_to_pressure(ground_pres);
86 public double filtered_altitude() {
87 return AltosConvert.pressure_to_altitude(filtered_pressure());
90 public double raw_altitude() {
91 return AltosConvert.pressure_to_altitude(raw_pressure());
94 public double ground_altitude() {
95 return AltosConvert.pressure_to_altitude(ground_pressure());
98 public double filtered_height() {
99 return filtered_altitude() - ground_altitude();
102 public double raw_height() {
103 return raw_altitude() - ground_altitude();
106 public double battery_voltage() {
107 return AltosConvert.cc_battery_to_voltage(batt);
110 public double main_voltage() {
111 return AltosConvert.cc_ignitor_to_voltage(main);
114 public double drogue_voltage() {
115 return AltosConvert.cc_ignitor_to_voltage(drogue);
118 /* Value for the CC1111 built-in temperature sensor
119 * Output voltage at 0°C = 0.755V
120 * Coefficient = 0.00247V/°C
121 * Reference voltage = 1.25V
123 * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247
124 * = (value - 19791.268) / 32768 * 1.25 / 0.00247
128 thermometer_to_temperature(double thermo)
130 return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247;
133 public double temperature() {
134 return thermometer_to_temperature(temp);
137 double accel_counts_per_mss() {
138 double counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
140 return counts_per_g / 9.80665;
142 public double acceleration() {
143 return (ground_accel - accel) / accel_counts_per_mss();
146 public double accel_speed() {
147 double speed = flight_vel / (accel_counts_per_mss() * 100.0);
151 public String state() {
152 return Altos.state_name(state);
155 public static String gets(FileInputStream s) throws IOException {
159 while ((c = s.read()) != -1) {
165 line = line + (char) c;
170 public AltosRecord(AltosRecord old) {
171 version = old.version;
172 callsign = old.callsign;
185 flight_accel = old.flight_accel;
186 ground_accel = old.ground_accel;
187 flight_vel = old.flight_vel;
188 flight_pres = old.flight_pres;
189 ground_pres = old.ground_pres;
190 accel_plus_g = old.accel_plus_g;
191 accel_minus_g = old.accel_minus_g;
192 gps = new AltosGPS(old.gps);
195 public AltosRecord() {
202 state = Altos.ao_flight_startup;
217 gps = new AltosGPS();