0% found this document useful (0 votes)
119 views

Manual de AMPL

This document is a reference manual for MPCtools 1.0, a set of Matlab functions that implement a model predictive control (MPC) controller. It describes getting started with MPCtools, background on MPC, linear MPC formulations, quadratic programming algorithms, an overview of MPCtools features, two case studies demonstrating MPCtools, and a command reference for the MPCtools functions. The overall purpose of MPCtools is to enable simulation and analysis of control systems using MPC without requiring knowledge of implementation details.

Uploaded by

cesarmachuca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views

Manual de AMPL

This document is a reference manual for MPCtools 1.0, a set of Matlab functions that implement a model predictive control (MPC) controller. It describes getting started with MPCtools, background on MPC, linear MPC formulations, quadratic programming algorithms, an overview of MPCtools features, two case studies demonstrating MPCtools, and a command reference for the MPCtools functions. The overall purpose of MPCtools is to enable simulation and analysis of control systems using MPC without requiring knowledge of implementation details.

Uploaded by

cesarmachuca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

MPCtools 1.

0 — Reference Manual

Johan Åkesson

Department of Automatic Control


Lund Institute of Technology
January 2006
Contents

1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2. Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3. Model Predictive Control – Background . . . . . . . . . . . . . 6
4. Linear Model Predictive Control . . . . . . . . . . . . . . . . . 7
4.1 Receding horizon control . . . . . . . . . . . . . . . . . . . . . 7
4.2 Model assumptions . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.3 An optimal control problem . . . . . . . . . . . . . . . . . . . . 8
4.4 Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.5 State estimation . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.6 Error-free tracking . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.7 Blocking factors . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.8 Linear properties of the MPC controller . . . . . . . . . . . . 14
5. Quadratic Programming Algorithms . . . . . . . . . . . . . . . 15
6. MPCtools — Overview . . . . . . . . . . . . . . . . . . . . . . . . 16
6.1 A quadratic programming solver . . . . . . . . . . . . . . . . . 17
6.2 MPCtools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
7. Case Studies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
7.1 The quadruple tank . . . . . . . . . . . . . . . . . . . . . . . . 20
7.2 The helicopter process . . . . . . . . . . . . . . . . . . . . . . . 23
8. MPCTools Command Reference . . . . . . . . . . . . . . . . . . 26
MPCinit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
MPCOptimizeSol . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
MPCSim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
MPCController . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
MPCfrsp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
qp_as . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
qp_ip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
getfeasible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
9. References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

3
4
1. Introduction
This report describes a set of Matlab functions, referred to as MPCtools. MPC-
tools implements an MPC controller for use with Matlab/Simulink, with the
following key features:

• Support for linear state space models for prediction


• Quadratic cost function
• Linear inequality constraints on states and controls
• Observer support for state and disturbance estimation
• Integral action by means of disturbance estimation
• Two different QP solvers for solving the optimization problem

The main purpose of MPCtools is to enable users to simulate and analyse control
systems which includes MPC controllers, wihout having to get into the implemen-
tational details. In the development of MPCtools, ease of use has been considered
more important than adding additional features. A limitation of MPCtools is that
no support for stabilizing schemes is given.
MPCtools are primarily intended for research and teaching but is free to use for
all purposes. The author accepts no responsibility for the consequences of using
MPCtools.

2. Getting Started
MPCtools requires no installation or compilation, but it is convenient to add
the directory containing the MPCtools functions to the Matlab path. The cur-
rent distribution contains two application examples, demonstrating the key fea-
tures of MPCtools. Both examples are described in detail in this report, and the
corresponding scripts for setting up the problem and producing plots showing
simulation results are included in the MPCtools distribution.
The following steps shows how to set up the path and how to run the example
scripts.

1 Start Matlab
2 To add the directory containing MPCtools to the Matlab path, enter

>> addpath(’/usr/matlab/MPCtools-1.0’)

assuming that MPCtools reside in the directory /usr/matlab/MPCtools-1.0


3 Enter the quadruple tank example directory by entering

>> cd /usr/matlab/MPCtools-1.0/QuadTank

4 Run the script Simulate_QuadTank_MPC by entering

>> Simulate_QuadTank_MPC

to simulate a linear quadruple tank model controlled by an MPC controller.

5
5 Run the script Simulate_QT_Simulink_MPC by entering

>> Simulate_QT_Simulink_MPC

to simulate a nonlinear quadruple tank model controlled by an MPC controller.


The script utilizes the Simulink model QuadTank_MPC.mdl for simulation.
6 Enter the helicopter example directory by entering

>> cd /usr/matlab/MPCtools-1.0/HelicopterII

7 Run the script Simulate_Helicopter_MPC by entering

>> Simulate_Helicopter_MPC

to simulate a linear nonlinear helicopter model controlled by an MPC con-


troller.

3. Model Predictive Control – Background


The key feature that distinguishes MPC from most other control strategies is the
receding horizon principle. An MPC controller solves, at each sampling instant,
a finite horizon optimal control problem. Only the first value of the resulting
optimal control variable solution is then applied to the plant, and the rest of the
solution is discarded. The same procedure is then repeated at each sampling in-
stant, and the prediction horizon is shifted forward one step. Thereby the name
receding horizon control. This strategy includes solving on-line an optimal con-
trol problem, which enables the controller to deal explicitly with MIMO plants
and constraints. On the downside are the computational requirements. Solving
the optimization problem may introduce computational delay, which, if not con-
sidered, may degrade control performance. Also, MPC is a model based control
strategy, and a model of the process to be controlled is a necessary requirement
for MPC.
Historically, there has been two major selling points for MPC; it works well for
MIMO plants, and it takes constraints into account explicitly. Both these issues
arise frequently in many practical applications, and must be dealt with in order
for a control design to be successful. MPC has been particularly successful in the
area of process control, which is also the field from where MPC originates. Tradi-
tionally, MPC has been mainly applied to plants with slow dynamics, where the
computational delay is small compared to typical sampling intervals. However,
recent reports of MPC applications include plants with fast dynamics, ranging
from air plane control to engine control. For a review of industrial use of MPC,
including a historical review of the evolution of MPC, see [Qin and Badgwell,
2003]
During the last decade, there has been significant research efforts to sort out
the theoretical issues of MPC. Notably, the problem of formulating a stabiliz-
ing MPC scheme has received much attention. As a result, several techniques
to ensure stability have been presented, see [Mayne et al., 2000] for a review.
The theory for MPC based on linear systems is well developed, and strong re-
sults ensuring robust stability exists, see [Maciejowski, 2002] for an overview.
Also, the optimization problem resulting from linear MPC is a Linear Inequality

6
Constrained Quadratic Programming (LICQP) problem, which is a convex opti-
mization problem, and efficient solution algorithms exist. In particular, existence
of a unique global minimum is guaranteed. For non-linear system, there exist
MPC formulations that guarantee stability under mild conditions. However, the
resulting optimization problem is, in general, non-convex and usually no guar-
antee of finding a global minimum exits. Non-linear MPC remains a very active
field of research and recent results have shown that optimality is not a neces-
sary condition for stability, see [Scokaert et al., 1999]. These promising results
show that many non-linear MPC schemes may be stabilizing although finding
the global minimum is difficult.

