如何制定在gekko中寻找最佳PID参数的问题?
how to formulate the problem of finding the optimal PID paramters in gekko?
我已经定义了一个一阶过程模型,并想找到该过程的最佳 PID 参数。优化 objective 是为了最小化 IAE(设定点和过程值之间绝对误差的积分),用于设定点在过程时间常数的 5 倍范围内变化。
它既不是动态优化 (IMODE =6
) 问题,也不是纯稳态优化问题 (IMODE=3
),因为它涉及导数。如何在gekko中表述上述问题?
m = GEKKO(remote=False)
# Controller model
Kc = m.Var(1.0,lb=0.01,ub=10) # controller gain
tauI = m.Var(2.0,lb=0.01,ub=1000) # controller reset time
tauD = m.Var(1.0,lb=0.0,ub=100) # derivative constant
OP = m.Var(value=0.0,lb=0.0,ub=100) # controller output
PV = m.Var(value=0.0) # process variable
SP = 1.0 # set point
Intgl = m.Var(value=0.0) # integral of the error
err = m.Intermediate(SP-PV) # set point error
m.Equation(Intgl.dt()==err) # integral of the error
m.Equation(OP == Kc*(err + (1/tauI)*Intgl + tauD*PV.dt()))
# Process model
Kp = 2 # process gain
tauP = 10.0 # process time constant
m.Equation(tauP*PV.dt() + PV == Kp*OP)
m.Obj((SP-PV)**2) # how to define the objective to minimize the error over a horizon
m.options.IMODE=3
m.solve(disp=False)
print(str(Kc.VALUE))
print(str(tauI.VALUE))
print(str(tauD.VALUE))
print(str(m.options.OBJFCNVAL))
有个video tutorial on simulating (00:00-17:00) and optimizing (17:00-23:41) PID tuning parameters with GEKKO. There is starting code as problem #14 in this list of tutorials.
视频中的要点是切换到 IMODE=6
并为应调整的参数设置 STATUS=1
以尽量减少错误:(SP-PV)**2
.
我已经定义了一个一阶过程模型,并想找到该过程的最佳 PID 参数。优化 objective 是为了最小化 IAE(设定点和过程值之间绝对误差的积分),用于设定点在过程时间常数的 5 倍范围内变化。
它既不是动态优化 (IMODE =6
) 问题,也不是纯稳态优化问题 (IMODE=3
),因为它涉及导数。如何在gekko中表述上述问题?
m = GEKKO(remote=False)
# Controller model
Kc = m.Var(1.0,lb=0.01,ub=10) # controller gain
tauI = m.Var(2.0,lb=0.01,ub=1000) # controller reset time
tauD = m.Var(1.0,lb=0.0,ub=100) # derivative constant
OP = m.Var(value=0.0,lb=0.0,ub=100) # controller output
PV = m.Var(value=0.0) # process variable
SP = 1.0 # set point
Intgl = m.Var(value=0.0) # integral of the error
err = m.Intermediate(SP-PV) # set point error
m.Equation(Intgl.dt()==err) # integral of the error
m.Equation(OP == Kc*(err + (1/tauI)*Intgl + tauD*PV.dt()))
# Process model
Kp = 2 # process gain
tauP = 10.0 # process time constant
m.Equation(tauP*PV.dt() + PV == Kp*OP)
m.Obj((SP-PV)**2) # how to define the objective to minimize the error over a horizon
m.options.IMODE=3
m.solve(disp=False)
print(str(Kc.VALUE))
print(str(tauI.VALUE))
print(str(tauD.VALUE))
print(str(m.options.OBJFCNVAL))
有个video tutorial on simulating (00:00-17:00) and optimizing (17:00-23:41) PID tuning parameters with GEKKO. There is starting code as problem #14 in this list of tutorials.
视频中的要点是切换到 IMODE=6
并为应调整的参数设置 STATUS=1
以尽量减少错误:(SP-PV)**2
.