• No results found

7.1 Introduction

7.4.2 Cost Function

The cost function, or objective function, is used to obtain the optimal control law. While the cost function can be any of a number of forms, the general aim is that the future system output should follow a determined reference signal for the considered horizon (Camacho & Bordons 2013).

In previous studies on the application of MPC to ventilation systems a range of cost functions have been used. For example, Ferreira et al. (2012) used a very simple cost function, which essentially represented the energy consumption by calculating the differ- ence between the outdoor temperature and setpoint for switching on the HVAC. Such cost functions have a clear goal, which has obvious physical meaning, e.g. minimising energy consumption or minimising periods of unacceptable IEQ. However, such formulations leave little flexibility to fine tune controller performance. For example, penalising the amount of control effort.

In this study the aim was to investigate the ability of MPC to maintain comfortable internal temperatures and minimise overheating. To achieve this a cost function designed for output reference tracking was used.

In the MATLAB Model Predictive Control Toolbox there are two cost functions which can be utilised as a measure of controller performance to be minimised. In this work the cost function used is an adapted version of the MATLAB “Standard Cost Function”:

126 7.4. Predictive Controller

J (zk) = Jy(zk) + J∆u(zk) + J(zk) (7.1)

where:

zk is the optimal control inputs

Jy(zk) is the output reference tracking

J∆u(zk) is the manipulated variable move suppression (control effort)

J(zk) is the constraint violation

The individual components of the cost function are described in the subsequent sections.

Output Reference Tracking

In this application of MPC, the main aim of the controller is to keep the internal tem- perature at or near a chosen setpoint. During occupied hours, 22 ◦C was chosen as the temperature. This fixed setpoint was used for the full year of simulation. Various simula- tions were carried out and impact of varying prediction and control horizons, parameter weights etc. was investigated. Future investigation could utilise a varying setpoint based upon the adaptive comfort standards (CIBSE 2013).

The output reference tracking term is given by:

Jy(zk) = ny X j=1 p X i=1 wy i,j syj [rj(k + i|k) − yj(k + i|k)] 2 (7.2) where:

k is the current control interval

p is the prediction horizon (i.e. the number of intervals) ny is the number of plant output variables

zk is the optimal control inputs

rj(k +i|k) is the reference value for the jth plant output at the ith prediction horizon

step (in engineering units)

yj(k + i|k) is the predicted value of the jth plant output at the ith prediction horizon

step (in engineering units)

syj is the scale factor for the jth plant output (in engineering units)

wyi,j is the tuning weight for the jth plant output at the ith prediction horizon step (dimensionless)

Chapter 7. Demonstrating Model Predictive Control 127

The tuning weight wyi,jis a time-varying weight. This allows the importance of maintaining the setpoint temperature to be varied at different times. In this case, it was used to disregard the setpoint temperature during unoccupied hours.

Manipulated Variable Move Suppression

In the standard cost function used by the MPC controller in MATLAB the manipulated variable (MV) move suppression term is used to limit the size of the MV adjustments (moves). This is because in a number of applications it is preferable to have small adjust- ments. In terms of the control of automated windows in a naturally ventilated building this is unlikely to be required. Furthermore, the inclusion of a penalty for large movements could even result in a controller which is slow to react.

While the size of the MV adjustment is not an issue in the control of natural ventilation the number of transitions between window states could be. Not only can frequent actuations of automated windows prove irritating for building occupants (due to the noise of the actuators) but also the service life of actuators must be considered.

The move suppression term is given by:

J∆u(zk) = ρ∆uM Vtrans (7.3)

where:

zk is the optimal control inputs

ρ∆u is the manipulated variable move suppression penalty weight (dimensionless)

M Vtrans is the number of manipulated variable transitions

Constraint Violation

In MPC constraints can be placed upon both input and output values (discussed further in Section 7.4.3). When applying a MPC controller to a real system, some degree of constraint violation may be unavoidable. Softening constraints allows the optimiser to determine a solution in situations where constraint violation cannot be prevented. The cost function quantifies the worst case constraint violation using the variable k. The

