Merge pull request #6598 from mikeller/fix_accelerometer_problems
Fixed problems with accelerometer.
This commit is contained in:
commit
dca0f13692
|
@ -355,16 +355,16 @@ STATIC_UNIT_TESTED void imuUpdateEulerAngles(void)
|
||||||
|
|
||||||
static bool imuIsAccelerometerHealthy(float *accAverage)
|
static bool imuIsAccelerometerHealthy(float *accAverage)
|
||||||
{
|
{
|
||||||
float accMagnitude = 0;
|
float accMagnitudeSq = 0;
|
||||||
for (int axis = 0; axis < 3; axis++) {
|
for (int axis = 0; axis < 3; axis++) {
|
||||||
const float a = accAverage[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
|
// Accept accel readings only in range 0.9g - 1.1g
|
||||||
return (0.80f <= accMagnitude) && (accMagnitude <= 1.20f);
|
return (0.81f < accMagnitudeSq) && (accMagnitudeSq < 1.21f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the dcmKpGain to use. When armed, the gain is imuRuntimeConfig.dcm_kp * 1.0 scaling.
|
// Calculate the dcmKpGain to use. When armed, the gain is imuRuntimeConfig.dcm_kp * 1.0 scaling.
|
||||||
|
|
|
@ -362,7 +362,7 @@ bool accInit(uint32_t gyroSamplingInverval)
|
||||||
}
|
}
|
||||||
acc.dev.acc_1G = 256; // set default
|
acc.dev.acc_1G = 256; // set default
|
||||||
acc.dev.initFn(&acc.dev); // driver initialisation
|
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
|
// 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
|
switch (gyroSamplingInverval) { // Switch statement kept in place to change acc sampling interval in the future
|
||||||
case 500:
|
case 500:
|
||||||
|
|
Loading…
Reference in New Issue