1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-26 09:45:33 +03:00

Optimised alignSensors function

This commit is contained in:
Martin Budden 2016-11-29 08:32:46 +00:00
parent 2ae1480ccc
commit 036810bd46
5 changed files with 49 additions and 48 deletions

View file

@ -203,7 +203,7 @@ void updateAccelerationReadings(void)
applyAccelerationZero(accZero, accGain); applyAccelerationZero(accZero, accGain);
alignSensors(accADC, accADC, accAlign); alignSensors(accADC, accAlign);
} }
void setAccelerationZero(flightDynamicsTrims_t * accZeroToUse) void setAccelerationZero(flightDynamicsTrims_t * accZeroToUse)

View file

@ -75,52 +75,53 @@ static void alignBoard(int32_t *vec)
vec[Z] = lrintf(boardRotation[0][Z] * x + boardRotation[1][Z] * y + boardRotation[2][Z] * z); vec[Z] = lrintf(boardRotation[0][Z] * x + boardRotation[1][Z] * y + boardRotation[2][Z] * z);
} }
void alignSensors(const int32_t *src, int32_t *dest, uint8_t rotation) void alignSensors(int32_t *dest, uint8_t rotation)
{ {
static uint32_t swap[3]; const int32_t x = dest[X];
memcpy(swap, src, sizeof(swap)); const int32_t y = dest[Y];
const int32_t z = dest[Z];
switch (rotation) { switch (rotation) {
default: default:
case CW0_DEG: case CW0_DEG:
dest[X] = swap[X]; dest[X] = x;
dest[Y] = swap[Y]; dest[Y] = y;
dest[Z] = swap[Z]; dest[Z] = z;
break; break;
case CW90_DEG: case CW90_DEG:
dest[X] = swap[Y]; dest[X] = y;
dest[Y] = -swap[X]; dest[Y] = -x;
dest[Z] = swap[Z]; dest[Z] = z;
break; break;
case CW180_DEG: case CW180_DEG:
dest[X] = -swap[X]; dest[X] = -x;
dest[Y] = -swap[Y]; dest[Y] = -y;
dest[Z] = swap[Z]; dest[Z] = z;
break; break;
case CW270_DEG: case CW270_DEG:
dest[X] = -swap[Y]; dest[X] = -y;
dest[Y] = swap[X]; dest[Y] = x;
dest[Z] = swap[Z]; dest[Z] = z;
break; break;
case CW0_DEG_FLIP: case CW0_DEG_FLIP:
dest[X] = -swap[X]; dest[X] = -x;
dest[Y] = swap[Y]; dest[Y] = y;
dest[Z] = -swap[Z]; dest[Z] = -z;
break; break;
case CW90_DEG_FLIP: case CW90_DEG_FLIP:
dest[X] = swap[Y]; dest[X] = y;
dest[Y] = swap[X]; dest[Y] = x;
dest[Z] = -swap[Z]; dest[Z] = -z;
break; break;
case CW180_DEG_FLIP: case CW180_DEG_FLIP:
dest[X] = swap[X]; dest[X] = x;
dest[Y] = -swap[Y]; dest[Y] = -y;
dest[Z] = -swap[Z]; dest[Z] = -z;
break; break;
case CW270_DEG_FLIP: case CW270_DEG_FLIP:
dest[X] = -swap[Y]; dest[X] = -y;
dest[Y] = -swap[X]; dest[Y] = -x;
dest[Z] = -swap[Z]; dest[Z] = -z;
break; break;
} }

View file

@ -23,6 +23,6 @@ typedef struct boardAlignment_s {
int16_t yawDeciDegrees; int16_t yawDeciDegrees;
} boardAlignment_t; } boardAlignment_t;
void alignSensors(const int32_t *src, int32_t *dest, uint8_t rotation); void alignSensors(int32_t *dest, uint8_t rotation);
void initBoardAlignment(const boardAlignment_t *boardAlignment); void initBoardAlignment(const boardAlignment_t *boardAlignment);
void updateBoardAlignment(boardAlignment_t *boardAlignment, int16_t roll, int16_t pitch); void updateBoardAlignment(boardAlignment_t *boardAlignment, int16_t roll, int16_t pitch);

View file

@ -140,7 +140,7 @@ void compassUpdate(uint32_t currentTime, flightDynamicsTrims_t *magZero)
} }
} }
alignSensors(magADC, magADC, magAlign); alignSensors(magADC, magAlign);
magUpdatedAtLeastOnce = 1; magUpdatedAtLeastOnce = 1;
} }

View file

@ -156,5 +156,5 @@ void gyroUpdate(void)
applyGyroZero(); applyGyroZero();
alignSensors(gyroADC, gyroADC, gyroAlign); alignSensors(gyroADC, gyroAlign);
} }