2

I'm working through the (excellent!) Process Dynamics and Control course at apmonitor.com and have a question about using GEKKO for simulating (and optimizing) PID control parameters.

Starting with Example 14. PID_Control_Tuning I am wondering how to deal with processes that have a physically limited output (OP) range. (The TCLab heater for example, which is limited to 0-100% of full-scale output.)

If the "step" variable in the example is changed to:

step[40:]  = 15.0 # Increase Step Size from 5.0 to 15.0

then the (dimensionless) output (OP) value at time=40 is 150.

GEKKO Python PID Process Control Plot

If I add LOWER and UPPER boundaries to the OP Variable using:

#OP = m.Var(value=0.0) # Original
OP = m.Var(value=0.0, lb=0.0, ub=100.0)

the model fails to solve and results in Exception: @error: Solution Not Found

What is the correct way to simulate a process in GEKKO that is bounded by hard limits (like 0%-100%)?

Jonas
  • 121,568
  • 97
  • 310
  • 388

1 Answers1

1

Unlike the MPC, the PID controller is not an optimization-based algorithm. If you simulate the PID controller, OP is not a decision variable that can be limited by the 'lb' and 'ub'.
You also may want to use a Gekko simulation mode (imode=4 or 7) as you simulate the PID controller.

OP value is a result of the PID calculation. So, you need to let PID calculate the OP value regardless of the physical limitation. Then, you add the additional conditions to deal with the physical limits as below. You also need to add the anti-windup (reset integral) logic as well.

if OP[i]>=100: # upper limit
    OP[i] = 100.0
    I[i] = I[i-1] # reset integral
if OP[i]<=0: # lower limit
    OP[i] = 0.0
    I[i] = I[i-1] # reset integral
Junho Park
  • 997
  • 4
  • 12
  • 1
    Thank you for the comment and code. Does this mean that there is _not_ a way to simulate PID control using GEKKO? The index-based `OP[i]` clipping code that you provided could be applied after `m.solve()`, but any changes made to OP would invalidate the solution of PV. Am I misunderstanding something basic here? – William Radigan Dec 17 '20 at 22:33
  • PID equation can always return the OP value bigger or smaller than the actual control valve size, 0 -100%. We would call that "Valve saturation". The lines of code here (OP clipping) are to simulate this physical situation. This is how the PID controller works. The valve saturation can occur more often when the PID tuning isn't acceptable or the valve sizing fails. – Junho Park Dec 18 '20 at 04:33
  • You can use GEKKO for PID simulation like the example code, but you can only do it with Gekko simulation mode, not the optimization mode because there is no optimization happening in the PID control. – Junho Park Dec 18 '20 at 04:47