Buildings.Controls.OBC.Utilities
Package with utility functions
Information
This package contains utility blocks, base classes and validation models for the OpenBuildingControl (OBC) library.
Package Content
Name  Description 

OptimalStart  Block that outputs the optimal start time for an HVAC system before occupancy 
PIDWithInputGains  P, PI, PD, and PID controller with output reset and input gains 
SetPoints  Package with blocks for setpoint resets 
Validation  Collection of validation models 
BaseClasses  Package with base classes 
Buildings.Controls.OBC.Utilities.OptimalStart
Block that outputs the optimal start time for an HVAC system before occupancy
Information
This block predicts the shortest time for an HVAC system to meet the occupied setpoint
prior to the scheduled occupancy. The block requires inputs of zone temperature,
occupied zone setpoint(s) and next occupancy. The two outputs are the optimal start
duration tOpt
and the optimal start on signal optOn
for
the HVAC system.
The block estimates the thermal mass of a zone using its measured air temperature gradient with respect to time. Once the temperature slope of a zone is known, the optimal start time can be calculated by the difference between the zone temperature and the occupied setpoint divided by the temperature slope, assuming the zone responds as if all thermal mass were concentrated in the room air.
The temperature slope is selftuned based on past data. The moving
average of the temperature slope of the past nDay
days
is calculated and used for
the prediction of the optimal start time in the current day.
Parameters
The parameter nDay
is used to compute the moving average of the temperature
slope; the first n
days of simulation is therefore used to
initialize the block.
The parameter
tOptMax
is the maximum allowed optimal start time.
The block includes two hysteresis parameters uLow
and uHigh
.
The parameter
uLow
is used to determine if the zone temperature reaches
the setpoint. The algorithm assumes that the zone temperature has reached the setpoint if
TSetZonHeaTZon ≤ uLow
for a heating system, or
TZonTSetZonCoo ≤ uLow
for a cooling system, where
TSetZonHea
denotes the zone heating setpoint during occupancy, TSetZonCoo
denotes the zone cooling setpoint during occupancy, and TZon
denotes the
zone temperature.
The parameter
uHigh
is used by the algorithm to determine if there is a need to
start the HVAC system prior to occupancy. If
TSetZonHeaTZon ≤ uHigh
for heating case or
TZonTSetZonCoo ≤ uHigh
for cooling case,
then there is no need for the system to start before the occupancy.
The optimal start is only active (i.e., the optimal start on signal optOn
becomes true) if the optimal start time is larger than the parameter
thrOptOn
.
Configuration for HVAC systems
The block can be used for heating system only or cooling system only or for both
heating and cooling system.
The two parameters computeHeating
and computeCooling
are
used to configure the block for these three scenarios.
The block calculates the optimal start time separately for heating and cooling systems. The base class Buildings.Controls.OBC.Utilities.BaseClasses.OptimalStartCalculation is used for the calculation.
Algorithm
The algorithm is as follows:
Step 1: Calculate temeperature slope TSlo
Once the HVAC system is started, a timer records the time duration
Δt
for the zone temperature to reach the
setpoint. At the time when the timer starts, the zone temperature TSam1
is sampled.
The temperature slope is
approximated using the equation TSlo = TSetZonOccTSam1/Δt
,
where TSetZonOcc
is the occupied zone setpoint. Note that if
Δt
is greater than the maximum optimal start time tOptMax
,
then tOptMax
is used instead of Δt
.
This is to avoid corner cases where the setpoint is never reached, e.g., the HVAC
system is undersized, or there is a steadystate error associated with the HVAC control.
Step 2: Calculate temperature slope moving average TSloMa
After computing the temperature slope of each day, the moving average of the
temperature slope TSloMa
during the previous nDay
days
is calculated. Please refer to
Buildings.Controls.OBC.CDL.Discrete.TriggeredMovingMean for details about
the moving average algorithm.
Step 3: Calculate optimal start time tOpt
Each day at a certain time before the occupancy, the algorithm takes another
sample of the zone temperature, denoted as TSam2
. The sample
takes place tOptMax
prior to occupancy start time.
The optimal start time is then calculated as tOpt = TSetZonOccTSam2/TSloMa
.
Validation
Validation models can be found in the package Buildings.Controls.OBC.Utilities.Validation.
Parameters
Type  Name  Default  Description 

Real  tOptMax  10800  Maximum optimal start time [s] 
Integer  nDay  3  Number of previous days used to compute the optimal start up time 
Boolean  computeHeating  false  Set to true to compute optimal start for heating 
Boolean  computeCooling  false  Set to true to compute optimal start for cooling 
Real  uLow  0  Threshold to determine if the zone temperature reaches the occupied setpoint, must be a nonnegative number [K] 
Real  uHigh  0.5  Threshold to determine the need to start the HVAC system before occupancy, must be greater than uLow [K] 
Real  thrOptOn  60  Threshold time, optimal start on signal becomes true when tOpt larger than thrOptOn [s] 
Connectors
Type  Name  Description 

