Buildings.Controls.OBC.Utilities.PIDWithAutotuning

Package with blocks for PID autotuning

Information

This package contains blocks for the PID controller that tune their control gains automatically.

Package Content

Name Description
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.FirstOrderAMIGO FirstOrderAMIGO Autotuning PID controller with an AMIGO tuner that employs a first-order system model
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.AutoTuner AutoTuner Package with blocks for PID autotuners
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay Relay Package with blocks for a relay controller
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.SystemIdentification SystemIdentification Package with blocks for identifying a system model of the control process
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types Types Package with type definitions
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Validation Validation Collection of models that validate the blocks for autotuning PID controllers

Buildings.Controls.OBC.Utilities.PIDWithAutotuning.FirstOrderAMIGO Buildings.Controls.OBC.Utilities.PIDWithAutotuning.FirstOrderAMIGO

Autotuning PID controller with an AMIGO tuner that employs a first-order system model

Buildings.Controls.OBC.Utilities.PIDWithAutotuning.FirstOrderAMIGO

Information

This block implements a PI or PID controller with the control gains being tuned by a rule-based method. This rule-based method automatically conducts tuning through the following steps:

Step 1: Introduce a relay disturbance

Step 2: Extract parameters of a first-order plus time-delay (FOPTD) model

Step 3: Calculate the PID gains

This block is implemented using Buildings.Controls.OBC.Utilities.PIDWithInputGains and inherits most of its configuration. However, through the parameter controllerType, the controller can only be configured as PI or PID controller.

Autotuning process

Before the tuning process starts, this block has output from Buildings.Controls.OBC.Utilities.PIDWithInputGains. The PID tuning process starts when a request for performing autotuning occurs, i.e., when the value of the boolean input signal triTun changes from false to true. During the tuning process, the block has the output from a relay controller (see Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.Controller). The PID tuning process ends automatically (see details in Buildings.Controls.OBC.Utilities.PIDWithAutotuning.BaseClasses.Relay.TunMonitor), at which point this block reverts the output from the PID controller that uses the tuned PID parameters.

Note:

Guidance for setting the parameters

The performance of the autotuning is determined by several parameters, including the typical range of the control error r, the reference output for the tuning process yRef, the higher and lower values for the relay output yHig and yLow, and the deadband deaBan. These parameters must be specified on a case-by-case basis. To set them, the user should conduct the following steps.

Step 1: Conduct a "test run"

Step 2: Calculate yRef and deaBan

Step 3: Determine yHig and yLow

References

J. Berner (2017). "Automatic Controller Tuning using Relay-based Model Identification." Department of Automatic Control, Lund University.

Parameters

TypeNameDefaultDescription
SimpleControllercontrollerTypeBuildings.Controls.OBC.Utili...Type of controller
Realr1Typical range of control error, used for scaling the control error
RealyHig Higher value for the relay output
RealyLow Lower value for the relay output
RealdeaBan Deadband for holding the relay output
RealyRef Reference output for the tuning process. It must be between yLow and yHig
BooleanreverseActingtrueSet to true for reverse acting, or false for direct acting control action
RealsetHys0.05*rHysteresis for checking set point
Initial control gains, used prior to first tuning
Realk_start1Gain of controller used before the first tuning
RealTi_start0.5Time constant of integrator block used before the first tuning [s]
RealTd_start0.1Time constant of derivative block used before the first tuning [s]
Limits
RealyMax1Upper limit of output
RealyMin0Lower limit of output
Integrator reset
Realy_resetxi_startValue to which the controller output is reset if the boolean trigger has a rising edge
Advanced
Integrator anti-windup
RealNi0.9Ni*Ti is time constant of anti-windup compensation
Derivative block
RealNd10The higher the Nd, the more ideal the derivative block
Initialization
Realxi_start0Initial value of integrator state
Realyd_start0Initial value of derivative output

Connectors

TypeNameDescription
input RealInputu_sConnector of set point input signal
input RealInputu_mConnector of measurement input signal
input BooleanInputtriResConnector for resetting the controller output
input BooleanInputtriTunConnector for starting the autotuning
output RealOutputyConnector for actuator output signal

Modelica definition