In this report, Matlab tools for a standard formulation of linear MPC will be
presented. State estimation, error-free tracking and stability are important is-
sues that will be covered in the following. The aim of developing the MPC tools
have been to simulate, in detail, the behavior of an MPC controller. A detailed
analysis of controller behavior also requires understanding of the algorithm used
to solve the LICQP problem. Accordingly, the tools include implementations of
common LICQP algorithms for this purpose.

4. Linear Model Predictive Control


In this section, an MPC formulation based on linear discrete-time state space
models will be described. The presentation is based on [Maciejowski, 2002].

4.1 Receding horizon control


The MPC scheme makes use of the receding horizon principle, illustrated in
Figure 1. At each sample, a finite horizon optimal control problem is solved over
a fixed interval of time, the prediction horizon. We assume that we would like the
controlled variables, z( k), to follow some set point trajectory, r( k). The optimal
control problem is formulated using a cost function penalizing deviations of the
controlled variables as well as variations in the control signal. A common choice
is to use a quadratic cost function, which in combination with a linear system
model yields a finite horizon LQ problem. Figure 1 shows the predicted optimal
trajectories ẑ( k + ip k) and û( k + ip k) starting at time k.

The predictions necessary to solve the optimization problem is obtained using a


model of the controlled system. The prediction of the controlled variable z is per-
formed over an interval with length H p samples. The control signal is assumed
to be fixed after Hu samples. H p and Hu are referred to as the prediction horizon
and the control horizon respectively. The distinction between the prediction and
control horizons is useful since the number of decision variables in the optimiza-
tion problem increases with Hu , but is independent of H p. Normally, Hu < H p
in order to reduce the complexity of the optimization problem.

When the solution of the optimal control problem has been obtained, the value of
the first first control variable in the optimal trajectory, u( kp k), is applied to the
process. The rest of the predicted control variable trajectory is discarded, and at
the next sampling interval the entire procedure is repeated.

7
r( k)

ẑ( k)

z( k)
û( k)
u( k)

k k + Hu k + Hp t
Figure 1 The idea of MPC. Here r ( k) is the set point trajectory, z( k) represents the
controlled output and u( k) the control signal.

4.2 Model assumptions


We assume that a model on the form

x( k + 1) = Ax( k) + Bu( k)
y( k) = Cy x( k)
(1)
z( k) = Cz x( k) + D zu( k)
zc ( k) = Cc x( k) + Dc u( k)

is available. Here y( k) ∈ R py is the measured output, z( k) ∈ R pz the controlled


output and u( k) ∈ R m the input vector. The state vector is x( k) ∈ R n . The
MPC controller should also respect constraints on control variables as well as
the constrained outputs, zc ( k) ∈ R pc

∆ umin ≤ ∆ u( k) ≤ ∆ umax
umin ≤ u( k) ≤ umax (2)
zmin ≤ zc ( k) ≤ zmax

where ∆ u( k) = u( k) − u( k − 1) are the control increments.


The distinction between controlled and constrained variables is natural, since
only the controlled variables have specified reference values. This distinction is
not made in [Maciejowski, 2002], but is quite useful. For example, there may
be plant variables that must respect constraints, without having corresponding
reference values. In some cases the constrained variables may not be included
in the set of measured variables. In this case, an observer can be used to obtain
estimates of such variables. The constraints are then enforced for the estimated
outputs, which may not be equal to the true constrained outputs. The same
argument applies to the controlled outputs, which will be discussed further in
the section dealing with error free tracking.

4.3 An optimal control problem


We will now formulate the optimal control problem that is the core element of

8
the MPC algorithm. Consider the following quadratic cost function:

H p + Hw − 1 H u −1

q ẑ( k + ip k) − r( k + ip k)q2Q + q∆ û( k + ip k)q2R


X X
J ( k) = (3)
i = Hw i=0

where ẑ( k + ip k) are the predicted controlled outputs at time k and ∆ û( k + ip k) are
the predicted control increments. The matrices Q ≥ 0 and R > 0 are weighting
matrices, which are assumed to be constant over the prediction horizon. The
length of the prediction horizon is H p, and the first sample to be included in the
horizon is Hw. Hw may be used to shift the control horizon, but in the following
presentation we will assume that Hw = 0. The control horizon is given by Hu .
In the cost function (3) ∆ u( k) is penalized rather than u( k), which is common
in LQ control. The reason for this is that for a non-zero set point, r( k), the
corresponding steady state control signal u( k) is usually also non-zero. By avoid
penalizing u( k), this conflict is avoided. A different method that has been used
is to introduce a set point also for the control variable, ru ( k), and to penalize
deviations of u( k) from ur . This approach may be implemented in the above
formulation by choosing Cz = 0 and D z = I, and thereby let u( k) be part of the
controlled variables.

The cost function (3) may be rewritten as

2
J ( k) = qZ ( k) − T ( k)qQ + q∆U qR2

where

   
ẑ( kp k) r( kp k)
 ..   .. 
Z ( k) = 
 . 
 T ( k) = 
 . 

ẑ( k + H p − 1p k) r( k + H p − 1p k)
Q 0 ... 0
 
 
∆ u( kp k)
0 Q ... 0 
 
 ..  
∆U ( k) =  .  Q=  .. .. . . .. 
. . . . 
   
∆ u( k + Hu − 1p k)

0 0 ... Q
0 ... 0
 
R
0 R ... 0
 
 
R=  .. .. . . .. 
. . . .
 
 
0 0 ... R

By deriving the prediction expressions, we can write

Z ( k) = Ψ x( k) + Γ u( k − 1) + Θ∆U ( k) (4)

9
where
 
Cz

 Cz A 

Cz A2
 
Ψ = 
..
 
.
 
 
Cz A H p −1
 
Dz

 Cz B + D z 

Cz AB + Cz B + D z
 
Γ = 
..
 
.
 
 
P H p −2 i
Cz i=0 A B + D z
 
Dz 0 ⋅⋅⋅ 0
 
 Cz B + D z Dz 
.. ..
 
. .
 
 Cz AB + Cz B + D z 
.. ..
 
Θ = . . 0
 

 C P Hu − 2 A i B + D
 
 z i=0 z ⋅⋅⋅ Dz 
. ..

.. ..
.
 

 . 

P H p −2 i P H p − Hu−1
Cz i=0 A B + D z ⋅ ⋅ ⋅ Cz i=0 Ai B + D z

Also, let
E ( k) = T ( k) − Ψ x( k) − Γ u( k − 1).
This quantity could be interpreted as the free response of the system, if all the
decision variables at t = k, ∆U ( k), were set to zero. Inserting the prediction
expressions into the cost function (3) we obtain

J ( k) = ∆U T H ∆U − ∆U T G + E T QE (5)

where
G = 2Θ T QE ( k)
H = ΘTQ Θ + R
The problem of minimizing the the cost function (5) is a quadratic programming
(QP) problem. If H is positive definite, the problem is convex, and the solu-
tion may be written on closed form. Positive definiteness of H follows from the
assumption that Q ≥ 0 and R > 0. The solution is given by

1 −1
∆U = H G.
2

Notice that the matrix H −1 does not depend on k, and may be pre-calculated. In
fact, the controller is linear, and may be calculated off-line. This will be discussed
in detail in Section 4.8.

10
4.4 Constraints
Let us now introduce constraints on the constrained and control variables, zc
and u. In general, linear constraints may be expressed as:

