altos: Reset 3d-accel and motor pressure sums each ground interval
authorKeith Packard <keithp@keithp.com>
Sat, 17 Oct 2020 03:48:55 +0000 (20:48 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 22 Oct 2020 04:33:59 +0000 (21:33 -0700)
We're repeatedly averaging 512 ground samples to get up-to-date values
for all of the sensors, but we need to clear the sums after each
sample interval. The 3d accel values were only cleared if there was a
full IMU, not for devices with only an accelerometer like
EasyMotor. The motor pressure sum was never cleared.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/kernel/ao_sample.c

index 874c91100a665ca1f0ec3680e4392ede174e9acc..2c77c36920ed5755046e158c9e32f4e92e2d9aae 100644 (file)
@@ -210,18 +210,18 @@ ao_sample_preflight_set(void)
        ao_ground_accel_along = ao_sample_accel_along_sum >> 9;
        ao_ground_accel_across = ao_sample_accel_across_sum >> 9;
        ao_ground_accel_through = ao_sample_accel_through_sum >> 9;
-
+       ao_sample_accel_along_sum = 0;
+       ao_sample_accel_across_sum = 0;
+       ao_sample_accel_through_sum = 0;
 #endif
 #if HAS_MOTOR_PRESSURE
        ao_ground_motor_pressure = ao_sample_motor_pressure_sum >> 9;
+       ao_sample_motor_pressure_sum = 0;
 #endif
 #if HAS_GYRO
        ao_ground_pitch = ao_sample_pitch_sum;
        ao_ground_yaw = ao_sample_yaw_sum;
        ao_ground_roll = ao_sample_roll_sum;
-       ao_sample_accel_along_sum = 0;
-       ao_sample_accel_across_sum = 0;
-       ao_sample_accel_through_sum = 0;
        ao_sample_pitch_sum = 0;
        ao_sample_yaw_sum = 0;
        ao_sample_roll_sum = 0;
@@ -257,7 +257,7 @@ ao_sample_preflight_set(void)
                       (ao_ground_accel_across - ao_config.accel_zero_across),
                       (ao_ground_accel_through - ao_config.accel_zero_through),
                       (ao_ground_accel_along - ao_config.accel_zero_along));
-#endif 
+#endif
 
        ao_sample_compute_orient();
        ao_sample_set_all_orients();