I have the PID Code like this
float updatePID(float target_Angle, float current_Angle, struct PIDdata *PIDparameters)
{
float error = target_Angle - current_Angle;
//
// Calculate the Integral Term.
//
PIDparameters->integratedError += PIDparameters->Ki * error * deltaPIDTime;
PIDparameters->integratedError = constrain(PIDparameters->integratedError, PIDparameters->windupGuard, -PIDparameters->windupGuard);
//
// Derivative Term Calculation
//
float dTerm = PIDparameters->Kd * (current_Angle - PIDparameters->last_Angle) * inv_deltaPIDTime;
//
// Update last angle
//
PIDparameters->last_Angle = current_Angle;
return (PIDparameters->Kp * error + PIDparameters->integratedError + dTerm);
}
I dont understand that the integral term is accumulated over time. Supposed that i use pid to control the level of the quadcopter. if the quadcopter deviates from the desired position and the comes back to the desired position. At that time the integral term has accumulated some error. So i think that although the quadcopter has come back to the desired position PID Output will not be zero for the code above.
Is the way i think is right?