W ∆U ( k) ≤ w (6)
FU ( k) ≤ f (7)
GZ c ( k) ≤ˆ (8)
(9)

This formulation allows for very general constraints, but in the following, only
the constraints specified by (2) will be considered. Using (2), we obtain
   
1 0 ⋅⋅⋅ 0 1 0 ⋅⋅⋅ 0
 −1  −1
   
 
.. ..
   
 0 1 .  0 1 .
   
 
−1 −1
   
W=F=   G= 
 . ..  . ..
 
 .. . 0  .. . 0
 
 
   
1 1
   
   
0 ⋅⋅⋅ 0 −1 0 ⋅ ⋅ ⋅ 0 −1
     
∆ umax umax zmax
 −∆ u   −u   −z 
 min   min   min 
 ..   .
..
  .. 
w=
 .  f
 =

 ˆ=
  . 

     
 ∆ umax   umax   zmax 
−∆ umin −umin − zmin

Notice that W and F may not be of the same size as G, though the structure is
the same. Since U ( k) and Z c ( k) are not explicitly included in the optimization
problem, we rewrite the above constraints in terms of ∆U ( k). This gives

−F 1 u( k − 1) + f
   
F
 G Θ c  ∆U ≤  − G (Ψ c x( k) + Γ c u( k − 1)) + ˆ  (10)
   

W w

where  
1 0 ⋅⋅⋅ 0 1
 

 −1 −1
   

..
   
1
 
 1 1 .
   
  
=  −1 −1 −1
 
F   F1 =  
..
 
 . ..

 ..
 
. 0 .
  
  
 
 1 1  1
   
 
−1 ⋅ ⋅ ⋅ −1 −1

The definitions of Ψ c , Θ c and Γ c are equivalent to those of Ψ , Θ and Γ . As


we can see, the left side of the inequality is not dependent on k, and could be
calculated off-line. The right side depends on the last control signal and the

11
present estimation of the state vector, and should thus be evaluated at each
sample.
The optimization problem can now be rewritten using (3) and (10)

min J ( k) = ∆U T H ∆U − ∆U T G + E T QE
subject to Ω∆U ≤ ω
The problem is still recognized as a quadratic programming problem, but now
with linear inequality constraints. The problem is convex, but due to the con-
straints, it is not possible to write the solution on closed form. Rather iterative
algorithms have to be employed. This issue will be discussed further in Section
5

4.5 State estimation


The algorithm for obtaining the optimal control signal at each sample assumes
that the present state vector is available. Since this is often not the case, state
estimation is required. The celebrated separation principle, stating that the op-
timal control and optimal estimation problems solved independently, yields a
globally optimal controller for linear systems, suggests an attractive approach.
We let the solution of the optimization problem be based on an estimate of the
state vector, x̂( k) instead of the true state vector x( k). For this purpose, a Kalman
filter,
x̂( k + 1) = A x̂ ( k) + Bu( k) + K ( y( k) − Cy x̂( k)).
can be used. If the covariance matrices of the states, W, and the measurement
noise, V , are assumed to be known, the gain matrix K may be obtained by solving
an algebraic Riccati equation, see for example [Åström and Wittenmark, 1990].
Apart from estimating the state of the system, an estimator could be used to
estimate disturbances, assuming that a disturbance model is available. For ex-
ample, error-free tracking may be achieved by including a particular disturbance
model in the observer.

4.6 Error-free tracking


In practical applications, there are always modeling errors and disturbances
present. The MPC formulation described above contains no explicit mechanism to
deal with these complications. In order for the controller to be useful in practice,
these problems have to be considered. Commonly, the controller is designed so
that it contains integral action, which ensures zero steady-state error. There are
several methods for achieving integral action in a controller. For SISO systems,
introduction of integral action is quite straight forward. A common approach is
to introduce an integrator state in the state space model:
" # " # " # " #
x( k + 1) A 0 B 0
= x( k) + u( k) + r( k)
xi ( k + 1) − Cz I 0 I
h i
y( k) = Cy 0
h i
z( k) = Cz 0 .

A stabilizing feedback control law may then be calculated based on the extended
model. The integrator state is implemented in the controller, and used for feed-
back together with the true or estimated states. From the definition of the ex-
tended system model, it is clear that in steady state, z = r. This approach does

12
not work so well for MPC controllers. In particular, it is not clear how the in-
tegral state should be introduced in the cost function in order for the integral
action to work properly.
A different approach to achieve integral action is to use a disturbance observer.
In summary, the extended system model

x( k + 1) 0
     
A B x( k) B
v ( k + 1 )   0
= I 0   va ( k)  +  0  u(t)
      
 a
d( k + 1) 0 0 I d( k) 0
h ih iT
z( k) = yz( k) = Cz 0 0 x( k)T va ( k) T
d( k) T

h ih iT
ya ( k) = Ca I 0 x( k)T va ( k)T d( k)T

is used. It is assumed that the number of controlled outputs, z, equals the num-
ber of inputs, u. Additional outputs, if any, are denoted ya . Also, the controlled
variables are assumed to be included in the set of measured variables. A detailed
treatment of this method is given in [Åkesson and Hagander, 2003].

4.7 Blocking factors


In some situations it may be advantageous to let the control signal be fixed over
several consecutive predicted samples. In this way, the control horizon may be
increased without increasing the complexity of the optimization problem. Also,
ringing behavior of the control signal may be avoided. For example, suppose
that the control horizon has to be increased in order to increase closed loop
performance. If the control horizon is increased, the time to solve the optimization
problem will also increase. If this is not acceptable, one approach might be to
include only every other decision variable in the optimization problem, assuming
that the the control signal is fixed over two consecutive sampling intervals. We
denote the set of predicted sample indexes for which the control signal is allowed
to vary by Iu .
In the MPC formulation given above this means that some ∆ û( k + ip k):s are set to
zero for certain i:s. This means that the corresponding columns in the matrices
Θ , W and F may be neglected.
In a similar way it is possible to generalize the prediction horizon. Instead of
including all predicted values in the interval [ k...k + H p − 1], we introduce the
set Ip consisting of all sample indexes for which the corresponding predicted out-
put values are included in the cost function and for which the constraints are
enforced. The last point is critical. It may be tempting to introduce a sparse set of
predicted sampling instants in order to obtain a longer prediction horizon. How-
ever, since the inter-sample behavior is neglected, this may lead to the constraint
in effect being violated at some points.
This generalization is easily introduced by neglecting the rows of the matrices
Ψ , Γ , Θ and G corresponding to sample indexes not present in Ip.
Using the notation introduced above, the cost function may be rewritten as

q ẑ( k + ip k) − r( k + ip k)q2Q + q∆ û( k + ip k)q2R .


X X
J ( k) = (11)
i∈ I p i∈ Iu

13
4.8 Linear properties of the MPC controller
The behavior of the MPC controller is intrinsically nonlinear, since constraints on
state and control variables are taken into account. However, if no constraints are
present in the problem formulation, the controller is linear. Also, the controller
behaves linearly during operation when no constraints are active. In the first
case, the control law, could (and should) be calculated off-line, whereas in the
second case, the optimization procedure must be done each sample. There are
however, methods for avoiding on-line solution of the optimization problem. Using
the observation that the MPC control law is piecewise linear in the states, it is
possible to calculate, off-line, all possible control laws. The on-line optimization
problem is then transformed into a search problem, where the objective is to
find the appropriate partition in the state space, identifying the corresponding
control law. This approach is described in [Bemporad et al., 2002].
We will now analyze the linear properties of the MPC controller. The analysis
is valid for the case when no constraints are present or the controller operates
so that no constraints are active. In this case, the minimizing solution of the
quadratic programming problem is

