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;
24 import altosui.AltosConvert;
25 import altosui.AltosGPS;
27 public class AltosRecord {
51 double time; /* seconds since boost */
54 * Values for our MP3H6115A pressure sensor
56 * From the data sheet:
58 * Pressure range: 15-115 kPa
59 * Voltage at 115kPa: 2.82
60 * Output scale: 27mV/kPa
63 * 27 mV/kPa * 2047 / 3300 counts/mV = 16.75 counts/kPa
64 * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa
67 static final double counts_per_kPa = 27 * 2047 / 3300;
68 static final double counts_at_101_3kPa = 1674.0;
71 barometer_to_pressure(double count)
73 return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0;
76 public double pressure() {
77 return barometer_to_pressure(flight_pres);
80 public double ground_pressure() {
81 return barometer_to_pressure(ground_pres);
84 public double altitude() {
85 return AltosConvert.pressure_to_altitude(pressure());
88 public double ground_altitude() {
89 return AltosConvert.pressure_to_altitude(ground_pressure());
92 public double height() {
93 return altitude() - ground_altitude();
96 public double battery_voltage() {
97 return AltosConvert.cc_battery_to_voltage(batt);
100 public double main_voltage() {
101 return AltosConvert.cc_ignitor_to_voltage(main);
104 public double drogue_voltage() {
105 return AltosConvert.cc_ignitor_to_voltage(drogue);
108 /* Value for the CC1111 built-in temperature sensor
109 * Output voltage at 0°C = 0.755V
110 * Coefficient = 0.00247V/°C
111 * Reference voltage = 1.25V
113 * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247
114 * = (value - 19791.268) / 32768 * 1.25 / 0.00247
118 thermometer_to_temperature(double thermo)
120 return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247;
123 public double temperature() {
124 return thermometer_to_temperature(temp);
127 double accel_counts_per_mss() {
128 double counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
130 return counts_per_g / 9.80665;
132 public double acceleration() {
133 return (accel_plus_g - accel) / accel_counts_per_mss();
136 public double accel_speed() {
137 double speed = flight_vel / (accel_counts_per_mss() * 100.0);
141 public String state() {
142 return Altos.state_name(state);
145 public static String gets(FileInputStream s) throws IOException {
149 while ((c = s.read()) != -1) {
155 line = line + (char) c;
160 public AltosRecord(AltosRecord old) {
161 version = old.version;
162 callsign = old.callsign;
175 flight_accel = old.flight_accel;
176 ground_accel = old.ground_accel;
177 flight_vel = old.flight_vel;
178 flight_pres = old.flight_pres;
179 ground_pres = old.ground_pres;
180 accel_plus_g = old.accel_plus_g;
181 accel_minus_g = old.accel_minus_g;
182 gps = new AltosGPS(old.gps);
185 public AltosRecord() {
192 state = Altos.ao_flight_startup;
207 gps = new AltosGPS();