]> git.gag.com Git - fw/altos/blob - altoslib/AltosRecordTM.java
altos/stm: Make sampling profiler work again
[fw/altos] / altoslib / AltosRecordTM.java
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 package org.altusmetrum.altoslib_1;
19
20 public class AltosRecordTM extends AltosRecord {
21
22         /* Sensor values */
23         public int      accel;
24         public int      pres;
25         public int      temp;
26         public int      batt;
27         public int      drogue;
28         public int      main;
29
30         public int      ground_accel;
31         public int      ground_pres;
32         public int      accel_plus_g;
33         public int      accel_minus_g;
34
35         public int      flight_accel;
36         public int      flight_vel;
37         public int      flight_pres;
38
39         /*
40          * Values for our MP3H6115A pressure sensor
41          *
42          * From the data sheet:
43          *
44          * Pressure range: 15-115 kPa
45          * Voltage at 115kPa: 2.82
46          * Output scale: 27mV/kPa
47          *
48          *
49          * 27 mV/kPa * 2047 / 3300 counts/mV = 16.75 counts/kPa
50          * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa
51          */
52
53         static final double counts_per_kPa = 27 * 2047 / 3300;
54         static final double counts_at_101_3kPa = 1674.0;
55
56         static double
57         barometer_to_pressure(double count)
58         {
59                 return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0;
60         }
61
62         public double pressure() {
63                 if (pres == MISSING)
64                         return MISSING;
65                 return barometer_to_pressure(pres);
66         }
67
68         public double ground_pressure() {
69                 if (ground_pres == MISSING)
70                         return MISSING;
71                 return barometer_to_pressure(ground_pres);
72         }
73
74         public double battery_voltage() {
75                 if (batt == MISSING)
76                         return MISSING;
77                 return AltosConvert.cc_battery_to_voltage(batt);
78         }
79
80         public double main_voltage() {
81                 if (main == MISSING)
82                         return MISSING;
83                 return AltosConvert.cc_ignitor_to_voltage(main);
84         }
85
86         public double drogue_voltage() {
87                 if (drogue == MISSING)
88                         return MISSING;
89                 return AltosConvert.cc_ignitor_to_voltage(drogue);
90         }
91
92         /* Value for the CC1111 built-in temperature sensor
93          * Output voltage at 0°C = 0.755V
94          * Coefficient = 0.00247V/°C
95          * Reference voltage = 1.25V
96          *
97          * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247
98          *      = (value - 19791.268) / 32768 * 1.25 / 0.00247
99          */
100
101         static double
102         thermometer_to_temperature(double thermo)
103         {
104                 return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247;
105         }
106
107         public double temperature() {
108                 if (temp == MISSING)
109                         return MISSING;
110                 return thermometer_to_temperature(temp);
111         }
112
113         double accel_counts_per_mss() {
114                 double  counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
115
116                 return counts_per_g / 9.80665;
117         }
118
119         public double acceleration() {
120                 if (ground_accel == MISSING || accel == MISSING)
121                         return MISSING;
122                 return (ground_accel - accel) / accel_counts_per_mss();
123         }
124
125         public void copy(AltosRecordTM old) {
126                 super.copy(old);
127
128                 version = old.version;
129                 callsign = old.callsign;
130                 serial = old.serial;
131                 flight = old.flight;
132                 rssi = old.rssi;
133                 status = old.status;
134                 state = old.state;
135                 tick = old.tick;
136                 accel = old.accel;
137                 pres = old.pres;
138                 temp = old.temp;
139                 batt = old.batt;
140                 drogue = old.drogue;
141                 main = old.main;
142                 flight_accel = old.flight_accel;
143                 ground_accel = old.ground_accel;
144                 flight_vel = old.flight_vel;
145                 flight_pres = old.flight_pres;
146                 ground_pres = old.ground_pres;
147                 accel_plus_g = old.accel_plus_g;
148                 accel_minus_g = old.accel_minus_g;
149         }
150
151         public AltosRecordTM clone() {
152                 return new AltosRecordTM(this);
153         }
154
155         void make_missing() {
156                 accel = MISSING;
157                 pres = MISSING;
158                 temp = MISSING;
159                 batt = MISSING;
160                 drogue = MISSING;
161                 main = MISSING;
162
163                 flight_accel = MISSING;
164                 flight_vel = MISSING;
165                 flight_pres = MISSING;
166
167                 ground_accel = MISSING;
168                 ground_pres = MISSING;
169                 accel_plus_g = MISSING;
170                 accel_minus_g = MISSING;
171         }
172
173         public AltosRecordTM(AltosRecord old) {
174                 super.copy(old);
175                 make_missing();
176         }
177
178         public AltosRecordTM(AltosRecordTM old) {
179                 copy(old);
180         }
181         
182         public AltosRecordTM() {
183                 super();
184                 make_missing();
185         }
186 }