∆U ( k) = (Θ T Q Θ + R )−1 Θ T QE ( k)
    
I r( k)
  . 
= (Θ T Q Θ + R )−1 Θ T Q   . 
  .  −Γ −Ψ   u( k − 1) 
 

I x̂( k)
 
r( k)
= K̄ s  u( k − 1) 
 

x̂( k)

Now, since only the first of the predicted control signals are applied we can write
the control law as
h iT
∆ u( kp k) = ∆ u( k) = K s r T ( k) uT ( k − 1) x̂T ( k)
h ih iT
= K sr K su K sx r T ( k) uT ( k − 1) x̂ T ( k)

where K s is given by the first m rows of K̄ s . This control law is linear, and
the constant gain matrix K s may be calculated off-line. The block diagram of
the controller may now be drawn as in Figure 2. In this figure, the transfer
function (matrix) of the plant is given by P( z), and Hu ( z) and H y( z) represents
the observer. This block diagram is readily converted into a feedback system on
standard form shown in Figure 3, with

P( z) = Cy( zI − A)−1 B
F ( z) = K sr
H ( z) = − K sx H y( z)
−1
1

z z
K ( z) = I− K su − K sx Hu ( z)
z−1 z−1 z−1
H y( z) = ( zI − A + K Cy)−1 K
Hu ( z) = ( zI − A + K Cy)−1 B

14
r( k) ∆ u( k) u( k) y( k)
z
K sr z−1
I P( z)

K su z−1 I

K sx Hu ( z)

− K sx H y( z)

Figure 2 The block diagram for the MPC controller

r( k) u( k) y( k)
F ( z) K ( z) P( z)

H ( z)

Figure 3 A standard feedback structure.

It is now straight forward to apply standard linear analysis methods. For exam-
ple, the poles and zeros of the closed loop system may be calculated, as well as
the sensitivity of the system.

5. Quadratic Programming Algorithms


An important element of the MPC algorithm described above is the algorithm
for solving the LICQP problem. The problem at hand is

min J ( k) = ∆U T H ∆U − ∆U T G + E T QE
subject to Ω∆U ≤ ω .

This problem has several nice features. For example, the objective function is
convex, since it is quadratic with positive definite Hessian. Also, the constraints
are also convex. Given these conditions, it is a well known result that a local
minimum, if it exists, is also a global minimum. (See for example Theorem 4.3.8
in [Bazaraa et al., 1993].) When designing numerical algorithms, this property
is of course very valuable, since we know in advance that if we find a minimum,
it is indeed a global minimum.

There exist several algorithms for constrained optimization, see for example
[Fletcher, 1987]. For quadratic programming problem the two most common ap-
proaches are primal-dual internal point methods and active set methods [Ma-
ciejowski, 2002].

15
The active set algorithm assumes an initial point in the decision variable space
that fulfills the constraints. The active set is defined as the set of all active con-
straints at this point. A constraint is said to be active if a particular point in
the search space is at the boundary of the feasible region defined by the con-
straint. In the case of linear constraints, these boundary surfaces are given by
hyper-planes. In each iteration step, a quadratic programming problem with lin-
ear equality constraints (namely those in the active set) is solved. The solution
of this problem may be written on closed form. Possibly this solution leads to
the introduction of a new constraint into the active set. By calculating the La-
grange multipliers for the problem at each iteration, it is possible to conclude if
a constraint may be relaxed, that is, removed from the active set. The algorithm
terminates when the gradient of the associated Lagrange function is identically
zero, and all Lagrange multipliers are positive.

One problem remains to deal with; the feasible initial point. In order to start the
active set algorithm, we need a feasible solution, that is, we would like to find
a solution that fulfills the constraints Ω∆U ≤ ω . Of course, such a solution is
not likely to be unique. Several methods exist for obtaining the desired solution.
For example, the problem may be cast as an LP problem, and solved by the
simplex algorithm. Another and possibly more attractive alternative is given in
[Fletcher, 1987]. This strategy employs an active set technique similar to the
one for solving the main quadratic programming problem. However, in this case,
the objective function is defined at each iteration as the sum of the violated
constraint functions.

Primal-dual interior point methods on the other hand, explores the Karush-
Kuhn-Tucker conditions explicitly. The name of this family of QP algorithms
stems from the fact that the primal and the dual problems are solved simultane-
ously. It is important to note however, that the term interior point refers to the
fact that the algorithm maintains a solution in the interior of the dual space.
In fact, the primal solution may not be feasible during the optimization run,
except at the optimal point. This constitutes an important difference between
active set methods and primal-dual interior point methods. Specifically, in the
former case it is possible to terminate the optimization algorithm prematurely
and still obtain a feasible, but sub-optimal, solution whereas in the latter case,
the algorithm may terminate only when the optimal solution is found.

Concerning performance, both methods have advantages and disadvantages when


applied to MPC. Rather, the key to achieve good performance lies in exploring
the special structure of the MPC QP problem. See [Bartlett et al., 2000] for a
comparison between interior point and active set methods.

6. MPCtools — Overview
In this section, Matlab tools implementing the algorithms described in the previ-
ous sections are presented. The main objective for implementing the MPC tools
has been to enable detailed study of the behavior of an MPC controller. In this
section, the functionality of the tools is described briefly, see Section 8 for a
detailed description.

16
6.1 A quadratic programming solver
Obviously, a quadratic programming solver is essential for the implementation
of the MPC controller. A solver of this type is available for example from the
Matlab Optimization Toolbox; quadprog. However, the aim of the development
of the Matlab tools has been to create a complete implementation of an MPC
controller. Since this also includes an algorithm to solve the QP problem, a solver
based on active sets as well as a primal-dual interior point QP solver have been
implemented. In addition, an algorithm for finding an initial feasible solution
for the active set solver has been implemented. The following Matlab functions
implement the necessary algorithms:

• getfeasible
This function obtains a feasible point given the constraints Ax ≤ b. The
algorithm is described in [Fletcher, 1987, p. 166].
• qp_as
This is an active set solver, based on [Fletcher, 1987, p. 240]. The algorithm
finds the solution of the optimization problem

1 T
min x Hx + fTx
2
s.t.
Ax ≤ b

using an initial solution x0 as starting point. The possibility of starting


the algorithm from an initial solution is quite useful when implementing
the MPC controller. Usually, the solution obtained at the previous sample
is a good initial guess, and the number of iterations may be reduced by
supplying this solution to the QP algorithm
• qp_ip
This function solves the same quadratic problem problem as qp_as. The al-
gorithm implements the Mehrotra predictor-corrector primal-dual interior
point method based on [Wright, 1997].

The MPC controller described in the next section enables the user to explore
either quadratic programming method, as well as the Optimization Toolbox func-
tion quadprog.

