``````    /*
PITCH CORRECTION
*/

pitchError = (desiredPitch - pitchAngle) * speedRatio - alpha;
if (pulseThrottle < 1100) pitchError = 0;
if (!pitchSaturation) pitchErrorSum += kI_Pitch * pitchError;
pitchCorrection = kP_Pitch * pitchError + pitchErrorSum + kD_Pitch * (pitchError - pitchErrorPrec);
if (pitchCorrection > maxPID_Pitch) {
pitchCorrection = maxPID_Pitch;
pitchSaturation = 1;
}
if (pitchCorrection < -maxPID_Pitch) {
pitchCorrection = -maxPID_Pitch;
pitchSaturation = 1;
}
if (pitchCorrection < maxPID_Pitch && pitchCorrection > -maxPID_Pitch) pitchSaturation = 0;
pitchErrorPrec = pitchError;
``````

Hello everybody. i’m coding my own quadcopter flight controller with arduino and i have a problem. it flies well but after pitching/rolling it is very slow in returning to hovering condition. for example, if it is pitching positive (20 degrees) and suddenly i bring back pitch stick to center (desiredPitch=0), quadcopter is slow in going from 20 to 0. viceversa, from 0 to 20 i had no problem, it is as i want! i’ve implented a angular speed PID controller and at first time i thought it was a wind up error or similar. so i added saturation code but it still behave like that! i tried a lot of ki,kp,kd combinations but no results! attached is the PID logic for picth. alpha is angular velocity while pitch angle is the estimated angle. i’m sure that these are good, no drift, no oscillations, no vibration affected. so the problem is the control logic… i don’t know what to do! thanks everybody will answer!

so the problem is the control logic

Or the values in the variables. For instance, I would expect that alpha would contain a positive value when you want to increase the pitch from 0 to 20, and would contain a negative value when you want to decrease the pitch from 20 to 0. But, there is no proof that such is the case.