altoslib: Fix MS5607 raw data to pressure conversion function
authorMiguel Benavidez <miguelbenavidez1145@gmail.com>
Thu, 4 May 2017 18:29:33 +0000 (11:29 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 5 May 2017 05:10:36 +0000 (22:10 -0700)
The MS5607 sensor provides raw 24-bit ADC outputs to the host along
with calibration constants necessary to convert those into temperature
and pressure values. The datasheet has a flow chart indicating how to
perform this computation. There are two parts of the algorithm which
adjust the result based on the ambient temperature, temperatures below
20°C get one compensation factor and temperatures below -15°C get an
additional factor.

The ground station version of this function mistakenly applied the
second compensation factor for all temperatures below +15°C. The
result was that the pressure computed on the ground when the measured
temperature was between -15°C and +15°C was incorrect, resulting in
altitudes which were several hundred meters off in some situations.

This can be seen when displaying any .eeprom (or .mpd) data
files for flights with temperatures in that range. The datafiles
themselves are not corrupted, only the display operation.

This is not seen for telemetry data, where the pressure and associated
altitude is computed in the airframe using the correct algorithm.

Thanks much to Miguel and the rest of the Vanguard School TARC team
for identifying the problem and providing this fix.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosMs5607.java

index 631bc716d41c23fbb70324f36b812b363fcbac30..19d2dd6db0b94fc6b85a9e6e9c5c15d4dbeea602 100644 (file)
@@ -64,7 +64,7 @@ public class AltosMs5607 {
                        int TEMPM = TEMP - 2000;
                        long OFF2 = ((long) 61 * (long) TEMPM * (long) TEMPM) >> 4;
                        long SENS2 = (long) 2 * (long) TEMPM * (long) TEMPM;
-                       if (TEMP < 1500) {
+                       if (TEMP < -1500) {
                                int TEMPP = TEMP + 1500;
                                long TEMPP2 = (long) TEMPP * (long) TEMPP;
                                OFF2 = OFF2 + 15 * TEMPP2;