6.2 MPCtools
The Matlab functions presented in this section implement an MPC controller
as described in Section 4. The tools enable the user to simulate a linear or
nonlinear plant model, with an MPC controller engaged. Most of the features
described in Section 4 are implemented, including constraint handling, observer
support, blocking factors and error-free tracking. Also, a basic tool for analyzing
the linear properties of the controller is supplied.
In summary, the same assumptions as in Section 4 are made for the Matlab
implementation of the MPC controller. We assume that a linear discrete time
model on the form (1), with linear inequality constraints (2) is available. Also,
we assume that the design variables Hw, H p, Hu and the blocking factors are
specified, as well as the weighting matrices Q, R and, if applicable, W and V for
the design of a Kalman filter.

17
An important goal in designing the MPC tools has been to enable the user to
experiment with different configurations of the MPC controller. Consequently,
the MPC tools support several modes of operation:

• Mode 0: State feedback.


• Mode 1: State feedback with explicit integrators.
• Mode 2: Observer-based output feedback.
• Mode 3: Observer-based output feedback with explicit integrators.
• Mode 4: Observer-based output feedback with a disturbance model that
gives error free tracking.

Both state and output feedback is supported. Also, two different strategies for
achieving error-free tracking are provided; explicit integrators and an observer
based solution. Both methods are described in Section 4.
The MPC tools are implemented in five functions:

• MPCInit
Typically, MPCInit is used to initialize the MPC controller. Most of the ma-
trices needed to solve the optimization problem may be calculated off-line in
advance, for example the Hessian of the QP problem. MPCInit implements
pre-processing of matrices, which drastically improves the performance of
the controller.

• MPCSim
MPCSim simulates a linear plant model controlled by the MPC controller.
Reference trajectories as well as input disturbance trajectories can be sup-
plied. The function produces the state and control variable trajectories, as
well as the predicted trajectories for the controlled and control variables.
The latter feature enables the user to examine the predicted solutions ob-
tained at each sample, and explore the effect of different choices of predic-
tion horizons.

• MPCfrsp
As noted in Section 4.8, the MPC controller behaves linearly if no con-
straints are active. It is then interesting to use standard tools for analysis
of linear systems. The function MPCfrsp provides frequency response plots
for relevant transfer functions corresponding to, e.g., the closed loop system
and input and output sensitivity functions.

• MPCOptimizeSol
MPCOptimizeSol is a low level function used by other functions rather than
by the user. This function provides the control signal of the MPC controller
given the current state measurement (or estimation) and reference value.

• MPCController
Most real world plants are nonlinear. It is therefore of interest to investigate
the performance of the linear MPC controller applied to a nonlinear plant
model, if it is available. This functionality is provided by the simulation
environment Simulink for Matlab. The MPC controller has been adapted
to Simulink, and is implemented by a Matlab S-function. The S-function

18
Figure 4 A Simulink model where the MPC controller is used to control a nonlinear
plant.

is a standard block in Simulink, which may in turn be connected to ar-


bitrary blocks. For an example, see Figure 4. The name of the S-function
is MPCController, and is intended for use with the Simulink S-function
block. It takes the argument md, which is a data structure created by the
MPCInit function. The MPCController block takes as its inputs a vector
signal consisting of the measured outputs of the plant and the reference
value. Its output is a vector signal consisting of the control signal u, and
the internal state estimation of the controller, x̂. The latter may, apart from
the estimated states of the plants, also include estimated disturbances or
integrator states.

Using the MPC tools described above, it is possible to simulate, at a high level
of detail, the behavior of an MPC controller. For example, the consequences of
various assumptions regarding measurements, integral action schemes, choice
of QP algorithm and prediction horizons are easily explored. Also, the use of
Simulink significantly increases the applicability of the tools, enabling the user
to simulate the behavior of the MPC controller when applied to nonlinear plants.

19
1 −γ1 1 −γ2

Tank 3 Tank 4

γ1 γ2

Pump 1
Pump 2
Tank 1 Tank 2
u1 u2

Figure 5 A schematic picture of the quadruple tank process

7. Case Studies
In this section, two cases studies are reported, illustrating the main functionality
of the MPC tools.

7.1 The quadruple tank


The quadruple-tank laboratory process, see Figure 5, was originally presented
in [Johansson, 1997]. The process consists of four tanks, organized in pairs (left
and right), where water from the two upper tanks flows into the two lower tanks.
A pump is used to pour water into the upper left tank and the lower right tank.
A valve width fixed position is used to allocate pump capacity to the upper and
lower tank respectively. A second pump is used to pour water into the upper
right tank and lower left tank. The control variables are the pump voltages. Let
the states of the system be defined by the water levels of the tanks (expressed
in cm) x1 , x2 , x3 and x4 respectively. The maximum level of each tank is 20 cm.
The dynamics of the system is given by

a1 p a3 p γ 1 k1
ẋ1 = − 2ˆ x1 + 2ˆ x3 + u1
A2 A1 A1
a2 p a4 p γ 2 k2
ẋ2 = − 2ˆ x2 + 2ˆ x4 + u2
A2 A2 A2
(12)
a3 p (1 − γ 2 ) k2
ẋ3 = − 2ˆ x3 + u2
A3 A3
a4 p (1 − γ 1 ) k1
ẋ4 = − 2ˆ x4 + u1
A4 A4

where the Ai :s and the ai :s represent the cross section area of the tanks and
the holes respectively. The parameters γ i :s determine the position of the valves
which control the flow rate to the upper and lower tanks respectively. The control
signals are given by the the ui :s. The objective is to control the levels of the two

20
Table 1 Parameter values of the Quadraple Tank

Parameters Values Unit


A1 , A2 28 [cm2 ]
A3 , A4 32 [cm2 ]
a1 , a2 0.071 [cm2 ]
a3 , a4 0.057 [cm2 ]
k1 , k2 3.33, 3.35 [cm3 /Vs]
kc 0.50 [V/cm]
ˆ 981 [cm/s2 ]

lower tanks, i.e. x1 and x2 . Numerical values of the parameters are given in Table
1.
An interesting feature of this multivariate process is that the linearized system
has an adjustable zero. By adjusting the parameters γ 1 and γ 2 it is possible
to obtain a zero with negative real part, or a non minimum phase zero with
positive real part. For the simulations, the valve positions were set to γ 1 = 0.30
and γ 2 = 0.30, yielding a non-minimum phase system.
The process is nonlinear, and in order to apply the MPC tools, a linearized model
must be derived. Introducing ∆ x = x − x0 , ∆ u = u − u0 and ∆ y = y − y0, we obtain

− T11
   γ k 
0 A4
A1 T3 0 1 1
A1 0
 0 1 A4 
0 γ 2 k2
0
  
− T 2 A T
 
2 4  ∆x +  A 2

∆ ẋ =  1 (1−γ 2 ) k2  ∆ u

 0 0 − T3 0    0 A3
(13)
  
(1−γ 1 ) k1
0 0 0 − T14 A4 0
" #
kc 0 0 0
∆y = ∆x
0 kc 0 0

where s
Ai 2xi0
Ti = .
ai ˆ
The stationary operating conditions, x0 and u0 , are given in Table 2. The par-
ticular choice of valve positions γ 1 = 0.25 and γ 2 = 0.35 yields a non-minimum
phase system. The measured outputs of the system are the levels of the lower
tanks, represented by a voltage ranging from 0 to 10 V. The objective of the
control system is to control, independently, the level of the lower tanks, while
preventing overflow in any of the four tanks. The maximum level of the tanks
is 20 cm, corresponding to 10 V. In the simulations, the tank level constraints
were set to 19.8 cm to ensure some safety margin. Also, the operation of the
pumps is limited to 0 to 10 V. We notice that the stationary level of the second
tank is close to the maximum level. The combination of a non-minimum phase
system and an operating point close to a constraint yields a quite challenging
control problem, where two of the main benefits of the MPC controller, namely
constraint handling and MIMO support, will be useful. The plant was discretized
using the sampling interval h = 3 s, resulting in a discrete time model used for
the MPC control design.

