Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses

Package with base classes

Information

This package contains base classes to construct blocks in Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.

Package Content

Name Description
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.HalfPeriodRatio HalfPeriodRatio Calculate the half period ratio of a response of a relay controller
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.NormalizedTimeDelay NormalizedTimeDelay Calculate the normalized time delay of the response of a relay controller
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.OnOffPeriod OnOffPeriod Calculate the lengths of the on period and the off period
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.SamplerWithResetThreshold SamplerWithResetThreshold Sampler with a reset and a threshold
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.TuningMonitor TuningMonitor Monitor the tuning process
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.Validation Validation Collection of validation models

Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.HalfPeriodRatio Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.HalfPeriodRatio

Calculate the half period ratio of a response of a relay controller

Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.HalfPeriodRatio

Information

This block calculates the half-period ratio of the output from a relay controller.

ρ = max(ton,toff)/ min(ton,toff),

where ton and toff are the lengths of the on period and the off period, respectively. An On period is defined as the period when the relay switch output of the relay controller is true. Likewise, an Off period is defined as the period when the relay switch output is false. See details of the relay switch output in Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.Controller.

References

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

Connectors

TypeNameDescription
input RealInputtOnLength for the on period [s]
input RealInputtOffLength for the off period [s]
input BooleanInputTunEndTrue: the tuning process ends
output RealOutputrhoReal signal of the half period ratio

Modelica definition

block HalfPeriodRatio "Calculate the half period ratio of a response of a relay controller" Buildings.Controls.OBC.CDL.Interfaces.RealInput tOn( final quantity="Time", final unit="s", min=100*Buildings.Controls.OBC.CDL.Constants.eps) "Length for the on period"; Buildings.Controls.OBC.CDL.Interfaces.RealInput tOff( final quantity="Time", final unit="s", min=100*Buildings.Controls.OBC.CDL.Constants.eps) "Length for the off period"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput TunEnd "True: the tuning process ends"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput rho "Real signal of the half period ratio"; protected Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler tOnSam( final y_start=Buildings.Controls.OBC.CDL.Constants.eps) "Block that samples tOn when the tuning period ends"; Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler tOffSam( final y_start=Buildings.Controls.OBC.CDL.Constants.eps) "Block that samples tOff when the tuning period ends"; Buildings.Controls.OBC.CDL.Reals.Min mintOntOff "Block that finds the smaller one between the length for the on period and the length for the off period"; Buildings.Controls.OBC.CDL.Reals.Max maxtOntOff "Block that finds the larger one between the length for the on period and the length for the off period"; Buildings.Controls.OBC.CDL.Reals.Divide halPerRat "Block that calculates the half period ratio"; equation connect(tOnSam.u, tOn); connect(tOffSam.u, tOff); connect(tOnSam.y, maxtOntOff.u1); connect(maxtOntOff.u2, tOffSam.y); connect(mintOntOff.u2, tOffSam.y); connect(maxtOntOff.y, halPerRat.u1); connect(halPerRat.u2, mintOntOff.y); connect(halPerRat.y, rho); connect(tOnSam.y, mintOntOff.u1); connect(tOnSam.trigger, TunEnd); connect(TunEnd, tOffSam.trigger); end HalfPeriodRatio;

Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.NormalizedTimeDelay Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.NormalizedTimeDelay

Calculate the normalized time delay of the response of a relay controller

Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.NormalizedTimeDelay

Information

This block calculates the normalized time delay of the output from a relay controller.

τ = (γ - ρ)/(γ - 1)/(ρ*0.35+0.65),

where γ and ρ are the asymmetry level of the relay controller and the half-period ratio, respectively.

References

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

Parameters

TypeNameDefaultDescription
Realgamma4Asymmetry level of the relay controller

Connectors

TypeNameDescription
input RealInputrhoHalf period ratio
input BooleanInputinTunCheck if the tuning is ongoing
output RealOutputtauNormalized time delay

Modelica definition

block NormalizedTimeDelay "Calculate the normalized time delay of the response of a relay controller" parameter Real gamma(min=1+1E-6) = 4 "Asymmetry level of the relay controller"; Buildings.Controls.OBC.CDL.Interfaces.RealInput rho "Half period ratio"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput inTun "Check if the tuning is ongoing"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput tau "Normalized time delay"; protected Buildings.Controls.OBC.CDL.Reals.AddParameter addPar1( final p=-1) "Block that calculates the difference between gamma and 1"; Buildings.Controls.OBC.CDL.Reals.AddParameter addPar2( final p=0.65) "Block that calculates the sum of the two inputs"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant asyLev( final k=gamma) "Asymmetry level of the relay controller"; Buildings.Controls.OBC.CDL.Reals.Divide div "Block that calculates the normalized time delay"; Buildings.Controls.OBC.CDL.Reals.Subtract subGamRho "Block that calculates the difference between the asymmetry level of the relay controller and the half period ratio"; Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai( final k=0.35) "Gain for the half period ratio"; Buildings.Controls.OBC.CDL.Reals.Multiply mul "Block that calculates the product of the two inputs"; Buildings.Controls.OBC.CDL.Utilities.Assert assMes( final message="Warning: the asymmetry level of the relay controller is lower than the half period ratio. Increase the asymmetry level.") "Warning message when asymmetry level is less than the half period ratio"; Buildings.Controls.OBC.CDL.Reals.Greater gre( final h=1e-6) "Output true if the asymmetry level is greater than the half period ratio"; Buildings.Controls.OBC.CDL.Logical.Or or2 "Enable the assert to check the asymmetry level"; Buildings.Controls.OBC.CDL.Logical.Not and1 "Disable the assert when the tuning is not ongoing"; equation connect(subGamRho.u1, asyLev.y); connect(subGamRho.u2, rho); connect(gai.u, rho); connect(div.u1, subGamRho.y); connect(div.u2, mul.y); connect(div.y, tau); connect(gai.y, addPar2.u); connect(addPar2.y, mul.u2); connect(addPar1.u, asyLev.y); connect(addPar1.y, mul.u1); connect(asyLev.y, gre.u1); connect(rho, gre.u2); connect(gre.y, or2.u1); connect(and1.u, inTun); connect(and1.y, or2.u2); connect(or2.y, assMes.u); end NormalizedTimeDelay;

Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.OnOffPeriod Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.OnOffPeriod

