da2d948cd3cf5953142189cb96cdd03621af272a
[fw/altos] / altoslib / AltosRecordTM2.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_2;
19
20 public class AltosRecordTM2 extends AltosRecord {
21
22         /* Sensor values */
23         public int      accel;
24         public int      pres;
25         public int      temp;
26         
27         public int      v_batt;
28         public int      sense_a;
29         public int      sense_m;
30
31         public int      ground_accel;
32         public int      ground_pres;
33         public int      accel_plus_g;
34         public int      accel_minus_g;
35
36         public int      flight_accel;
37         public int      flight_vel;
38         public int      flight_pres;
39
40         static double adc(int raw) {
41                 return raw / 4095.0;
42         }
43
44         public double pressure() {
45                 if (pres != MISSING)
46                         return pres;
47                 return MISSING;
48         }
49
50         public double ground_pressure() {
51                 if (ground_pres != MISSING)
52                         return ground_pres;
53                 return MISSING;
54         }
55
56         public double battery_voltage() {
57                 if (v_batt != MISSING)
58                         return 3.3 * adc(v_batt) * (15.0 + 27.0) / 27.0;
59                 return MISSING;
60         }
61
62         static double pyro(int raw) {
63                 if (raw != MISSING)
64                         return 3.3 * adc(raw) * (100.0 + 27.0) / 27.0;
65                 return MISSING;
66         }
67
68         public double main_voltage() {
69                 return pyro(sense_m);
70         }
71
72         public double drogue_voltage() {
73                 return pyro(sense_a);
74         }
75
76         public double temperature() {
77                 if (temp != MISSING)
78                         return temp / 100.0;
79                 return MISSING;
80         }
81         
82         double accel_counts_per_mss() {
83                 double  counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
84
85                 return counts_per_g / 9.80665;
86         }
87
88         public double acceleration() {
89                 if (ground_accel == MISSING || accel == MISSING)
90                         return MISSING;
91
92                 if (accel_minus_g == MISSING || accel_plus_g == MISSING)
93                         return MISSING;
94
95                 return (ground_accel - accel) / accel_counts_per_mss();
96         }
97
98         public void copy (AltosRecordTM2 old) {
99                 super.copy(old);
100
101                 accel = old.accel;
102                 pres = old.pres;
103                 temp = old.temp;
104
105                 v_batt = old.v_batt;
106                 sense_a = old.sense_a;
107                 sense_m = old.sense_m;
108
109                 ground_accel = old.ground_accel;
110                 ground_pres = old.ground_pres;
111                 accel_plus_g = old.accel_plus_g;
112                 accel_minus_g = old.accel_minus_g;
113                 
114                 flight_accel = old.flight_accel;
115                 flight_vel = old.flight_vel;
116                 flight_pres = old.flight_pres;
117         }
118
119         public AltosRecordTM2 clone() {
120                 return new AltosRecordTM2(this);
121         }
122
123         void make_missing() {
124
125                 accel = MISSING;
126                 pres = MISSING;
127                 temp = MISSING;
128
129                 v_batt = MISSING;
130                 sense_a = MISSING;
131                 sense_m = MISSING;
132
133                 ground_accel = MISSING;
134                 ground_pres = MISSING;
135                 accel_plus_g = MISSING;
136                 accel_minus_g = MISSING;
137
138                 flight_accel = 0;
139                 flight_vel = 0;
140                 flight_pres = 0;
141         }
142
143         public AltosRecordTM2(AltosRecord old) {
144                 super.copy(old);
145                 make_missing();
146         }
147
148         public AltosRecordTM2(AltosRecordTM2 old) {
149                 copy(old);
150         }
151
152         public AltosRecordTM2() {
153                 super();
154                 make_missing();
155         }
156 }