21
Table 2 Stationary values corresponding to γ 1 = 0.25 and γ 2 = 0.35.

Variables Values Unit


x10 , x20 8.2444, 19.0163 [cm]
x30 , x40 4.3146, 8.8065 [cm]
u01 , u02 3, 3 [V]

Table 3 MPC controller parameters for the Quadruple Tank simulations

Parameter Value
Hp 30
Hw 1
Hu 10
Ip Only every other sample was included
in the optimization problem.
Iu Every other control increment was as-
sumed to be constant.
Q diag(4, 1)
R diag(0.01, 0.01)
W diag(1, 1, 1, 1)/diag(1, 1, 1, 1, 1, 1)
V diag(0.01, 0.01)

Control of the linearized model In Table 3, the controller parameters used


in the simulations are summarized. The choice of prediction and control horizons
have been made considering the time constants of the system. Too short horizons
may cause instability. However, the prediction and control horizons must not be
chosen to large, since it would result in an unnecessarily complex QP problem
to solve at each sample. In order to increase the horizons without increasing the
number of optimization variables, the blocking factor 2 has been specified for
both the control and prediction horizons.

Obviously, since all states are not measurable, an observer must be used. In
the first simulation, controller mode 2 was used: a Kalman filter was designed,
but no mechanism to ensure integral action was assumed. The result of the
simulation is shown in Figure 6, represented by the dashed curves. The dotted
curves represent the set points for the lower tanks. A step change in the set
point of level 1 of size 6 cm is applied at t = 60 s, while the set point of level
2 is held constant. As we can see, the controller achieves the correct set points,
and in particular, the level of tank 2 does not exceed 20 cm. At t = 600 s, a
unit step disturbance is applied to the input channel 2. As expected, the MPC
controller does not manage to achieve error-free tracking in the presence of load
disturbances.

In a second design, control mode 4 was assumed. In this case, the disturbance
observer described in [Åkesson and Hagander, 2003] was used to estimate the
state vector and the disturbance states. The response of the system is identical
to the previous case during the step response. However, the input disturbance is
now rejected.

22
12 10
10 8

h3 [cm]

h4 [cm]
8
6
6
4 4

2 2
0 200 400 600 800 1000 1200 0 200 400 600 800 1000 1200

16 20
h1 [cm] 14 19.5

h2 [cm]
12
19
10
8 18.5

6 18
0 200 400 600 800 1000 1200 0 200 400 600 800 1000 1200

4 8

3
6
u1 [V]

u2 [V]
2
4
1

0 2
0 200 400 600 800 1000 1200 0 200 400 600 800 1000 1200
t [s] t [s]

Figure 6 Simulations of the MPC controller applied to the linearized plant.

Control of the nonlinear model As noted above, the true Quadruple Tank
system is nonlinear. A more realistic scenario would then be to apply the MPC
controller designed above to the nonlinear plant model. The plant model was im-
plemented in Simulink, and an S-function block representing the MPC controller
was connected to the plant model block. The design parameters of the MPC con-
troller were identical to the previous case, see Table 3. Also the same simulation
scenario was assumed. The result of the simulation can be seen in Figure 7. The
dashed curves represent the case when an observer without disturbance states
is employed. As we can see, the controller fails to achieve error-free tracking
even when no disturbances are present, which is due to the fact that there is a
model-mismatch between the linear and the nonlinear plant. Obviously, the con-
troller also fails to compensate fully for the load disturbance. If the disturbance
observer is employed however, the controller gives zero steady-state error. This
is shown by the solid curves. In both cases, however, the controller respects the
constraints: no tank level exceed 20 cm.

7.2 The helicopter process


As an example of a process with fast dynamics, we consider the helicopter process
shown in Figure 8. The helicopter consists of an arm mounted to a base, enabling
the arm to rotate freely. The arm carries the helicopter body on one end and a
counterweight on the other end. The helicopter body consists of a bar connected
to the arm in such a way that it may rotate around the arm axis. To the bar is
connected two propellers, which may be used to maneuver the plant. A schematic
image of the process is shown in Figure 8, where the elevation angle, θ e, measures
the angle of the arm with respect to the horizontal plane, the travel angle, θ r ,
measures the rotational position of the arm and the pitch angle, θ p, measures

23
14 10
12
8
10

h3 [cm]

h4 [cm]
8 6
6
4
4
2 2
0 200 400 600 800 1000 1200 0 200 400 600 800 1000 1200

16 20
14 19.5

h2 [cm]
h1 [cm]

12
19
10
18.5
8
18
6
0 200 400 600 800 1000 1200 0 200 400 600 800 1000 1200

4 8

3
6
u1 [V]

u2 [V]
2
4
1

0 2
0 200 400 600 800 1000 1200 0 200 400 600 800 1000 1200
t [s] t [s]

Figure 7 Simulations of the MPC controller applied to the nonlinear plant.

Table 4 Parameter values of the helicopter process

Parameter Value Unit Description


2
Je 0.91 [kgm ] Moment of inertia about elevation
axis
la 0.66 [ m] Arm length from elevation axis to he-
licopter body
Kf 0.5 Motor Force Constant
Fˆ 0.5 [ N] Differential force due to gravity and
counter weight
Tˆ la Fˆ [Nm] Differential torque
Jp 0.0364 [kgm2 ] Moment of inertia about pitch axis
lh 0.177 [ m] Distance from pitch axis to either mo-
tor
Jt 0.91 [kgm2 ] Moment of inertia about travel axis

the angle of the bar. A simple dynamical model of the system is given by

θ¨ e = ( K f la / J e )( V f + Vb) − Tˆ / J e
θ¨r = −( Fˆ la / Jt ) sin θ p (14)
θ¨ p = ( K f lh / J p)( V f − Vb )

where the coefficients are given in Table 4. The input signals to the system are
V f and Vb which represent the voltages fed to the propeller motors. In addition,
the elevation and pitch angles are constrained, so that

−0.5 ≤ θ e ≤ 0.6 −1 ≤ θ p ≤ 1.

24
Figure 8 The helicopter process.

Table 5 MPC controller parameters for the Helicopter simulations

Parameter Value
Hp 30
Hw 1
Hu 10
Ip Only every other sample was included
in the optimization problem.
Iu Every other control increment was as-
sumed to be constant.
Q diag(1,1)
R diag(0.1,0.1)

The process was linearized around the stationary point


 
θ 0e , θ r0 , θ 0p, V f0 , Vb0 , = 0, 0, 0, Tˆ /(2K f la ), Tˆ /(2K f la )