performance measure is given by:

J(zk) = ρ2k (7.4)

where:

zk is the optimal control inputs

128 7.4. Predictive Controller

ρ is the constraint violation penalty weight (dimensionless)

7.4.3 Constraints

One of the reasons for the success of MPC is the ability to handle constraints. Constraints can be placed upon both inputs and plant output.

As was mentioned in the previous section, it is not always possible to satisfy all of the constraints. In some cases it will be mathematically impossible for the optimiser to solve the control decision without violating constraints. If this was the case and the constraints were hard, i.e. they had to be satisfied by the optimiser, the solution is infeasible and the controller is likely to return an error. Most MPC controllers deal with this by not changing the manipulated variables, so their state remains the same as in the previous timestep. However, if this infeasibility continues it will result in a loss of control. Therefore, the constraints are relaxed, or softened (Maciejowski 2002, Rawlings & Mayne 2009).

Constraints were placed upon the plant output variable, i.e. zone temperature. During occupied hours the output is constrained to between 18 and 26 ◦C. Due to the nature of natural ventilation it is necessary that this constraint is soft, as at times it may not be possible to maintain a zone temperature within these limits (particularly with regards to the upper limit). Softening this constraint also allows the controller to sacrifice some constraint violation for an overall better performance. During unoccupied hours this constraint was further softened. This allows the controller more freedom and the potential to pre-cool the space.

The constraint upon the zone temperature during occupied hours is not strictly required. The output variable reference tracking term in the cost function (Section 7.4.2) would perform a similar role. By aiming to keep the output close to a setpoint it will implicitly aim to maintain a temperature within the wider limits imposed by the output variable constraints. However, the use of output variable constraints in addition to a reference tracking term in the cost function was found to give greater flexibility and tuneability. This is achieved by adjusting the tuning weight within the output reference tracking term, the softness of the output variable constraints and the constraint violation penalty weight. This allows for refining the balance between keeping the zone temperature close to the optimum and allowing greater movement within and beyond the output constraints. To soften the constraints, a relaxation factor was used. Following the methodology used by the MATLAB MPC Toolbox the parameter could be varied between 0 and 20, with 0 meaning no violation allowed (i.e. a hard constraint) and 20 meaning large violation allowed. Tuning of constraints was done manually based upon controller performance. Hard constraints were placed upon the manipulated variable (opening percentage) as this must clearly remain in the 0-100% range. Hard constraints could also be used to ensure that windows did not open at specific times. This would be applicable if there were security concerns and windows needed to be closed or have a limited opening during unoccupied hours. In this study, no such constraints were utilised. The predominate reason for this

Chapter 7. Demonstrating Model Predictive Control 129

was to allow the controller the maximum amount of freedom and the potential to utilise night cooling. Furthermore, the particular zone being controlled is on the first floor of the building, as such the opening of automated windows during unoccupied hours is likely to be allowed.

In this study, the building simulation did not include heating as the focus was primarily overheating in summer. To prevent the space from dropping too low during unoccupied periods a ”very hard” soft constraint was used to prevent the zone temperature going below 10 ◦C. The constraint of 10 ◦C was used as a typical value for the purpose of plant and fabric protection during unoccupied periods. No hard constraints were placed upon plant output. The reason for using a ”very hard” soft constraint in place of a hard constraint, is to prevent problems caused by unexpected constraint violations. It is possible that prediction errors or disturbances could cause a hard constraint to be violated (this is much more likely in a real building than in a simulation). This can lead to the controller becoming unable to find a feasible solution.

7.4.4 Optimiser

The optimisation process is used to find the sequence of control inputs which minimises the cost function. Nonlinear optimisation is a vast field of study and there is a number of possible methods which can be used for the optimisation process in NMPC. For example: Sequential Quadratic Programming (SQP) (Dhoodhat 2014, Diehl et al. 2009, Li & Li 2015, Martinsen et al. 2004), Genetic Algorithms (Al-Duwaish & Naeem 2001, Potoˇcnik & Grabec 2002), Particle Swarm Optimisation (PSO) (Dhoodhat 2014, Mercieca & Fabri 2011, 2012, Sandou & Olaru 2009) etc.

