Python GEKKO for PID Tuning

1.5k Views Asked by At

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%)?

1

There are 1 best solutions below

3
On

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