and then discretized using the sampling interval h = 0.2 s. This gives a discrete-
time state space model of the process to be used to design the MPC controller.
The task of the control system is to control, independently, the elevation angle
and the rotation angle. The main constraint is that the pitch angle must not
be too large, reflecting the fact that for large θ p, the control authority in the
θ e direction is small. This is not accounted for in the linearized model, and the
controller is likely to have degraded performance when θ p is large.
The design parameters of the MPC controller are given in Table 5. Again, the
choice of prediction and control horizons have been made considering the domi-
nating time constants of the system. We also assume that the entire state vector
is measurable, enabling the use of the state feedback configuration of the MPC
controller corresponding to mode 0. In order to achieve fast sampling, (which
requires a QP problem of moderate complexity) while maintaining sufficiently
long prediction and control horizons, the blocking factor 2 was specified for both
horizons.
The result of the simulation when the MPC controller is applied to the nonlinear
plant (14) is shown in Figure 9. Reference trajectories specifying step sequences
for the elevation and rotation angles respectively are applied to the system. As

25
0.4 4

0.3 3

Elevation [rad]

Rotation [rad]
0.2 2

0.1 1

0 0

−0.1 −1
0 10 20 30 0 10 20 30

4
1
3
0.5
2
Pitch [rad]

V , V [V]
b
0 1

f
0
−0.5
−1
−1
−2
0 10 20 30 0 10 20 30
t [s] t [s]

Figure 9 A simulation of the MPC controller applied to the nonlinear helicopter plant.

we can see, the controller manages to track the set points, while keeping the
pitch angle within the specified limits.

8. MPCTools Command Reference


In this section the syntax of MPCtools is described. The tools are intended for use
with Matlab R14, but should work also with Matlab R13. The tools require Con-
trol System Toolbox and, if the Simulink extension is to be used, also Simulink.
The quadratic programming solver quadprog may be used to solve the MPC op-
timization problem, but this feature requires Optimization Toolbox. It is not
necessary in order to use the tools however.

26
MPCinit

Purpose
Initializes the MPC data structure.

Syntax
md = MPCInit(Ad, Bd, Cyd, Czd, Dzd, Ccd, Dcd, Hp,
Hw, zblk, Hu, ublk, du_max, du_min,
u_max, u_min, z_max, z_min, Q, R, W, V,
h, cmode, solver)

Input arguments
Ad, Bd, Cyd System matrices for the plant; Ad , Bd and Cd .
Czd, Dzd Matrices defining the controlled outputs; Cz and D z.
Ccd, Dcd Matrices defining the constrained outputs; Cc and Dc .
Hw, Hp, Hu Integers defining the prediction and control horizons; Hw,
H p and Hu .
zblk, ublk Blocking factors defining the sets Ip and Iu .
u_min, u_max Control variable limits; umin and umax .
du_min, du_max Control increment limits; ∆ umin and ∆ umax .
z_min, z_max Controlled variable limits; zmin and zmax .
Q, R Weighting matrices for the cost function.
W, V Weighting matrices for the Kalman filter design, if
applicable.
h Sampling interval.
cmode Controller mode.
solver Solver to be used for the quadratic programming problem.

Output arguments
md Contains the pre-computed matrices needed by the MPC controller.

Description
MPCInit creates the data structure used by the MPC controller. A discrete time
model, with sampling interval h, of the controlled system is assumed,

x( k + 1) = Ax( k) + Bu( k)
y( k) = Cy x( k)
(15)
z( k) = Cz x( k) + D zu( k)
zc ( k) = Cc x( k) + Dc u( k)

where z( k) are the controlled outputs, y( k) the measured outputs and zc ( k) the
constrained outputs. The constraints of the system are given by

∆ umin ≤ ∆ u( k) ≤ ∆ umax , k ∈ Iu
umin ≤ u( k) ≤ umax , k ∈ Iu (16)
zmin ≤ zc ( k) ≤ zmax , k ∈ Ip

27
where ∆ u( k) = u( k) − u( k − 1) are the control increments. Ip and Iu are the
sets of samples for which the controlled and control variables are included in the
cost function and for which the constraints are enforced. The first sample to be
included in the optimization procedure is Hw, and the total number of samples
in the prediction horizon is H p. The entries in the array z_blk indicates the
time distance between two consecutive predicted samples. Also, the last entry in
z_blk is used as distance between the remaining samples (if length(z_blk) <
H p).

Example
Assume that Hw = 1, H p = 6 and z_blk = [1 2 2 5]. Then the samples [1 2 4 6
11 16] will be included in the cost function evaluation.
Equivalently, Hu indicates the number of predicted control moves to be calculated
at each sample. The array u_blk contains the blocking factors indicating over
which sampling intervals the control signal should be constant. For example, a
blocking factor of 2 indicates that 2 consecutive control signals are equal.

Example
Assume that Hu = 3, u_blk = [1 2]. Then it is assumed that at each sample, for
the predicted control signal, û, we have that û( k + 1) = û( k + 2) and û( k + 3) =
û( k+4). Only û( k), û( k+1) and û( k+3) will be calculated. Q and R are weighting
matrixes for the cost function, where Q penalizes the controlled outputs and R
penalizes control increments. W and V are weighting matrices for the design
of the Kalman filter used to estimate the state and load disturbances. W is the
covariance matrix of the state and V is the covariance matrix of the measurement
noise.
The controller supports several control modes. cmode specifies which mode should
be used. The following modes are supported:

• Mode 0: State feedback


The arguments W and V are not used, and may be set to []. Cy is assumed
to be identity.
• Mode 1: State feedback and explicit integrators
The integrators act the controlled outputs, specified by Cz. The Q-matrix
should be extended to include weights for the integrator states as well as
the controlled outputs. The arguments W and V are not used, and may be
set to [].
• Mode 2: Observer based output feedback
The design of the Kalman filter is based on the covariance matrices W and
V.
• Mode 3: Observer based output feedback with explicit integrators
The integrators act on the controlled outputs, specified by Cz. The Q-matrix
should be extended to include weights for the integrator states as well as
the controlled outputs. The controlled variables should be the same as the
first pz ( pz = dim(z)) measured variables.
• Mode 4: Disturbance observer based output feedback
The disturbance model ensures that the controller achieves error free track-
ing. Constant load disturbances are assumed on the control input, and the

28
system is augmented to include also the disturbance states. If the number
of measured outputs exceed the number of inputs, constant load distur-
bances on the additional measured outputs are assumed. The controlled
variables should be the same as the first pz measured variables. Also, the
number of controlled outputs should be equal to the number of inputs.

The argument solver should be a string containing one of the alternatives qp_as,
qp_ip or quadprog, indicating which solver should be used to solve the quadratic
programming problem. Notice that quadprog requires Optimization Toolbox.

See Also
MPCOptimizeSol, MPCSim and MPCfrsp.

29
MPCOptimizeSol

Purpose
This function solves the MPC optimization problem.

Syntax
[duPred, zPred, J] = MPCOptimizeSol(x_est,u_last,du_old,
r,md)

Input arguments
x_est The current estimate of the state vector
u_last The control signal applied to the plant at the last sample.
du_old The optimal decision vector from the last sample that is used to hot
start the quadratic programming algorithm.
r The reference vector for the controlled variables.
md The data structure containing pre-computed matrices.

Output arguments
duPred Optimal control increment trajectory.
zPred Optimal trajectory of the controlled variables.
J Optimal value of the cost function.

Description
MPCOptimizeSol solves the MPC optimization problem. duPred and zPred are the
predicted control increments and controlled outputs for the specified prediction
horizons.
An estimate of the current state vector is given by x_est, and u_last is the last
applied control input. As an initial starting point for the optimization algorithm,
the last predicted control input vector, du_old, is supplied. r is the desired set
point for the controlled outputs and md is the data structure containing matrices
needed to solve the optimization problem.