input RealInput  TSetZonHea  Zone heating setpoint temperature during occupancy [K] 
input RealInput  TZon  Zone temperature [K] 
input RealInput  TSetZonCoo  Zone cooling setpoint temperature during occupancy [K] 
input RealInput  tNexOcc  Time until next occupancy [s] 
output RealOutput  tOpt  Optimal start time duration of HVAC system [s] 
output BooleanOutput  optOn  Outputs true if the HVAC system remains in the optimal start period 
Modelica definition
Buildings.Controls.OBC.Utilities.PIDWithInputGains
P, PI, PD, and PID controller with output reset and input gains
Information
PID controller in the standard form
y_{u} = k/r (e(t) + 1 ⁄ T_{i} ∫ e(τ) dτ + T_{d} d⁄dt e(t)),
with output reset, where y_{u} is the control signal before output limitation, e(t) = u_{s}(t)  u_{m}(t) is the control error, with u_{s} being the set point and u_{m} being the measured quantity, k is the gain, T_{i} is the time constant of the integral term, T_{d} is the time constant of the derivative term, r is a scaling factor, with default r=1. The scaling factor should be set to the typical order of magnitude of the range of the error e. For example, you may set r=100 to r=1000 if the control input is a pressure of a heating water circulation pump in units of Pascal, or leave r=1 if the control input is a room temperature.
Note that the units of k are the inverse of the units of the control error, while the units of T_{i} and T_{d} are seconds.
The actual control output is
y = min( y_{max}, max( y_{min}, y)),
where y_{min} and y_{max} are limits for the control signal.
This block is identical to Buildings.Controls.OBC.CDL.Reals.PIDWithReset, except that the controller gains k, T_{i} and T_{d} are inputs rather than parameters.
P, PI, PD, or PID action
Through the parameter controllerType
, the controller can be configured
as P, PI, PD or PID controller. The default configuration is PI.
Reverse or direct action
Through the parameter reverseActing
, the controller can be configured to
be reverse or direct acting.
The above standard form is reverse acting, which is the default configuration.
For a reverse acting controller, for a constant set point,
an increase in measurement signal u_m
decreases the control output signal y
(Montgomery and McDowall, 2008).
Thus,

for a heating coil with a twoway valve, leave
reverseActing = true
, but 
for a cooling coil with a twoway valve, set
reverseActing = false
.
If reverseAction=false
, then the error e above is multiplied by 1.
Antiwindup compensation
The controller antiwindup compensation is as follows: Instead of the above basic control law, the implementation is
y_{u} = k (e(t) ⁄ r + 1 ⁄ T_{i} ∫ (Δy + e(τ) ⁄ r) dτ + T_{d} ⁄ r d⁄dt e(t)),
where the antiwindup compensation Δy is
Δy = (y_{u}  y) ⁄ (k N_{i}),
where N_{i} > 0 is the time constant for the antiwindup compensation. To accelerate the antiwindup, decrease N_{i}.
Note that the antiwindup term (Δy + e(τ) ⁄ r) shows that the range of the typical control error r should be set to a reasonable value so that
e(τ) ⁄ r = (u_{s}(τ)  u_{m}(τ)) ⁄ r
has order of magnitude one, and hence the antiwindup compensation should work well.
Reset of the controller output
Whenever the value of boolean input signal trigger
changes from
false
to true
, the controller output is reset by setting
y
to the value of the parameter y_reset
.
Approximation of the derivative term
The derivative of the control error d ⁄ dt e(t) is approximated using
d⁄dt x(t) = (e(t)x(t)) N_{d} ⁄ T_{d},
and
d⁄dt e(t) ≈ N_{d} (e(t)x(t)),
where x(t) is an internal state.
Guidance for tuning the control gains
The parameters of the controller can be manually adjusted by performing closed loop tests (= controller + plant connected together) and using the following strategy:
 Set very large limits, e.g., set y_{max} = 1000.

Select a Pcontroller and manually enlarge the parameter
k
(the total gain of the controller) until the closedloop response cannot be improved any more. 
Select a PIcontroller and manually adjust the parameters
k
andTi
(the time constant of the integrator). The first value ofTi
can be selected such that it is in the order of the time constant of the oscillations occurring with the Pcontroller. If, e.g., oscillations in the order of 100 seconds occur in the previous step, start withTi=1/100
seconds. 
If you want to make the reaction of the control loop faster
(but probably less robust against disturbances and measurement noise)
select a PIDcontroller and manually adjust parameters
k
,Ti
,Td
(time constant of derivative block). 
Set the limits
yMax
andyMin
according to your specification. 
Perform simulations such that the output of the PID controller
goes in its limits. Tune
Ni
(N_{i} T_{i} is the time constant of the antiwindup compensation) such that the input to the limiter block (=lim.u
) goes quickly enough back to its limits. IfNi
is decreased, this happens faster. IfNi
is very large, the antiwindup compensation is not effective and the controller works bad.
References
R. Montgomery and R. McDowall (2008). "Fundamentals of HVAC Control Systems." American Society of Heating Refrigerating and AirConditioning Engineers Inc. Atlanta, GA.
Parameters
Type  Name  Default  Description 

SimpleController  controllerType  Buildings.Controls.OBC.CDL.T...  Type of controller 
Real  r  1  Typical range of control error, used for scaling the control error 
Boolean  reverseActing  true  Set to true for reverse acting, or false for direct acting control action 
Limits  
Real  yMax  1  Upper limit of output 
Real  yMin  0  Lower limit of output 
Integrator reset  
Real  y_reset  xi_start  Value to which the controller output is reset if the boolean trigger has a rising edge 
Advanced  
Integrator antiwindup  
Real  Ni  0.9  Ni*Ti is time constant of antiwindup compensation 
Derivative block  
Real  Nd  10  The higher Nd, the more ideal the derivative block 
Initialization  
Real  xi_start  0  Initial value of integrator state 
Real  yd_start  0  Initial value of derivative output 
Connectors
Type  Name  Description 

input RealInput  u_s  Connector for setpoint input signal 
input RealInput  u_m  Connector for measurement input signal 
input RealInput  k  Connector for control gain signal 
input RealInput  Ti  Connector for time constant signal for the integral term [s] 
input RealInput  Td  Connector for time constant signal for the derivative term [s] 
output RealOutput  y  Connector for actuator output signal 
input BooleanInput  trigger  Resets the controller output when trigger becomes true 