Calculate the lengths of the on period and the off period

Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.OnOffPeriod

Information

This block processes a relay switch output and calculates the length of the on period, tOn, and the length of the off period, tOff, as shown below.

image

Note that tOn is sampled when the relay switch output becomes false. Likewise, tOff is sampled when the relay switch output becomes true.

References

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

Connectors

TypeNameDescription
input RealInputtimSimulation time [s]
input BooleanInputonRelay switch signal
input BooleanInputtriggerReset the output when trigger becomes true
output RealOutputtOffLength for the off period [s]
output RealOutputtOnLength for the on period [s]

Modelica definition

block OnOffPeriod "Calculate the lengths of the on period and the off period" Buildings.Controls.OBC.CDL.Interfaces.RealInput tim( final quantity="Time", final unit="s") "Simulation time"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput on "Relay switch signal"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput trigger "Reset the output when trigger becomes true"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput tOff( final quantity="Time", final unit="s", min=100*Buildings.Controls.OBC.CDL.Constants.eps) "Length for the off period"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput tOn( final quantity="Time", final unit="s", min=100*Buildings.Controls.OBC.CDL.Constants.eps) "Length for the on period"; protected Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler timOn "Simulation time when the input signal becomes on (True)"; Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler timOff "Simulation time when the input signal becomes off (False)"; Buildings.Controls.OBC.CDL.Reals.Subtract lenOffCal "Block that calculates the horizon length for the off period"; Buildings.Controls.OBC.CDL.Reals.Subtract lenOnCal "Block that calculates the horizon length for the on period"; Buildings.Controls.OBC.CDL.Logical.Not not1 "True: the relay output switch to false"; Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.SamplerWithResetThreshold timOnRec( final lowLim=0, final y_reset=0) "Sample the on time"; Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.SamplerWithResetThreshold timOffRec( final lowLim=0, final y_reset=0) "Sample the off time"; equation connect(lenOffCal.u1, timOn.y); connect(lenOnCal.u2, timOn.y); connect(lenOnCal.u1, timOff.y); connect(lenOffCal.u2, timOff.y); connect(timOn.u, tim); connect(timOff.u, tim); connect(timOn.trigger, on); connect(not1.u, on); connect(not1.y, timOff.trigger); connect(timOnRec.y, tOn); connect(timOffRec.y, tOff); connect(lenOnCal.y, timOnRec.u); connect(lenOffCal.y, timOffRec.u); connect(timOnRec.trigger, trigger); connect(timOffRec.trigger, trigger); end OnOffPeriod;

Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.SamplerWithResetThreshold Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.SamplerWithResetThreshold

Sampler with a reset and a threshold

Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.SamplerWithResetThreshold

Information

This block samples the input real signal u when u is larger than a threshold. On the other hand, when the input boolean signal trigger becomes true, the output y is reset to a default value.

Parameters

TypeNameDefaultDescription
ReallowLim1Lower limit for triggering the sampling
Realy_reset1The value of y when the reset occurs

Connectors

TypeNameDescription
input RealInputuInput real signal
input BooleanInputtriggerReset the output when trigger becomes true
output RealOutputySampling output

Modelica definition