See Also
MPCInit, MPCSim and MPCfrsp

30
MPCSim

Purpose
Simulates a linear system model controlled by the MPC controller.

Syntax
[x, u, y, z, zPredTraj, uPredTraj] = MPCSim(md,r,d)

Input arguments
md Data object containing the pre-computed matrices.
r Reference trajectory for the controlled variables.
d Input disturbance trajectory.

Output arguments
x State trajectory of the plant.
u Control variable trajectory.
y Measured variable trajectory.
z Controlled variable trajectory.
zPredTraj Optimal predicted trajectories for the controlled variables at
each sample.
uPredTraj Optimal predicted trajectories for the control variables at each
sample.

Description
MPCSim simulates the MPC controller specified by the data object md. The refer-
ence trajectory for the controlled outputs is given by r and a load disturbance
acting on the input is given by d.

See Also
MPCInit, MPCOptimizeSol and MPCfrsp

31
MPCController

Purpose
S-function for simulation of the MPC controller in the Simulink environment.

Syntax
[sys, x0, str, ts] = MPCController(t, x, u, flag, md)

Input arguments
t Supplied by the Simulink environment.
x Supplied by the Simulink environment.
u Supplied by the Simulink environment.
flag Supplied by the Simulink environment.
md Data object containing the pre-computed matrices needed by the MPC
controller. Supplied as a parameter in the S-function block.

Output arguments
sys Needed by the Simulink environment.
x0 Needed by the Simulink environment.
str Needed by the Simulink environment.
ts Needed by the Simulink environment.

Description
MPCController is an S-function implementing the MPC controller intended for
use with Simulink. The argument md, which is the only user supplied argu-
ment, contains the data structures needed by the controller. The input to the
S-function block is a vector signal consisting of the measured outputs and the
reference values for the controlled outputs. The output of the S-function block is
a vector signal consisting of the control variables and the estimated state vector,
potentially including estimated disturbance states.

See Also
MPCOptimizeSol and MPCInit

32
MPCfrsp

Purpose
Calculates the linear controller corresponding to the MPC controller if no con-
straints are active.

[Sys_CL, Sys_S, Sys_CS, Sys_SU, F, H, K, h] = MPCfrsp(md)

Input arguments
md MPC data object.
fignbr If this argument fignbr is given, two plots with numbers
fignbr and fignbr+1 are drawn.

Output arguments
Sys_CL Closed loop system from r to z.
Sys_S Sensitivity function from v to y.
Sys_CS Complimentary sensitivity function: from n to y.
Sys_SU Control signal sensitivity function: from n to u.
F See block diagram.
H See block diagram.
K See block diagram.
h A vector of handles to the figures where the transfer functions are
plotted.
See Figure 10 for explanation of the notation.

Description
MPCfrsp calculates the frequency responses of the MPC controller. When no con-
straints are active, the MPC controller is a linear controller and may be analyzed
using linear methods. Some important transfer functions are also plotted.

See Also
MPCInit

r u y
F ( z) K ( z) P( z)

H ( z)

Figure 10 Block diagram used for calculation of the linear controller.

33
qp_as

Purpose
Solves a quadratic program using an active set method.

Syntax
[xopt, lambda, J, x_hist] = qp_as(H,f,A,b,x0)

Input arguments
H H-matrix (Hessian) of the QP problem.
f f -vector of the QP problem.
A A-matrix defining linear constraints.
b b-vector defining linear constraints.
x0 Initial solution guess.

Output arguments
xopt The optimal solution.
lambda Lagrange multipliers.
J The optimal value of the cost function.
x_hist History of x during the optimization run. Each column in x_hist
represents the solution at the corresponding iteration.

Description
qp_as solves the quadratic programming problem

1 T
min x Hx + fTx
2
s.t.
Ax ≤ b

The algorithm is based on [Fletcher, 1987, p. 240].

See Also
get feasible

34
qp_ip

Purpose
Solves a quadratic program using a primal-dual interior point method.

Syntax
[xopt, lambda, J, x_hist] = qp_ip(H,f,A,b,x0)

Input arguments
H H-matrix (Hessian) of the QP problem.
f f -vector of the QP problem.
A A-matrix defining linear constraints.
b b-vector defining linear constraints.
x0 Initial solution guess.

Output arguments
xopt The optimal solution.
lambda Lagrange multipliers.
J The optimal value of the cost function.
x_hist History of x during the optimization run. Each column in x_hist
represents the solution at the corresponding iteration.

Description
qp_ip solves the quadratic programming problem

1 T
min x Hx + fTx
2
s.t.
Ax ≤ b

The algorithm is based on [Wright, 1997]. An initial solution is supplied in x0,


but is not used efficiently by the algorithm in the current implementation.

35
getfeasible

Purpose
Finds a feasible solution subject to linear inequality constraints.

Syntax
[x, as, iter] = getfeasible(A,b)

Input arguments
A A-matrix defining linear constraints.
b b-vector defining linear constraints.

Output arguments
x A feasible solution.
as The indices of active constraints, if any.
iter The number of iterations.

Description
getfeasible finds a feasible vector that fulfills the linear inequality constraints

Ax ≤ b.

The algorithm is based on [Fletcher, 1987, p. 166]

See Also
qp_as

36
9. References
Åkesson, J. and P. Hagander (2003): “Integral action—a disturbance observer
approach.” In Proceedings of European Control Conference.
Åström, K. J. and B. Wittenmark (1990): Computer Controlled Systems—Theory
and Design. Prentice-Hall, Englewood Cliffs, New Jersey.
Bartlett, R. A., A. Wächter, and L. T. Biegler (2000): “Active set vs. interior
point strategies for model predictive control.” In Proceedings of the American
Control Conference. Chicago, Illinois.
Bazaraa, M. S., H. D. Sherall, and C. M. Shetty (1993): Nonlinear Programming:
Theory and Algorithms. John Wiley & Sons, Inc.
Bemporad, A., M. Morari, V. Dua, and E. N. Pistikopoulos (2002): “The explicit
linear quadratic regulator for constrained systems.” Automatica, 38:1, pp. 3–
20.
Fletcher, R. (1987): Practical Methods of Optimization. John Wily & Sons Ltd.
Johansson, K. H. (1997): Relay Feedback and Multivariable Control. PhD thesis
ISRN LUTFD2/TFRT- -1048- -SE, Department of Automatic Control, Lund
Institute of Technology, Sweden.
Maciejowski, J. M. (2002): Predictive Control with Constraints. Pearson Educa-
tion.
Mayne, D. Q., J. B. Rawlings, C. V. Rao, and P. O. M. Scokaert (2000):
“Constrained model predictive control: Stability and optimality.” Automatica,
36:6, pp. 789–814.
Qin, S. J. and T. A. Badgwell (2003): “A survey of industrial model predictive
control technology.” Control Engineering Practice, 11, pp. 733–764.
Scokaert, P. O. M., D. Q. Mayne, and J. B. Rawlings (1999): “Suboptimal
model predictive control (feasibility implies stability).” IEEE Transactions
of Automatic Control, 44:3, pp. 648–654.
Wright, S. J. (1997): Primal-Dual Interior-Point Methods. SIAM.

37

You might also like