block FirstOrderAMIGO "Autotuning PID controller with an AMIGO tuner that employs a first-order system model" parameter Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController controllerType= Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController.PI "Type of controller"; parameter Real k_start( final min=100*Buildings.Controls.OBC.CDL.Constants.eps)=1 "Gain of controller used before the first tuning"; parameter Real Ti_start(unit="s")=0.5 "Time constant of integrator block used before the first tuning"; parameter Real Td_start(unit="s")=0.1 "Time constant of derivative block used before the first tuning"; parameter Real r( final min=100*Buildings.Controls.OBC.CDL.Constants.eps)=1 "Typical range of control error, used for scaling the control error"; parameter Real yHig( final min = 0, final max = 1) "Higher value for the relay output"; parameter Real yLow( final min = 0, final max = 1) "Lower value for the relay output"; parameter Real deaBan( final min=1E-6) "Deadband for holding the relay output"; parameter Real yRef "Reference output for the tuning process. It must be between yLow and yHig"; parameter Real yMax = 1 "Upper limit of output"; parameter Real yMin = 0 "Lower limit of output"; parameter Real Ni( final min=100*Buildings.Controls.OBC.CDL.Constants.eps)=0.9 "Ni*Ti is time constant of anti-windup compensation"; parameter Real Nd( final min=100*Buildings.Controls.OBC.CDL.Constants.eps)=10 "The higher the Nd, the more ideal the derivative block"; parameter Real xi_start=0 "Initial value of integrator state"; parameter Real yd_start=0 "Initial value of derivative output"; parameter Boolean reverseActing=true "Set to true for reverse acting, or false for direct acting control action"; parameter Real y_reset=xi_start "Value to which the controller output is reset if the boolean trigger has a rising edge"; parameter Real setHys = 0.05*r "Hysteresis for checking set point"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u_s "Connector of set point input signal"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u_m "Connector of measurement input signal"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput triRes "Connector for resetting the controller output"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput triTun "Connector for starting the autotuning"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Connector for actuator output signal"; Buildings.Controls.OBC.Utilities.PIDWithInputGains con( final controllerType=conTyp, final r=r, final yMax=yMax, final yMin=yMin, final Ni=Ni, final Nd= Nd, final xi_start=xi_start, final yd_start=yd_start, final reverseActing=reverseActing, final y_reset=xi_start) "PI or P controller with the gains as inputs"; Buildings.Controls.OBC.Utilities.PIDWithAutotuning.AutoTuner.AMIGO.PID PIDPar if with_D "Autotuner of gains for a PID controller"; Buildings.Controls.OBC.Utilities.PIDWithAutotuning.AutoTuner.AMIGO.PI PIPar if not with_D "Autotuner of gains for a PI controller"; Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.Controller rel( final r=r, final yHig=yHig, final yLow=yLow, final deaBan=deaBan, final reverseActing=reverseActing) "Relay controller"; Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.ResponseProcess resPro( final yHig=yHig - yRef, final yLow=yRef - yLow) "Identify the on and off period length, the half period ratio, and the moments when the tuning starts and ends"; Buildings.Controls.OBC.Utilities.PIDWithAutotuning.SystemIdentification.FirstOrderTimeDelay.ControlProcessModel conProMod( final yHig=yHig - yRef, final yLow=yRef - yLow, final deaBan=deaBan) "Calculates the parameters of a first-order time delayed model"; Buildings.Controls.OBC.CDL.Logical.Latch inTunPro "Outputs true if the controller is conducting the autotuning process"; protected final parameter Boolean with_D=controllerType == Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController.PID "Boolean flag to enable derivative action"; final parameter Buildings.Controls.OBC.CDL.Types.SimpleController conTyp= if controllerType==Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController.PI then Buildings.Controls.OBC.CDL.Types.SimpleController.PI else Buildings.Controls.OBC.CDL.Types.SimpleController.PID "Type of controller"; Buildings.Controls.OBC.CDL.Reals.Sources.CivilTime modTim "Simulation time"; Buildings.Controls.OBC.CDL.Reals.Switch swi "Switch between a PID controller and a relay controller"; Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler samk( final y_start=k_start) "Recording the proportional control gain"; Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler samTi( final y_start=Ti_start) "Recording the integral time"; Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler samTd( final y_start=Td_start) if with_D "Recording the derivative time"; Buildings.Controls.OBC.CDL.Utilities.Assert assMes2( final message="The relay output needs to be asymmetric. Check the value of yHig, yLow and yRef.") "Warning message when the relay output is symmetric"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant con1(final k=yHig) "Higher value for the relay output"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant con2(final k=yRef) "Reference value for the relay output"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant con3(final k=yLow) "Lower value for the relay output"; Buildings.Controls.OBC.CDL.Reals.Subtract sub "Difference between the higher value and the reference value of the relay output"; Buildings.Controls.OBC.CDL.Reals.Subtract sub1 "Difference between the reference value and the lower value of the relay output"; Buildings.Controls.OBC.CDL.Reals.Subtract sub2 "Symmetricity level of the relay output"; Buildings.Controls.OBC.CDL.Reals.Abs abs1 "Absolute value"; Buildings.Controls.OBC.CDL.Reals.Greater gre "Check if the relay output is asymmetric"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant con4(final k=1e-3) "Threshold for checking if the input is larger than 0"; Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter yRel( final k=yMax - yMin) "Relay output multiplied by the possible range of the output"; Buildings.Controls.OBC.CDL.Logical.Nand nand "Check if an autotuning is ongoing while a new autotuning request is received"; Buildings.Controls.OBC.CDL.Utilities.Assert assMes1( final message="A new tuning request is ignored as the autotuning is ongoing.") "Warning message when an autotuning tuning is ongoing while a new autotuning request is received"; Buildings.Controls.OBC.CDL.Logical.Edge edgReq "True only when a new request is received"; Buildings.Controls.OBC.CDL.Logical.TrueDelay tunStaDel( final delayTime=0.001) "A small time delay for the autotuning start time to avoid false alerts"; Buildings.Controls.OBC.CDL.Reals.AddParameter addPar( final p=yMin) "Sums the inputs"; Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler sam_u_s(final y_start=0) "Recording the set point. Not that y_start does not influence the tuning."; Buildings.Controls.OBC.CDL.Logical.Nand nand1 "Check if an autotuning is ongoing while the set point changes"; Buildings.Controls.OBC.CDL.Reals.Subtract sub3 "Change of the set point"; Buildings.Controls.OBC.CDL.Reals.Abs abs2 "Absolute value of the set point change"; Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr( final t=setHys, final h=0.5*setHys) "Check if the set point changes"; Buildings.Controls.OBC.CDL.Utilities.Assert assMes3( final message="The set point must not change when an autotuning tuning is ongoing. This ongoing autotuning will be aborted and the control gains will not be changed.") "Warning message when the set point changes during tuning process"; Buildings.Controls.OBC.CDL.Logical.FallingEdge falEdg "Check if the set point changes during an autotuning process"; Buildings.Controls.OBC.CDL.Logical.Or or2 "Check if the autotuning is completed or aborted"; Buildings.Controls.OBC.CDL.Logical.And and2 "Check if an autotuning is completed with no error"; equation connect(con.u_s, u_s); connect(con.trigger, triRes); connect(samk.y,con. k); connect(con.Ti, samTi.y); connect(samTd.y,con. Td); connect(resPro.on, rel.yOn); connect(modTim.y, resPro.tim); connect(resPro.tau, conProMod.tau); connect(conProMod.tOff, resPro.tOff); connect(resPro.tOn, conProMod.tOn); connect(rel.yDif, conProMod.u); connect(PIDPar.kp, conProMod.k); connect(PIDPar.T, conProMod.T); connect(PIDPar.L, conProMod.L); connect(PIDPar.Ti, samTi.u); connect(PIPar.kp, conProMod.k); connect(PIPar.T, conProMod.T); connect(PIPar.L, conProMod.L); connect(PIPar.k, samk.u); connect(PIPar.Ti, samTi.u); connect(resPro.triSta, conProMod.triSta); connect(swi.y, y); connect(u_m,con. u_m); connect(swi.u3,con. y); connect(inTunPro.y, swi.u2); connect(inTunPro.u, triTun); connect(rel.trigger, triTun); connect(resPro.trigger, triTun); connect(nand.y, assMes1.u); connect(nand.u2, edgReq.y); connect(edgReq.u, triTun); connect(tunStaDel.y, nand.u1); connect(tunStaDel.u, inTunPro.y); connect(con1.y, sub.u1); connect(con2.y, sub.u2); connect(sub1.u1, con2.y); connect(sub1.u2, con3.y); connect(sub.y, sub2.u1); connect(sub1.y, sub2.u2); connect(abs1.u, sub2.y); connect(abs1.y, gre.u1); connect(gre.y, assMes2.u); connect(con4.y, gre.u2); connect(rel.y, yRel.u); connect(yRel.y, addPar.u); connect(addPar.y, swi.u1); connect(rel.u_m, u_m); connect(rel.u_s, u_s); connect(sam_u_s.u, u_s); connect(sam_u_s.y, sub3.u1); connect(sub3.u2, u_s); connect(sub3.y, abs2.u); connect(nand1.y, assMes3.u); connect(greThr.y, nand1.u1); connect(sam_u_s.trigger, triTun); connect(abs2.y, greThr.u); connect(nand1.u2, triTun); connect(falEdg.u, nand1.y); connect(falEdg.y, or2.u1); connect(resPro.triEnd, or2.u2); connect(or2.y, inTunPro.clr); connect(conProMod.triEnd, resPro.triEnd); connect(PIDPar.k, samk.u); connect(PIDPar.Td, samTd.u); connect(conProMod.tunSta, and2.u2); connect(and2.y, samk.trigger); connect(samTi.trigger, and2.y); connect(samTd.trigger, and2.y); connect(and2.u1, nand1.y); connect(resPro.inTun, inTunPro.y); connect(conProMod.inTun, inTunPro.y); end FirstOrderAMIGO;