File: drone-flight-controller.ino
Line: 253
Problem
angular_motions[YAW] uses +gyro_raw[Z], while measures[YAW] uses -gyro_raw[Z].
They represent the same physical quantity with opposite signs.
The PID error is computed from angular_motions[YAW]. Since the yaw set point is positive for a rightward rotation, but angular_motions[YAW] is negative for the same rotation, the error grows larger as the drone approaches the desired yaw rate — positive feedback.
The drone will spin uncontrollably.
Fix
// Before
angular_motions[YAW] = 0.7 * angular_motions[YAW] + 0.3 * gyro_raw[Z] / SSF_GYRO;
// After
angular_motions[YAW] = 0.7 * angular_motions[YAW] - 0.3 * gyro_raw[Z] / SSF_GYRO;
Verification
With throttle low and yaw stick pushed right, the drone should rotate clockwise (nose right) at a speed proportional to stick deflection, and stop rotating when the stick returns to center.
File:
drone-flight-controller.inoLine: 253
Problem
angular_motions[YAW]uses+gyro_raw[Z], whilemeasures[YAW]uses-gyro_raw[Z].They represent the same physical quantity with opposite signs.
The PID error is computed from
angular_motions[YAW]. Since the yaw set point is positive for a rightward rotation, butangular_motions[YAW]is negative for the same rotation, the error grows larger as the drone approaches the desired yaw rate — positive feedback.The drone will spin uncontrollably.
Fix
Verification
With throttle low and yaw stick pushed right, the drone should rotate clockwise (nose right) at a speed proportional to stick deflection, and stop rotating when the stick returns to center.