altoslib: use motor pressure calibration data for EasyMotor
authorKeith Packard <keithp@keithp.com>
Fri, 16 Oct 2020 22:30:35 +0000 (15:30 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 22 Oct 2020 04:33:59 +0000 (21:33 -0700)
EasyMotor stores an average sensor value for motor pressure, use that
to report pressure above that value.

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

index 832725defb842fd39d05efeaac980abc4bba52ed..8bca92291757a42c695985c23bb5337334c9b4e4 100644 (file)
@@ -120,6 +120,13 @@ public class AltosCalData {
                        this.ground_accel = ground_accel;
        }
 
+       public double           ground_motor_pressure = AltosLib.MISSING;
+
+       public void set_ground_motor_pressure(double ground_motor_pressure) {
+               if (ground_motor_pressure != AltosLib.MISSING)
+                       this.ground_motor_pressure = ground_motor_pressure;
+       }
+
        /* Raw acceleration value */
        public double           accel = AltosLib.MISSING;
 
index e51e4f3059f942893a1fc30d331fbdcf16ab5dba..099ea04859337bb14e0799df62d607eabc97f9d8 100644 (file)
@@ -280,11 +280,11 @@ public class AltosConvert {
                return 3.3 * mega_adc(sensor) * (100.0 + 27.0) / 27.0;
        }
 
-       static double easy_mini_2_adc(int raw) {
+       static double easy_mini_2_adc(double raw) {
                return raw / 4095.0;
        }
 
-       static double easy_mini_1_adc(int raw) {
+       static double easy_mini_1_adc(double raw) {
                return raw / 32767.0;
        }
 
@@ -323,11 +323,12 @@ public class AltosConvert {
                return (voltage - base) / (max - base) * full_scale_pressure;
        }
 
-       static double easy_motor_2_motor_pressure(int sensor) {
+       static double easy_motor_2_motor_pressure(int sensor, double ground_sensor) {
                double  supply = 3.3;
+               double  ground_voltage = easy_mini_2_adc(ground_sensor) * supply * 15.6 / 10.0;
                double  voltage = easy_mini_2_adc(sensor) * supply * 15.6 / 10.0;
 
-               return motor_pressure(voltage);
+               return motor_pressure(voltage) - motor_pressure(ground_voltage);
        }
 
        public static double radio_to_frequency(int freq, int setting, int cal, int channel) {
index 656feb9b32db76a01c6e9fdd81da9800ce3ec1b8..a2ec569a0c2340901313a01b1b3622835f03c028 100644 (file)
@@ -25,6 +25,7 @@ public class AltosEepromRecordMotor extends AltosEepromRecord {
        private int ground_accel_along() { return data16(4); }
        private int ground_accel_across() { return data16(6); }
        private int ground_accel_through() { return data16(8); }
+       private int ground_motor_pressure() { return data16(10); }
 
        /* AO_LOG_STATE elements */
        private int state() { return data16(0); }
@@ -59,6 +60,7 @@ public class AltosEepromRecordMotor extends AltosEepromRecord {
                        listener.set_accel_ground(cal_data.accel_along(ground_accel_along()),
                                                  cal_data.accel_across(ground_accel_across()),
                                                  cal_data.accel_through(ground_accel_through()));
+                       cal_data.set_ground_motor_pressure(ground_motor_pressure());
                        break;
                case AltosLib.AO_LOG_STATE:
                        listener.set_state(state());
@@ -67,7 +69,7 @@ public class AltosEepromRecordMotor extends AltosEepromRecord {
                        AltosConfigData config_data = eeprom.config_data();
 
                        listener.set_battery_voltage(AltosConvert.easy_mini_2_voltage(v_batt()));
-                       double pa = AltosConvert.easy_motor_2_motor_pressure(motor_pres());
+                       double pa = AltosConvert.easy_motor_2_motor_pressure(motor_pres(), cal_data.ground_motor_pressure);
                        listener.set_motor_pressure(pa);
 
                        int     accel_along = accel_along();