double previousError = 0;
double integral = 0;
void updatePID(double setPoint, double currentTemperature) {
double error = setPoint - currentTemperature;
integral += error;
double derivative = error - previousError;
double output = Kp * error + Ki * integral + Kd * derivative;
setHeaterPower(output);
previousError = error;
}
|