altos: struct ao_log_mega doesn't have a ground temp value
[fw/altos] / altoslib / AltosRecordMM.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;
19
20 public class AltosRecordMM extends AltosRecord {
21
22         public int      accel;
23         public int      pres;
24         public int      temp;
25         
26         public int      v_batt;
27         public int      v_pyro;
28         public int      sense[];
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         public final static int num_sense = 6;
40
41         public AltosIMU imu;
42         public AltosMag mag;
43
44         static double adc(int raw) {
45                 return raw / 4095.0;
46         }
47
48         public double raw_pressure() {
49                 if (pres != MISSING)
50                         return pres;
51                 return MISSING;
52         }
53
54         public double filtered_pressure() {
55                 return raw_pressure();
56         }
57
58         public double ground_pressure() {
59                 if (ground_pres != MISSING)
60                         return ground_pres;
61                 return MISSING;
62         }
63
64         public double battery_voltage() {
65                 if (v_batt != MISSING)
66                         return 3.3 * adc(v_batt) * (15.0 + 27.0) / 27.0;
67                 return MISSING;
68         }
69
70         static double pyro(int raw) {
71                 if (raw != MISSING)
72                         return 3.3 * adc(raw) * (100.0 + 27.0) / 27.0;
73                 return MISSING;
74         }
75
76         public double main_voltage() {
77                 return pyro(sense[1]);
78         }
79
80         public double drogue_voltage() {
81                 return pyro(sense[0]);
82         }
83
84         public double temperature() {
85                 if (temp != MISSING)
86                         return temp / 100.0;
87                 return MISSING;
88         }
89         
90         public AltosIMU imu() { return imu; }
91
92         public AltosMag mag() { return mag; }
93
94         double accel_counts_per_mss() {
95                 double  counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
96
97                 return counts_per_g / 9.80665;
98         }
99
100         public double acceleration() {
101                 if (acceleration != MISSING)
102                         return acceleration;
103
104                 if (ground_accel == MISSING || accel == MISSING)
105                         return MISSING;
106
107                 if (accel_minus_g == MISSING || accel_plus_g == MISSING)
108                         return MISSING;
109
110                 return (ground_accel - accel) / accel_counts_per_mss();
111         }
112
113         public double accel_speed() {
114                 return speed;
115         }
116
117         public void copy (AltosRecordMM old) {
118                 super.copy(old);
119
120                 accel = old.accel;
121                 pres = old.pres;
122                 temp = old.temp;
123
124                 v_batt = old.v_batt;
125                 v_pyro = old.v_pyro;
126                 sense = new int[num_sense];
127                 
128                 for (int i = 0; i < num_sense; i++)
129                         sense[i] = old.sense[i];
130
131                 ground_accel = old.ground_accel;
132                 ground_pres = old.ground_pres;
133                 accel_plus_g = old.accel_plus_g;
134                 accel_minus_g = old.accel_minus_g;
135                 
136                 flight_accel = old.flight_accel;
137                 flight_vel = old.flight_vel;
138                 flight_pres = old.flight_pres;
139
140                 imu = old.imu;
141                 mag = old.mag;
142         }
143
144         public AltosRecordMM clone() {
145                 AltosRecordMM n = (AltosRecordMM) super.clone();
146                 n.copy(this);
147                 return n;
148         }
149
150         void make_missing() {
151
152                 accel = MISSING;
153                 pres = MISSING;
154                 temp = MISSING;
155
156                 v_batt = MISSING;
157                 v_pyro = MISSING;
158                 sense = new int[num_sense];
159                 for (int i = 0; i < num_sense; i++)
160                         sense[i] = MISSING;
161
162                 ground_accel = MISSING;
163                 ground_pres = MISSING;
164                 accel_plus_g = MISSING;
165                 accel_minus_g = MISSING;
166
167                 flight_accel = 0;
168                 flight_vel = 0;
169                 flight_pres = 0;
170
171                 imu = new AltosIMU();
172                 mag = new AltosMag();
173         }
174
175         public AltosRecordMM(AltosRecord old) {
176                 super.copy(old);
177                 make_missing();
178         }
179
180         public AltosRecordMM() {
181                 super();
182                 make_missing();
183         }
184 }