For this study, SQP was chosen as the optimisation method. According to Boggs & Tolle (1995), “Sequential Quadratic Programming (SQP) has arguably become the most successful method for solving nonlinearly constrained optimization problems”. SQP has been shown to be effecient in both small and largescale problems, and can handle linear and nonlinear constraints (Nocedal & Wright 2006). Furthermore SQP has previously been used successfully in MPC applications where neural networks were used as the predictive model (Akyurek et al. 2009, Lawry´nczuk 2007, Li & Li 2015).

SQP solves constrained nonlinear problems by forming a quadratic approximation of the cost function. This results in a Quadratic Programming (QP) subproblem, the result of which is then used to define the next iteration. A full description of SQP can be found in Nocedal & Wright (2006) and Gr¨une & Pannek (2011).

The specific optimisation algorithm used in this study is the MATLAB function fmincon (MathWorks 2016), which is included in the Optimization Toolbox. The fmincon function includes a gradient based implementation of SQP. As such, it is susceptible to problems with local minima.

130 7.5. Implementation of MPC Controller

Figure 7.4: Example of the shift method for initialisation of subsequent timesteps. Control actions from the optimal solution at time t are shifted one step forward. To maintain a vector of the correct size the final value is duplicated and appended to the vector.

7.5

Implementation of MPC Controller

This section provides a brief description of the three main stages in the MPC control algorithm. Further information, specifically relating to the nmpc.m algorithm upon which this work is based, can be found in Nocedal & Wright (2006).

7.5.1 Initialisation

The algorithm’s first step is to initialise all of the variables required to solve the optimal control problem. This includes the control and prediction horizons, initial input states, control input values and any constraints.

The initial value for the control input is specified by the user. For subsequent iterations the nmpc.n algorithm uses a technique called the “shift method” to determine starting values for the control vector (Diehl et al. 2009, Nocedal & Wright 2006). Using this technique, the optimal sequence of control actions, determined by the optimiser, is stored and used as the starting point for the following timestep. As the first control action will have already been applied to the plant, the control actions are shifted forward by one timestep. To maintain a vector of the correct size, the final control action is duplicated and appended to the vector (see Figure 7.4).

The shifted solution is unlikely to be the optimal for the new timestep. Unless the pre- diction model is very accurate and there are no disturbances. However, particularly in problems with systems which are slow to react and controllers which utilise long prediction horizons, it can be expected to be a good initial guess for the new solution (Diehl et al. 2009). By using techniques such as shift initialisation the computational time taken by the optimisation process can be reduced, as such is often incorporated into MPC controllers (Biegler & Rawlings 1991, Li & Biegler 1990, Mayne et al. 2000).

7.5.2 Optimisation

The second stage in the nmpc.m algorithm is solving the optimal control problem. This stage is responsible for the majority of the computational effort when executing the algo- rithm. The optimal control problem is solved by transforming it into a static nonlinear

Chapter 7. Demonstrating Model Predictive Control 131

Thermal Mass Prediction Horizon (hours)

Time above 25 ◦C (hours) Max Temp (◦C)

MPC RBC MPC RBC Low 1 48 1361 529 1310 30.6 29.2 31.3 Medium 1 48 882 245 905 29.7 27.8 30.7 High 1 48 143 21 151 27.4 25.8 27.6

Table 7.1: Overheating for different thermal mass scenarios using 1 and 48 hour prediction horizons compared to RBC simulation results.

optimisation problem, which is then solved using the fmincon SQP optimisation function (see Section 7.4.4).

The SQP method is iterative, at each iteration it solves a quadratic programming problem to determine the optimal control strategy to minimise the cost function. Before imple- menting the control action, the sequence of optimal control inputs is stored so that it can be used to initialise the optimisation problem at the subsequent timestep.