Collection of models that illustrate model use and test models
Information
This package contains examples for the use of models that can be found in
Buildings.Controls.Continuous.
Extends from Modelica.Icons.ExamplesPackage (Icon for packages containing runnable examples).
Package Content
Name |
Description |
LimPID
|
Test model for PID controller with optional reverse action |
LimPIDWithReset
|
Example that demonstrates the controller output reset |
NumberOfRequests
|
Example model for block that outputs the number of requests |
OffTimer
|
Example model for off timer |
PIDHysteresis
|
Example model for PID controller with hysteresis |
PIDHysteresisTimer
|
Example model for PID controller with hysteresis and timer |
SignalRanker
|
Example model for signal ranker |
Test model for PID controller with optional reverse action
Information
This model tests the implementation of the
PID controller with optional reverse action.
The model limPIDOri
is the original
implementation of the controller from the Modelica
Standard Library. The models limPID
and limPIDRev
are the implementations
from the Buildings library. The model
limPIDRev
is parameterized to have
reverse action.
The assertion blocks test whether the results
of all three controllers are identical.
Extends from Modelica.Icons.Example (Icon for runnable examples).
Modelica definition
model LimPID
extends Modelica.Icons.Example;
Modelica.Blocks.Sources.Pulse pulse(period=0.25);
Buildings.Controls.Continuous.LimPID limPID(
controllerType=Modelica.Blocks.Types.SimpleController.PID,
Ti=1,
Td=1,
yMax=1,
yMin=-1,
initType=Modelica.Blocks.Types.InitPID.InitialState);
Buildings.Controls.Continuous.LimPID limPIDRev(
controllerType=Modelica.Blocks.Types.SimpleController.PID,
reverseAction=true,
Ti=1,
Td=1,
yMax=1,
yMin=-1,
initType=Modelica.Blocks.Types.InitPID.InitialState)
;
Modelica.Blocks.Sources.Constant const(k=0.5);
Modelica.Blocks.Math.Gain gain(k=-1);
Buildings.Utilities.Diagnostics.AssertEquality assertEquality(
threShold=1e-3);
Modelica.Blocks.Continuous.LimPID limPIDOri(
controllerType=Modelica.Blocks.Types.SimpleController.PID,
Ti=1,
Td=1,
yMax=1,
yMin=-1,
initType=Modelica.Blocks.Types.InitPID.InitialState);
Buildings.Utilities.Diagnostics.AssertEquality assertEquality1(
threShold=1e-3);
equation
connect(pulse.y, limPID.u_s);
connect(pulse.y, limPIDRev.u_s);
connect(const.y, limPID.u_m);
connect(const.y, limPIDRev.u_m);
connect(limPIDRev.y, gain.u);
connect(gain.y, assertEquality.u2);
connect(limPID.y, assertEquality.u1);
connect(pulse.y, limPIDOri.u_s);
connect(const.y, limPIDOri.u_m);
connect(assertEquality1.u1, limPIDOri.y);
connect(assertEquality1.u2, limPID.y);
end LimPID;
Example that demonstrates the controller output reset
Information
Example that demonstrates the effect
of the integrator reset.
The top model has the reset of the controller output enabled.
By plotting the controller error, one sees that the integrator reset
improves the closed loop performance slightly.
Note, however, that both controllers have an integrator anti-windup
and hence the integrator reset has limited benefits.
Extends from Modelica.Icons.Example (Icon for runnable examples).
Modelica definition
model LimPIDWithReset
extends Modelica.Icons.Example;
Plant plaWitRes ;
Controller conWitRes(reset=Buildings.Types.Reset.Parameter)
;
Plant plaNoRes ;
Controller conNoRes(reset=Buildings.Types.Reset.Disabled)
;
Modelica.Blocks.Sources.Pulse TSet(
amplitude=20,
width=50,
offset=293.15,
y(unit="K"),
period=180) ;
protected
model Plant
extends Modelica.Blocks.Icons.Block;
Modelica.Blocks.Interfaces.RealInput Q_flow(unit="W")
;
Modelica.Blocks.Interfaces.RealOutput T(unit="K")
;
Modelica.Thermal.HeatTransfer.Components.HeatCapacitor cap(
C=10,
T(fixed=true,
start=293.15)) ;
Modelica.Thermal.HeatTransfer.Components.HeatCapacitor cap1(
C=10,
T(fixed=true,
start=293.15)) ;
Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor temSen
;
Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow preHea
;
Modelica.Thermal.HeatTransfer.Components.ThermalConductor theCon(G=5)
;
Buildings.HeatTransfer.Sources.FixedTemperature TBou(T=293.15)
;
Modelica.Thermal.HeatTransfer.Components.ThermalConductor theCon1(G=1)
;
equation
connect(Q_flow, preHea.Q_flow);
connect(T, temSen.T);
connect(TBou.port, theCon.port_a);
connect(cap.port, theCon1.port_a);
connect(theCon1.port_b, cap1.port);
connect(cap1.port, temSen.port);
connect(theCon.port_b, cap.port);
connect(preHea.port, cap.port);
end Plant;
model Controller
extends Modelica.Blocks.Icons.Block;
parameter Buildings.Types.Reset reset=Buildings.Types.Reset.Disabled
;
Modelica.Blocks.Interfaces.RealInput TSet(unit="K") ;
Modelica.Blocks.Interfaces.RealInput u_m(unit="K")
;
Modelica.Blocks.Interfaces.RealOutput y
;
Buildings.Controls.Continuous.LimPID conPID(
final reset=reset,
yMax=1,
yMin=0,
controllerType=Modelica.Blocks.Types.SimpleController.PI,
Ti=1,
k=10) ;
Modelica.Blocks.Math.Gain gain(k=5000)
;
Modelica.Blocks.Logical.GreaterThreshold trigger(threshold=303.15)
;
equation
connect(conPID.y,gain. u);
connect(trigger.y,conPID. trigger);
connect(u_m, conPID.u_m);
connect(conPID.u_s, TSet);
connect(trigger.u, TSet);
connect(gain.y, y);
end Controller;
equation
connect(plaWitRes.T, conWitRes.u_m);
connect(conWitRes.y, plaWitRes.Q_flow);
connect(plaNoRes.T, conNoRes.u_m);
connect(conNoRes.y, plaNoRes.Q_flow);
connect(TSet.y, conWitRes.TSet);
connect(TSet.y, conNoRes.TSet);
end LimPIDWithReset;
Example model for block that outputs the number of requests
Information
Example that demonstrates the use of the block
Buildings.Controls.Continuous.NumberOfRequests.
The parameters of the block are such that the output is incremented
for each input signal that is strictly larger than 0.
The figure below shows the inputs and the output of the block.
Extends from Modelica.Icons.Example (Icon for runnable examples).
Modelica definition
Example model for off timer
Information
Example that demonstrates the use of the model
Buildings.Controls.Continuous.OffTimer.
The input to the two timers are alternating boolean values.
Whenever the input becomes false(=0)
, the timer is reset.
The figures below show the input and output of the blocks.
Extends from Modelica.Icons.Example (Icon for runnable examples).
Modelica definition
Example model for PID controller with hysteresis
Information
Example that demonstrates the use of the PID controller
with hysteresis. The control objective is to keep
the temperature of the energy storage cap
at 40°C.
The controller con
is parameterized to
switch on if the control error is bigger than
eon=1.
The output of the controller remains above ymin=0.3 until the control
error is smaller than eoff=-1, at which
time the controller outputs y=0 until the
control error is again bigger than 1.
The figure below shows the control error
con.feeBac.y
and the control signal
con.y
.
Extends from Modelica.Icons.Example (Icon for runnable examples).
Modelica definition
model PIDHysteresis
extends Modelica.Icons.Example;
Buildings.Controls.Continuous.PIDHysteresis con(
pre_y_start=false,
controllerType=Modelica.Blocks.Types.SimpleController.PI,
yMin=0.3,
Ti=600,
Td=60);
Modelica.Blocks.Sources.Constant TSet(k=273.15 + 40, y(unit="K")) ;
Modelica.Thermal.HeatTransfer.Components.HeatCapacitor cap(C=1000000, T(start=
313.15, fixed=true));
Buildings.HeatTransfer.Sources.PrescribedTemperature TBC;
Modelica.Thermal.HeatTransfer.Components.ThermalConductor theCon(G=20);
Modelica.Blocks.Math.Gain gain(k=2000);
Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor temSen;
Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow Q_flow;
Modelica.Blocks.Sources.Sine sine(
freqHz=1/86400,
offset=273.15,
amplitude=20,
phase=-1.5707963267949,
y(unit="K"));
equation
connect(TSet.y, con.u_s);
connect(TBC.port, theCon.port_a);
connect(theCon.port_b, cap.port);
connect(con.y, gain.u);
connect(cap.port, temSen.port);
connect(temSen.T, con.u_m);
connect(gain.y, Q_flow.Q_flow);
connect(Q_flow.port, cap.port);
connect(sine.y, TBC.T);
end PIDHysteresis;
Example model for PID controller with hysteresis and timer
Information
Example that demonstrates the use of the PID controller
with hysteresis and off timer.
The example is identical to
Buildings.Controls.Continuous.Examples.PIDHysteresis,
except that the controller also has an off timer.
This timer keeps the control signal at y=0
for a period of minOffTime=1000
seconds.
This may be used to avoid short-cycling if the load is small
and the system has little heat capacity.
The figure below shows the control error
con.feeBac.y
and the control signal
con.y
.
Extends from Modelica.Icons.Example (Icon for runnable examples).
Modelica definition
model PIDHysteresisTimer
extends Modelica.Icons.Example;
Buildings.Controls.Continuous.PIDHysteresisTimer con(
yMin=0.3,
minOffTime=10000,
controllerType=Modelica.Blocks.Types.SimpleController.PI,
Ti=60,
Td=10);
Modelica.Blocks.Sources.Constant TSet(k=273.15 + 40, y(unit="K")) ;
Modelica.Thermal.HeatTransfer.Components.HeatCapacitor cap(C=100000, T(start=
293.15, fixed=true));
Buildings.HeatTransfer.Sources.PrescribedTemperature TBC;
Modelica.Thermal.HeatTransfer.Components.ThermalConductor theCon(G=10);
Modelica.Blocks.Math.Gain gain(k=800);
Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor temSen;
Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow Q_flow;
Modelica.Blocks.Sources.Sine sine(
freqHz=1/86400,
offset=273.15,
amplitude=20,
phase=-1.5707963267949);
equation
connect(TSet.y, con.u_s);
connect(TBC.port, theCon.port_a);
connect(theCon.port_b, cap.port);
connect(con.y, gain.u);
connect(cap.port, temSen.port);
connect(temSen.T, con.u_m);
connect(gain.y, Q_flow.Q_flow);
connect(Q_flow.port, cap.port);
connect(sine.y, TBC.T);
end PIDHysteresisTimer;
Example model for signal ranker
Information
Example that demonstrates the use of the signal ranker model.
The figure below shows the input and output signals of the block.
Note that
sigRan.y[1] ≥ sigRan.y[2] ≥ sigRan.y[3]
.
Extends from Modelica.Icons.Example (Icon for runnable examples).
Modelica definition
Plant model
Information
Plant model for
Buildings.Controls.Continuous.Examples.LimPIDWithReset.
consisting of a simple heat transfer model.
Implementation
To compare the effect of the controller output reset, the plant and control
models have been implemented in separate blocks so they can be instantiated
twice in the system model with the appropriate control settings.
Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).
Connectors
Type | Name | Description |
input RealInput | Q_flow | Heat flow rate added to system [W] |
output RealOutput | T | Controlled temperature [K] |
Modelica definition
model Plant
extends Modelica.Blocks.Icons.Block;
Modelica.Blocks.Interfaces.RealInput Q_flow(unit="W")
;
Modelica.Blocks.Interfaces.RealOutput T(unit="K")
;
Modelica.Thermal.HeatTransfer.Components.HeatCapacitor cap(
C=10,
T(fixed=true,
start=293.15)) ;
Modelica.Thermal.HeatTransfer.Components.HeatCapacitor cap1(
C=10,
T(fixed=true,
start=293.15)) ;
Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor temSen
;
Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow preHea
;
Modelica.Thermal.HeatTransfer.Components.ThermalConductor theCon(G=5)
;
Buildings.HeatTransfer.Sources.FixedTemperature TBou(T=293.15)
;
Modelica.Thermal.HeatTransfer.Components.ThermalConductor theCon1(G=1)
;
equation
connect(Q_flow, preHea.Q_flow);
connect(T, temSen.T);
connect(TBou.port, theCon.port_a);
connect(cap.port, theCon1.port_a);
connect(theCon1.port_b, cap1.port);
connect(cap1.port, temSen.port);
connect(theCon.port_b, cap.port);
connect(preHea.port, cap.port);
end Plant;
PID controller with optional output reset
Information
Controller model for
Buildings.Controls.Continuous.Examples.LimPIDWithReset.
The controller is reset whenever the input signal becomes bigger than
30°C.
Implementation
To compare the effect of the controller output reset, the plant and control
models have been implemented in separate blocks so they can be instantiated
twice in the system model with the appropriate control settings.
Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).
Parameters
Type | Name | Default | Description |
Reset | reset | Buildings.Types.Reset.Disabled | Type of controller output reset |
Connectors
Type | Name | Description |
input RealInput | TSet | Temperature set point [K] |
input RealInput | u_m | Measured temperature [K] |
output RealOutput | y | Control signal |
Modelica definition
model Controller
extends Modelica.Blocks.Icons.Block;
parameter Buildings.Types.Reset reset=Buildings.Types.Reset.Disabled
;
Modelica.Blocks.Interfaces.RealInput TSet(unit="K") ;
Modelica.Blocks.Interfaces.RealInput u_m(unit="K")
;
Modelica.Blocks.Interfaces.RealOutput y
;
Buildings.Controls.Continuous.LimPID conPID(
final reset=reset,
yMax=1,
yMin=0,
controllerType=Modelica.Blocks.Types.SimpleController.PI,
Ti=1,
k=10) ;
Modelica.Blocks.Math.Gain gain(k=5000)
;
Modelica.Blocks.Logical.GreaterThreshold trigger(threshold=303.15)
;
equation
connect(conPID.y,gain. u);
connect(trigger.y,conPID. trigger);
connect(u_m, conPID.u_m);
connect(conPID.u_s, TSet);
connect(trigger.u, TSet);
connect(gain.y, y);
end Controller;