Arduino-PID-Library icon indicating copy to clipboard operation
Arduino-PID-Library copied to clipboard

PID algorithm problem

Open q-bird opened this issue 7 years ago • 0 comments

Hi @br3ttb

Can you please check the PID algorithm? I see the following code inside the library

//...
      double input = *myInput;
      double error = *mySetpoint - input;
      double dInput = (input - lastInput);
      outputSum+= (ki * error);
//...

For example:

  • SetControllerDirection(REVERSE), use PI controller (D = 0)
  • The setpoint is 23 degree
  • The real temperature will reduce step by step from 28 degree Based on the formula in the library outputSum += (ki * error) ; output = outputSum + kp*error (ki = Ki*T), but (ki * error) and kp*error are always positive numbers until the input is equal setpoint (where the error = 0)

Then at the setpoint, error = 0, but the pre_outputSum > 0 ==> the outputSum at setpoint = pre_outputSum + current_outputSum > 0 ==> it will absolutely be overshoot, in theory we expect that the output should stop before the input reaches the setpoint, but here it's still working, based on this formula, the output will be even working few cycles after setpoint because the outputSum is still postive, then after pass through setpoint, the error will become "negative" and "P", "I" will become "negative" too, then the output will go to zero, but it's too late already!

q-bird avatar Sep 25 '18 08:09 q-bird