block SamplerWithResetThreshold "Sampler with a reset and a threshold" parameter Real lowLim = 1 "Lower limit for triggering the sampling"; parameter Real y_reset = 1 "The value of y when the reset occurs"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u "Input real signal"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput trigger "Reset the output when trigger becomes true"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Sampling output"; protected Buildings.Controls.OBC.CDL.Reals.Sources.Constant thr(final k=lowLim) "Threshold"; Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler yRec( final y_start=y_reset) "Record the input when sampling is triggered"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant reset( final k=y_reset) "Reset value"; Buildings.Controls.OBC.CDL.Logical.Or samTri "Sampling trigger"; Buildings.Controls.OBC.CDL.Reals.Greater gre "Check if the input signal is larger than the threshold"; Buildings.Controls.OBC.CDL.Reals.Switch swi "Switch between sampling the input signal and the reset value"; Buildings.Controls.OBC.CDL.Logical.Edge edgRes( final pre_u_start=false) "Detect if the reset is triggered"; Buildings.Controls.OBC.CDL.Logical.Edge edgThr( final pre_u_start=false) "Detect if the threshold is exceeded"; equation connect(yRec.y, y); connect(thr.y, gre.u2); connect(gre.u1, u); connect(yRec.u, swi.y); connect(edgRes.u, trigger); connect(edgRes.y, swi.u2); connect(swi.u3, u); connect(swi.u1, reset.y); connect(samTri.u2, edgRes.y); connect(samTri.y, yRec.trigger); connect(edgThr.y, samTri.u1); connect(edgThr.u, gre.y); end SamplerWithResetThreshold;

Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.TuningMonitor Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.TuningMonitor

Monitor the tuning process

Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.BaseClasses.TuningMonitor

Information

This block detects when a PID tuning period should start and end. Specifically, the tuning period is triggered to begin when either tOn or tOff becomes greater than 0. The tuning period is triggered to end when either tOn or tOff changes after the tuning period starts, as illustrated below:

image

References

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

Connectors

TypeNameDescription
input RealInputtOnLength for the on period [s]
input RealInputtOffLength for the off period [s]
output BooleanOutputtriStaA boolean signal, true if the tuning starts
output BooleanOutputtriEndA boolean signal, true if the tuning completes

Modelica definition

block TuningMonitor "Monitor the tuning process" constant Modelica.Units.SI.Time minHorLen = Buildings.Controls.OBC.CDL.Constants.eps "Minimum value for horizon length, used to guard against rounding errors"; Buildings.Controls.OBC.CDL.Interfaces.RealInput tOn( final quantity="Time", final unit="s", min=100*Buildings.Controls.OBC.CDL.Constants.eps) "Length for the on period"; Buildings.Controls.OBC.CDL.Interfaces.RealInput tOff( final quantity="Time", final unit="s", min=100*Buildings.Controls.OBC.CDL.Constants.eps) "Length for the off period"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput triSta "A boolean signal, true if the tuning starts"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput triEnd "A boolean signal, true if the tuning completes"; protected Buildings.Controls.OBC.CDL.Reals.Max tMax "Maximum value of the length for the on and Off period "; Buildings.Controls.OBC.CDL.Reals.Greater greThr "Check if either the length for the on period or the length for the off period are larger than 0"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant minLen( final k=minHorLen) "Minimum value for the horizon length"; Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler samAddtOntOff "Sample the minimum period when the minimum period is greater than 0"; Buildings.Controls.OBC.CDL.Reals.Greater tInc "Check if either the length for the on period or the length for the off period increases after they both become positive"; Buildings.Controls.OBC.CDL.Reals.Add addtOntOff "Block that calculates the sum of the length for the on period and the length for the off period"; Buildings.Controls.OBC.CDL.Reals.Greater tDec "Check if either the length for the on period or the length for the off period decreases after they both become positive"; Buildings.Controls.OBC.CDL.Logical.Or tCha "Block that checks if the length for the on period or the length for the off period changes"; Buildings.Controls.OBC.CDL.Logical.Edge edgTunSta "Detect if the tuning process starts"; Buildings.Controls.OBC.CDL.Logical.Edge edgTunEnd "Detect if the tuning process ends"; Buildings.Controls.OBC.CDL.Reals.Multiply mul "Calculate the product of two inputs"; Buildings.Controls.OBC.CDL.Reals.Min tMin "Minimum value of the length for the on and Off period"; Buildings.Controls.OBC.CDL.Reals.Greater greThr1 "Check if both the length for the on period and the length for the off period are larger than 0"; Buildings.Controls.OBC.CDL.Reals.Subtract sub "Find the input difference"; Buildings.Controls.OBC.CDL.Reals.Subtract sub1 "Find the input difference"; equation connect(tMax.u1, tOn); connect(tMax.u2, tOff); connect(addtOntOff.u2, tOff); connect(addtOntOff.u1, tOn); connect(edgTunSta.y, triSta); connect(tCha.y, edgTunEnd.u); connect(edgTunEnd.y, triEnd); connect(tMin.u1, tOn); connect(tMin.u2, tOff); connect(greThr.y, edgTunSta.u); connect(greThr1.y, samAddtOntOff.trigger); connect(addtOntOff.y, mul.u1); connect(mul.u2, tMin.y); connect(samAddtOntOff.u, mul.y); connect(tInc.y, tCha.u1); connect(tDec.y, tCha.u2); connect(samAddtOntOff.y, sub.u2); connect(mul.y, sub.u1); connect(samAddtOntOff.y, sub1.u1); connect(mul.y, sub1.u2); connect(tMax.y, greThr.u1); connect(tMin.y, greThr1.u1); connect(minLen.y, greThr.u2); connect(minLen.y, greThr1.u2); connect(sub.y, tInc.u1); connect(sub1.y, tDec.u1); connect(minLen.y, tInc.u2); connect(minLen.y, tDec.u2); end TuningMonitor;