1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-24 00:35:34 +03:00

Make accelerometer position calculation aligned with Configurator

This commit is contained in:
Konstantin Sharlaimov (DigitalEntity) 2017-12-30 22:05:36 +10:00
parent ca1e0ab05a
commit 1c68e9b720

View file

@ -359,6 +359,9 @@ uint8_t accGetCalibrationAxisFlags(void)
int getPrimaryAxisIndex(int32_t sample[3]) int getPrimaryAxisIndex(int32_t sample[3])
{ {
// Apply sensor & board alignment (for axis detection only)
alignSensors(sample, acc.dev.accAlign);
// Tolerate up to atan(1 / 1.5) = 33 deg tilt (in worst case 66 deg separation between points) // Tolerate up to atan(1 / 1.5) = 33 deg tilt (in worst case 66 deg separation between points)
if ((ABS(sample[Z]) / 1.5f) > ABS(sample[X]) && (ABS(sample[Z]) / 1.5f) > ABS(sample[Y])) { if ((ABS(sample[Z]) / 1.5f) > ABS(sample[X]) && (ABS(sample[Z]) / 1.5f) > ABS(sample[Y])) {
//Z-axis //Z-axis
@ -366,11 +369,11 @@ int getPrimaryAxisIndex(int32_t sample[3])
} }
else if ((ABS(sample[X]) / 1.5f) > ABS(sample[Y]) && (ABS(sample[X]) / 1.5f) > ABS(sample[Z])) { else if ((ABS(sample[X]) / 1.5f) > ABS(sample[Y]) && (ABS(sample[X]) / 1.5f) > ABS(sample[Z])) {
//X-axis //X-axis
return (sample[X] > 0) ? 2 : 3; return (sample[X] > 0) ? 3 : 5;
} }
else if ((ABS(sample[Y]) / 1.5f) > ABS(sample[X]) && (ABS(sample[Y]) / 1.5f) > ABS(sample[Z])) { else if ((ABS(sample[Y]) / 1.5f) > ABS(sample[X]) && (ABS(sample[Y]) / 1.5f) > ABS(sample[Z])) {
//Y-axis //Y-axis
return (sample[Y] > 0) ? 4 : 5; return (sample[Y] > 0) ? 2 : 4;
} }
else else
return -1; return -1;