From 6394cc275d247c2761f5aadd57bb9003a4974cd0 Mon Sep 17 00:00:00 2001 From: mikeller Date: Mon, 20 Aug 2018 15:54:29 +1200 Subject: [PATCH] Fixed problems with accelerometer. --- src/main/flight/imu.c | 10 +++++----- src/main/sensors/acceleration.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/flight/imu.c b/src/main/flight/imu.c index 8dec160a5..6f6dd85d2 100644 --- a/src/main/flight/imu.c +++ b/src/main/flight/imu.c @@ -355,16 +355,16 @@ STATIC_UNIT_TESTED void imuUpdateEulerAngles(void) static bool imuIsAccelerometerHealthy(float *accAverage) { - float accMagnitude = 0; + float accMagnitudeSq = 0; for (int axis = 0; axis < 3; axis++) { const float a = accAverage[axis]; - accMagnitude += a * a; + accMagnitudeSq += a * a; } - accMagnitude = sqrtf(accMagnitude) * acc.dev.acc_1G_rec; + accMagnitudeSq = accMagnitudeSq * sq(acc.dev.acc_1G_rec); - // Accept accel readings only in range 0.80g - 1.20g - return (0.80f <= accMagnitude) && (accMagnitude <= 1.20f); + // Accept accel readings only in range 0.9g - 1.1g + return (0.81f < accMagnitudeSq) && (accMagnitudeSq < 1.21f); } // Calculate the dcmKpGain to use. When armed, the gain is imuRuntimeConfig.dcm_kp * 1.0 scaling. diff --git a/src/main/sensors/acceleration.c b/src/main/sensors/acceleration.c index e938e1700..882fbccd1 100644 --- a/src/main/sensors/acceleration.c +++ b/src/main/sensors/acceleration.c @@ -362,7 +362,7 @@ bool accInit(uint32_t gyroSamplingInverval) } acc.dev.acc_1G = 256; // set default acc.dev.initFn(&acc.dev); // driver initialisation - acc.dev.acc_1G_rec = 1 / acc.dev.acc_1G; + acc.dev.acc_1G_rec = 1.0f / acc.dev.acc_1G; // set the acc sampling interval according to the gyro sampling interval switch (gyroSamplingInverval) { // Switch statement kept in place to change acc sampling interval in the future case 500: