diff --git a/src/main/fc/mw.c b/src/main/fc/mw.c index 9a77edd6e..44f542440 100644 --- a/src/main/fc/mw.c +++ b/src/main/fc/mw.c @@ -688,7 +688,8 @@ void processRx(uint32_t currentTime) void subTaskPidController(void) { - const uint32_t startTime = micros(); + uint32_t startTime; + if (debugMode == DEBUG_PIDLOOP) {startTime = micros();} // PID - note this is function pointer set by setPIDController() pidController( ¤tProfile->pidProfile, diff --git a/src/main/sensors/boardalignment.c b/src/main/sensors/boardalignment.c index 42ede9155..b18c558f2 100644 --- a/src/main/sensors/boardalignment.c +++ b/src/main/sensors/boardalignment.c @@ -64,51 +64,55 @@ static void alignBoard(int32_t *vec) void alignSensors(const int32_t *src, int32_t *dest, uint8_t rotation) { - static uint32_t swap[3]; - memcpy(swap, src, sizeof(swap)); + int32_t x; + // note src and dest may point to the same address switch (rotation) { - default: - case CW0_DEG: - dest[X] = swap[X]; - dest[Y] = swap[Y]; - dest[Z] = swap[Z]; - break; - case CW90_DEG: - dest[X] = swap[Y]; - dest[Y] = -swap[X]; - dest[Z] = swap[Z]; - break; - case CW180_DEG: - dest[X] = -swap[X]; - dest[Y] = -swap[Y]; - dest[Z] = swap[Z]; - break; - case CW270_DEG: - dest[X] = -swap[Y]; - dest[Y] = swap[X]; - dest[Z] = swap[Z]; - break; - case CW0_DEG_FLIP: - dest[X] = -swap[X]; - dest[Y] = swap[Y]; - dest[Z] = -swap[Z]; - break; - case CW90_DEG_FLIP: - dest[X] = swap[Y]; - dest[Y] = swap[X]; - dest[Z] = -swap[Z]; - break; - case CW180_DEG_FLIP: - dest[X] = swap[X]; - dest[Y] = -swap[Y]; - dest[Z] = -swap[Z]; - break; - case CW270_DEG_FLIP: - dest[X] = -swap[Y]; - dest[Y] = -swap[X]; - dest[Z] = -swap[Z]; - break; + default: + case CW0_DEG: + dest[X] = src[X]; + dest[Y] = src[Y]; + dest[Z] = src[Z]; + break; + case CW90_DEG: + x = src[X]; + dest[X] = src[Y]; + dest[Y] = -x; + dest[Z] = src[Z]; + break; + case CW180_DEG: + dest[X] = -src[X]; + dest[Y] = -src[Y]; + dest[Z] = src[Z]; + break; + case CW270_DEG: + x = src[X]; + dest[X] = -src[Y]; + dest[Y] = x; + dest[Z] = src[Z]; + break; + case CW0_DEG_FLIP: + dest[X] = -src[X]; + dest[Y] = src[Y]; + dest[Z] = -src[Z]; + break; + case CW90_DEG_FLIP: + x = src[X]; + dest[X] = src[Y]; + dest[Y] = x; + dest[Z] = -src[Z]; + break; + case CW180_DEG_FLIP: + dest[X] = src[X]; + dest[Y] = -src[Y]; + dest[Z] = -src[Z]; + break; + case CW270_DEG_FLIP: + x = src[X]; + dest[X] = -src[Y]; + dest[Y] = -x; + dest[Z] = -src[Z]; + break; } if (!standardBoardAlignment) diff --git a/src/main/sensors/gyro.c b/src/main/sensors/gyro.c index c139da427..5ed678e10 100644 --- a/src/main/sensors/gyro.c +++ b/src/main/sensors/gyro.c @@ -157,13 +157,6 @@ static void performGyroCalibration(uint8_t gyroMovementCalibrationThreshold) } -static void applyGyroZero(void) -{ - for (int axis = 0; axis < 3; axis++) { - gyroADC[axis] -= gyroZero[axis]; - } -} - void gyroUpdate(void) { int16_t gyroADCRaw[XYZ_AXIS_COUNT]; @@ -173,9 +166,9 @@ void gyroUpdate(void) return; } - for (int axis = 0; axis < XYZ_AXIS_COUNT; axis++) { - gyroADC[axis] = gyroADCRaw[axis]; - } + gyroADC[X] = gyroADCRaw[X]; + gyroADC[Y] = gyroADCRaw[Y]; + gyroADC[Z] = gyroADCRaw[Z]; alignSensors(gyroADC, gyroADC, gyroAlign); @@ -183,7 +176,9 @@ void gyroUpdate(void) performGyroCalibration(gyroConfig->gyroMovementCalibrationThreshold); } - applyGyroZero(); + gyroADC[X] -= gyroZero[X]; + gyroADC[Y] -= gyroZero[Y]; + gyroADC[Z] -= gyroZero[Z]; if (gyroSoftLpfHz) { for (int axis = 0; axis < XYZ_AXIS_COUNT; axis++) {