Model Predictive Control Toolbox™ User's Guide
Model Predictive Control Toolbox™ User's Guide
User’s Guide
R2014a
Alberto Bemporad
Manfred Morari
N. Lawrence Ricker
How to Contact MathWorks
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support
508-647-7000 (Phone)
508-647-7001 (Fax)
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
October 2004 First printing New for Version 2.1 (Release 14SP1)
March 2005 Online only Revised for Version 2.2 (Release 14SP2)
September 2005 Online only Revised for Version 2.2.1 (Release 14SP3)
March 2006 Online only Revised for Version 2.2.2 (Release 2006a)
September 2006 Online only Revised for Version 2.2.3 (Release 2006b)
March 2007 Online only Revised for Version 2.2.4 (Release 2007a)
September 2007 Online only Revised for Version 2.3 (Release 2007b)
March 2008 Online only Revised for Version 2.3.1 (Release 2008a)
October 2008 Online only Revised for Version 3.0 (Release 2008b)
March 2009 Online only Revised for Version 3.1 (Release 2009a)
September 2009 Online only Revised for Version 3.1.1 (Release 2009b)
March 2010 Online only Revised for Version 3.2 (Release 2010a)
September 2010 Online only Revised for Version 3.2.1 (Release 2010b)
April 2011 Online only Revised for Version 3.3 (Release 2011a)
September 2011 Online only Revised for Version 4.0 (Release 2011b)
March 2012 Online only Revised for Version 4.1 (Release 2012a)
September 2012 Online only Revised for Version 4.1.1 (Release 2012b)
March 2013 Online only Revised for Version 4.1.2 (Release R2013a)
September 2013 Online only Revised for Version 4.1.3 (Release R2013b)
March 2014 Online only Revised for Version 4.2 (Release R2014a)
Contents
Introduction
1
How Plants Are Used In Model Predictive Control . . . . 1-2
Single-Input Single-Output (SISO) Plants . . . . . . . . . . . . . 1-2
Multi-Input Multi-Output (MIMO) Plants . . . . . . . . . . . . . 1-5
Blocking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12
v
State Estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17
Unmeasured (Input) Disturbance Model . . . . . . . . . . . . . . . 2-17
Measurement Noise Model . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19
Output Disturbance Model . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19
State Observer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20
QP Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23
Prediction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23
Optimization Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24
Cost Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26
Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27
vi Contents
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15
Case-Study Examples
4
Servomechanism Controller . . . . . . . . . . . . . . . . . . . . . . . . 4-2
System Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Control Objectives and Constraints . . . . . . . . . . . . . . . . . . . 4-4
Defining the Plant Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
Controller Design Using MPCTOOL . . . . . . . . . . . . . . . . . . 4-5
Using Model Predictive Control Toolbox Commands . . . . . 4-19
Using MPC Tools in Simulink . . . . . . . . . . . . . . . . . . . . . . . 4-23
vii
Refine Controller Tuning Weights Using the Tuning
Advisor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-65
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-100
viii Contents
Signal Definition View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18
Plant Models View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-23
Controllers View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-25
Simulation Scenarios List . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-29
Controller Specifications View . . . . . . . . . . . . . . . . . . . . . . . 5-32
Simulation Scenario View . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-54
ix
x Contents
1
Introduction
1-2
How Plants Are Used In Model Predictive Control
The following table summarizes the nomenclature used in the previous figure.
Symbol Description
d Unmeasured disturbance. This signal is unknown except for
its effect on the plant output. The controller provides feedback
compensation for such disturbances.
r Setpoint (or reference). The target value for the output.
u Manipulated variable (or actuator). The signal the controller
adjusts in order to achieve its objectives.
v Measured disturbance (optional). The controller provides
feedforward compensation for such disturbances as they occur
to minimize their impact on the output.
Output (or controlled variable). The signal to be held at the
y
setpoint. This is the true value, uncorrupted by measurement
noise.
y Measured output. The signal used to estimate the true value,
y.
z Measurement noise. The signal represents electrical noise,
sampling errors, drifting calibration, and other effects that
impair measurement precision and accuracy.
The SISO plant actually has multiple inputs. In addition to the manipulated
variable input, u, there may be:
1-3
1 Introduction
Various noise effects can corrupt the measurement. The signal z in the Block
Diagram of a SISO Model Predictive Control Toolbox™ Application on page
1-2 figure represents such effects. Theses effects can vary randomly with a
zero mean, or can exhibit a nonzero, drifting bias. Model Predictive Control
1-4
How Plants Are Used In Model Predictive Control
The main challenge is to tune the controller to achieve multiple objectives. For
example, if there are several outputs to be controlled, it might be necessary
to prioritize so that the controller provides accurate setpoint tracking for
the most important output, sacrificing others when necessary, e.g., when it
encounters constraints. Model Predictive Control Toolbox features support
such prioritization.
1-5
1 Introduction
Specifically, the controller predicts how much each output will deviate from
its setpoint within the prediction horizon. It multiplies each deviation by
the output’s weight, and computes the weighted sum of squared deviations,
Sy(k), as follows:
ny 2
P
S y (k) = ∑ ∑{ w yj [ rj (k + i) − }
y j (k + i)]
i =1 j =1
If w yj wiy≠ j , the controller does its best to track rj, sacrificing ri tracking
Choosing the weights is a critical step. You will usually need to tune your
controller, varying the weights to achieve the desired behavior.
1-6
How Plants Are Used In Model Predictive Control
CSTR Schematic
From the Model Predictive Control Toolbox point of view, T and CA would be
plant outputs, and CAi and Tc would be inputs. More specifically, CAi would be
an independent disturbance input, and Tc would be a manipulated variable
(actuator).
M nmv 2
SΔu (k) = ∑ ∑{ }
wΔj u Δu j (k + i − 1)
i =1 j =1
which must be zero or positive. Increasing wΔj u forces the controller to make
1-7
1 Introduction
smaller, more cautious Δu j moves. In many cases (but not all) this will have
the following effects:
On the other hand, some plants have more MVs than output setpoints. In
such a plant, if all manipulated variables were allowed to move freely, the
MV values needed to achieve a particular setpoint or to reject a particular
disturbance would be non-unique. Thus, the MVs would drift within the
operating space.
M nmv 2
Su (k) = ∑ ∑{ wuj [u j }
− u j (k + i − 1)]
i =1 j =1
where u j is the manipulated variable setpoint (nominal value) for the jth MV,
1-8
How Plants Are Used In Model Predictive Control
discouraged. The designer may specify the degree of softness in each case,
making selected constraints less likely to be violated than others. See
“Optimization Problem” on page 2-5 for the mathematical details.
Briefly, you specify a tolerance band for each constraint. If the tolerance band
is zero, the constraint is hard (no violation allowed). Increasing the tolerance
band softens the constraint.
The tolerance band is not a limit on the constraint violation, however. (If it
were, you would still have a hard constraint.) You need to view it relative
to other constraints.
For example, suppose you have two constraints, one on a temperature and
the other on a flow rate. You specify a tolerance band of 2 degrees on the
temperature constraint, and 20 kg/s on the flow rate constraint. The Model
Predictive Controller assumes that violations of these magnitudes are of equal
concern, and should be handled accordingly.
If all plant states are measured, the state estimation problem is relatively
simple and requires consideration of measurement noise effects only.
Unfortunately, the internal workings of a typical plant are unmeasured,
and the controller must estimate their current values from the available
measurements. It also estimate the values of any sustained, unmeasured
disturbances.
Plant Delays
The software discretizes the plant model to the controller sample time. If
the plant model contains delays, the software replaces each model delay of
1-9
1 Introduction
Blocking
In figure Controller State at the kth Sampling Instant on page 1-15 (b),
M = 4 and P= 9, and the controller is optimizing the first M moves of the
prediction horizon, after which the manipulated variable remains constant for
the remaining P – M = 5 sampling instants.
1-10
How Plants Are Used In Model Predictive Control
As for the default (unblocked) mode, only the current move, uk, actually goes
to the plant. Thus, as shown in the figure above, the controller has made a
plant adjustment at each sampling instant.
So why use blocking? When P >> M (as is generally recommended), and all
M moves are at the beginning of the horizon, the moves tend to be larger
(because all but the final move last just one sampling period). Blocking often
leads to smoother adjustments, all other things being equal.
See the subsequent case study examples and the literature for more discussion
and MIMO design guidelines.
1-11
1 Introduction
Blocking
In figure Controller State at the kth Sampling Instant on page 1-15 (b),
M = 4 and P= 9, and the controller is optimizing the first M moves of the
prediction horizon, after which the manipulated variable remains constant for
the remaining P – M = 5 sampling instants.
As for the default (unblocked) mode, only the current move, uk, actually goes
to the plant. Thus, as shown in the figure above, the controller has made a
plant adjustment at each sampling instant.
So why use blocking? When P >> M (as is generally recommended), and all
M moves are at the beginning of the horizon, the moves tend to be larger
1-12
Blocking
(because all but the final move last just one sampling period). Blocking often
leads to smoother adjustments, all other things being equal.
See the subsequent case study examples and the literature for more discussion
and MIMO design guidelines.
1-13
1 Introduction
1-14
Typical Sampling Instant
The figure, Controller State at the kth Sampling Instant on page 1-15, shows
the state of a hypothetical SISO model preditive control system. This system
has been operating for many sampling instants. Integer k represents the
current instant. The latest measured output, yk, and previous measurements,
yk–1, yk–2, ..., are known and are the filled circles in the figure Controller
1-15
1 Introduction
State at the kth Sampling Instant on page 1-15 (a). If there is a measured
disturbance, its current and past values would be known (not shown).
Figure Controller State at the kth Sampling Instant on page 1-15 (b) shows
the controller’s previous moves, uk–4, ..., uk–1, as filled circles. As is usually
the case, a zero-order hold receives each move from the controller and holds it
until the next sampling instant, causing the step-wise variations shown in
figure Controller State at the kth Sampling Instant on page 1-15 (b).
In the example, the optimal moves are the four open circles in figure
Controller State at the kth Sampling Instant on page 1-15 (b). The controller
predicts that the resulting output values will be the nine open circles in figure
Controller State at the kth Sampling Instant on page 1-15 (a). Notice that
both are within their constraints, umin≤uk+j≤umax and ymin≤yk+i≤ymax.
When it’s finished calculating, the controller sends move uk to the plant. The
plant operates with this constant input until the next sampling instant, Δt
time units later. The controller then obtains new measurements and totally
revises its plan. This cycle repeats indefinitely.
1-16
Typical Sampling Instant
1-17
1 Introduction
• Plant delays. Suppose that the plant includes a pure time delay equivalent
to D sampling instants. In other words, the controller’s current move, uk,
has no effect until yk+D+1. In this situation it is essential that P >> D and M
<< P −D, as this forces the controller to consider the full effect of each move.
For example, suppose D = 5, P = 7, M = 3, the current time instant is k,
and the three moves to be calculated are uk, uk+1, and uk+2. Moves uk, uk+1
would have some impact within the prediction horizon, but move uk+2 would
have none until yk+8, which is outside. Thus, uk+2 is indeterminant. Setting
P = 8 (or M = 2) would allow a unique value to be determined. It would
be better to increase P even more.
• Other nonminimum phase plants. Consider a SISO plant with an
inverse-response, i.e., a plant with a short-term response in one direction,
1-18
Prediction and Control Horizons
1 Choose the control interval such that the plant’s open-loop settling time
is approximately 20–30 sampling periods (i.e., the sampling period is
approximately one fifth of the dominant time constant).
1-19
1 Introduction
1-20
2
Prediction Model
The linear model used in Model Predictive Control Toolbox software for
prediction and optimization is depicted in the following figure.
Note When defining a model predictive controller, you must specify a plant
model. You do not need to specify a model generating the disturbances, as
the controller setup assumes by default that unmeasured disturbances are
generated by integrators driven by white noise (see “Output Disturbance
Model” on page 2-19 and setindist).
2-2
Prediction Model
In the above equations, d(k) collects state disturbances (Bd≠0) and output
disturbances (Dd≠0).
Note A valid plant model for Model Predictive Control Toolbox software
cannot have direct feedthrough of manipulated variables u(k) on the output
vector y(k).
The unmeasured disturbance d(k) is modeled as the output of the linear time
invariant system:
Offsets
In many practical applications, the model matrices A, B, C, D are obtained by
linearizing a nonlinear dynamical system, such as
x′ = f ( x, u, v, d)
y = h(x, u, v, d)
2-3
2 Model Predictive Control Problem Setup
at some nominal value x=x0, u=u0, v=v0, d=d0. In these equations x´ denotes
either the time derivative (continuous time model) or the successor x(k+1)
(discrete time model). As an example, x0, u0, v0, d0 may be obtained by using
findop on a Simulink® model describing the nonlinear dynamical equations,
and A, B, C, D by using linearize. The linearized model has the form:
x ′ ≅ f ( x0 , u0 , v0 , d0 ) + ∇ x f ( x0 , u0 , v0 , d0 )( x − x0 ) + ∇ x f ( x0 , u0 , v0 , d0 )(u − u0 )
+ ∇v f ( x0 , u0 , v0 , d0 )(v − v0 ) + ∇ d f ( x0 , u0 , v0 , d0 )(d − d0 )
y ≅ h( x0 , u0 , v0 , d0 ) + ∇ x h( x0 , u0 , v0 , d0 )( x − x0 ) + ∇u h( x0 , u0 , v0 , d0 )(u − u0 )
+ ∇v h( x0 , u0 , v0 , d0 )(v − v0 ) + ∇ d h( x0 , u0 , v0 , d0 )(d − d0 )
The linearized dynamics are affected by the constant terms F=f(x0, u0, v0, d0)
and H=h(x0, u0, v0, d0). For this reason the model predictive control algorithm
internally adds a measured disturbance v=1, so that F and H can be embedded
into Bv and Dv, respectively, as additional columns.
2-4
Optimization Problem
Optimization Problem
In this section...
“Standard Form” on page 2-5
“Alternative Cost Function” on page 2-7
“Terminal Weights and Constraints” on page 2-8
“Custom Constraints on Inputs and Outputs” on page 2-11
Standard Form
Assume that estimates of x(k), xd(k) are available at time k (for state
estimation, see “State Estimation” on page 2-17). The model predictive control
action at time k is obtained by solving the optimization problem:
⎧ ⎛n 2 nu nu ⎞⎫
⎪ p−1 ⎜ y Δu Δu ( k + i k ) 2 + 2 ⎟⎪
∑ ∑ ∑ ∑
y u (u (k + i k) − u
⎪ w ( y ( k + i + 1 k) − r ( k + i + 1)) + w w ( k + i)) ⎟⎟ ⎪
⎜⎜ i+1, j
min j j i, j j i, j j jtarget
⎨ ⎬
Δu(k k),...,Δu(m−1+ k k), ⎪ i=0 ⎝ j =1 j =1 j =1 ⎠⎪
⎪
⎩ + 2 ⎪
⎭ (2-3)
where
i = 0, ..., p–1
h = m, ..., p–1
2-5
2 Model Predictive Control Problem Setup
Note Only the measured output vector ym(k) is fed back to the model
predictive controller. However, r(k) is a reference for all the outputs
(measured and unmeasured).
When the reference r is not known in advance, the current reference r(k) is
used over the whole prediction horizon, so r(k+i+1)=r(k) in Equation 2-3.
wiΔ, uj , wiu, j , wiy, j are nonnegative weights for the corresponding variable. The
smaller the value of w, the less important the behavior of the corresponding
variable is to the overall performance.
uj,min uj,max, Δuj,min, Δuj,max, yj,min, yj,max are lower/upper bounds on the
corresponding variables. In Equation 2-3, the constraints on u, Δu, and y are
relaxed or softened by introducing the slack variable ε≥ 0. In Equation 2-4,
the weight ρε on the slack variable ε penalizes the violation of the constraints.
As ρε increases relative to the input and output weights, the controller gives
minimization of constraint violations higher priority.
u u Δu
The Equal Concern for the Relaxation (ECR) vectors Vmin , Vmax , Vmin ,
Du y y
Vmax , Vmin , Vmax have nonnegative entries that quantify the concern for
relaxing the corresponding constraint; the larger V, the softer the constraint.
V=0 means the constraint is hard and cannot be violated. By default, all
2-6
Optimization Problem
u u Δu Δu
input constraints are hard ( Vmin = Vmax = Vmin = Vmax = 0 ) and all output
y y
constraints are soft ( Vmin = Vmax = 1 ). Also, by default:
{ }
e = 105 max wiΔ, uj , wiu, j , wiy, j . (2-4)
The model predictive controller penalizes the worst case soft constraint
violation—the one for which the inclusion of the non-zero slack variable
(and the associated ECR value) allows the constraint to be satisfied at
equality. As the model predictive controller attempts to minimize the cost
function, it might increase violations of other soft constraints. You can use
the ECR values to adjust the priority. Doing so allows you to determine which
constraint is selected as the worst-case violation.
Vector utarget(k+i) is a setpoint for the input vector. You typically uses utarget
when the number of inputs is greater than the number of outputs. Doing so
specifies a preferred value for the inputs when all other objectives have been
achieved.
2-7
2 Model Predictive Control Problem Setup
p−1
T
∑ ⎡⎣ y ( k + i + 1 k) − r ( k + i + 1)⎤⎦ Q ⎣⎡ y ( k + i + 1 k ) − r ( k + i + 1) ⎤⎦ + Δu ( k + i k ) RΔu ( k + i k )
T
J (Δu, ) =
i =0
T
+ ⎡⎣u ( k + i k ) − utarget ( k + i ) ⎤⎦ Ru ⎡⎣u ( k + i k ) − utarget ( k + i ) ⎤⎦ + e 2 (2-5)
• Weights wiy, j , wiΔ, uj , and wiu, j are constant for all i = 1, ..., p.
• Matrices Q, RΔu and Ru are diagonal with the squares of the weights wiy, j ,
Note When using the alternative cost function, you must define the controller
using MATLAB® commands. The Model Predictive Control Toolbox design
tool does not provide this option.
Terminal constraints are the constraints on y(t + p) and u(t + p – 1), where p is
the prediction horizon. You can use terminal constraints as an alternative
way to achieve closed-loop stability by defining a terminal region.
Note You can use terminal weights and constraints only at the
command-line. See setterminal.
2-8
Optimization Problem
For the relatively simple unconstrained case, a terminal weight can make the
finite-horizon Model Predictive Controller behave as if its prediction horizon
were infinite. For example, the MPC controller behavior is identical to a
linear-quadratic regulator (LQR). The standard LQR derives from the cost
function:
J (u) x(k i)T Qx(k i) u(k i 1)T Ru(k i 1)
i1 (2-6)
The LQR provides nominal stability provided matrices Q and R meet certain
conditions. You can convert the LQR to a finite-horizon form as follows:
p1
J (u) [ x(k i)T Qx(k i) u(k i 1)T Ru(k i 1)] x(k p)T Qp x(k p)
i1 (2-8)
where Qp , the terminal penalty matrix, is the solution of the Riccati equation:
Q p AT Q p A AT Q p B( BT Q p B R)1 BT Q p A Q (2-9)
You can obtain this solution using the lqr command in Control System
Toolbox software.
yaug(k) = Qcx(k)
2-9
2 Model Predictive Control Problem Setup
2 Define the auxiliary outputs yaug as unmeasured, and specify zero weight
to them.
3 Specify unity weight on yaug at the last step in the prediction horizon using
setterminal.
For an in-depth discussion of design issues for constrained systems see [2].
Depending on the situation, you might need to include terminal constraints
to force the plant states into a defined region at the end of the horizon, after
which the LQR can drive the plant signals to their targets. Use setterminal
to add such constraints to the controller definition.
Related Examples
2-10
Optimization Problem
Note Custom constraints can be specified only at the command line. See
setconstraint.
Related Examples
2-11
2 Model Predictive Control Problem Setup
Terminal constraints are the constraints on y(t + p) and u(t + p – 1), where p is
the prediction horizon. You can use terminal constraints as an alternative
way to achieve closed-loop stability by defining a terminal region.
Note You can use terminal weights and constraints only at the
command-line. See setterminal.
For the relatively simple unconstrained case, a terminal weight can make the
finite-horizon Model Predictive Controller behave as if its prediction horizon
were infinite. For example, the MPC controller behavior is identical to a
linear-quadratic regulator (LQR). The standard LQR derives from the cost
function:
J (u) x(k i)T Qx(k i) u(k i 1)T Ru(k i 1)
i1 (2-10)
The LQR provides nominal stability provided matrices Q and R meet certain
conditions. You can convert the LQR to a finite-horizon form as follows:
p1
J (u) [ x(k i)T Qx(k i) u(k i 1)T Ru(k i 1)] x(k p)T Qp x(k p)
i1 (2-12)
where Qp , the terminal penalty matrix, is the solution of the Riccati equation:
2-12
Terminal Weights and Constraints
Q p AT Q p A AT Q p B( BT Q p B R)1 BT Q p A Q (2-13)
You can obtain this solution using the lqr command in Control System
Toolbox software.
yaug(k) = Qcx(k)
2 Define the auxiliary outputs yaug as unmeasured, and specify zero weight
to them.
3 Specify unity weight on yaug at the last step in the prediction horizon using
setterminal.
For an in-depth discussion of design issues for constrained systems see [2].
Depending on the situation, you might need to include terminal constraints
to force the plant states into a defined region at the end of the horizon, after
2-13
2 Model Predictive Control Problem Setup
which the LQR can drive the plant signals to their targets. Use setterminal
to add such constraints to the controller definition.
Related Examples
2-14
Custom Constraints on Inputs and Outputs
Note Custom constraints can be specified only at the command line. See
setconstraint.
Related Examples
2-15
2 Model Predictive Control Problem Setup
Constraint Softening
A hard constraint cannot be violated. Hard constraints are risky, especially
for outputs, because the controller will ignore its other objectives in order to
satisfy them. Also, the constraints might be impossible to satisfy in certain
situations, in which case the calculations are mathematically infeasible.
Soft input and output constraints are scalars or vectors. The latter defines a
time-varying relaxation band. The relaxation band is a relative tolerance, not
a strict bound. In other words, the actual constraint violation can exceed the
relaxation band. Specifying zero indicates a hard constraint.
See Also
• getconstraint
• setconstraint
• “Define Soft Output Constraints”
2-16
State Estimation
State Estimation
In this section...
“Unmeasured (Input) Disturbance Model” on page 2-17
“Measurement Noise Model” on page 2-19
“Output Disturbance Model” on page 2-19
“State Observer” on page 2-20
As the states x(k), xd(k) are not directly measurable, predictions are obtained
from a state estimator. In order to provide more flexibility, the estimator is
based on the model depicted in the following figure.
2-17
2 Model Predictive Control Problem Setup
xd (k 1) Ad xd (k) Bd nd (k)
d(k) Cd xd (k) Dd nd (k)
where nd(k) is a zero-mean, unit variance, random Gaussian input and xd(k)
are the input disturbance model states. You may supply the model in any
convenient LTI form (e.g. transfer function). The Model Predictive Control
Toolbox will convert it to the state-space model internally.
There are three ways to specify the input disturbance model. Suppose Obj is
an mpc object for a plant with two inputs and two outputs. One input is the
manipulated variable and the other is an unmeasured disturbance. Let the
input disturbance model be an LTI system parameterized by matrices Ad, Bd,
Cd, Dd. If xd is length 2, then Cd must contain 1 row and 2 columns. Use one of
the following methods to specify this input disturbance model:
Obj.Model.Disturbance = ss(Ad,Bd,Cd,Dd);
• Call setindist
DistMod = ss(Ad,Bd,Cd,Dd);
setindist(Obj,'model',DistMod);
2-18
State Estimation
• Use the graphical design tool to import the disturbance model for the mpc
object. For more information, see “Input Disturbances” on page 5-49.
A default disturbance model is created if the plant model includes a d(k) signal
but no input disturbance model is specified. This guarantees asymptotic
rejection of plant output disturbances.
(k) + Bn
xm (k + 1) = Ax
m m (k)
m(k) = Cx (k) + Dn
m m (k)
Note The objective of the model predictive controller is to bring yu(k) and
[ym(k)–m(k)] as close as possible to the reference vector r(k). For this reason,
the measurement noise model producing m(k) is not needed in the prediction
model used for optimization described in “Prediction Model” on page 2-2.
2-19
2 Model Predictive Control Problem Setup
Use getoutdist to obtain the output disturbance model in the form used
internally.
State Observer
The state observer is designed to provide estimates of x(k), xd(k), xm(k), where
x(k) is the state of the plant model, xd(k) is the overall state of the input
and output disturbance model, xm(k) is the state of the measurement noise
model. The estimates are computed from the measured output ym(k) by the
linear state observer
2-20
State Estimation
⎡ xˆ (k k) ⎤ ⎡ xˆ (k k − 1) ⎤
⎢ ⎥ ⎢ ⎥
⎢ xˆ d (k k) ⎥ = ⎢ xˆ d (k k − 1) ⎥ + M ( ym (k) − yˆ m (k))
⎢ xˆ (k k) ⎥ ⎢ xˆ (k k − 1) ⎥
⎣ m ⎦ ⎣ m ⎦
⎡ xˆ (k + 1 k) ⎤ ⎡ Axˆ (k k) + Buu(k) + Bvv(k) + Bd Cxˆ d (k k) ⎤
⎢ ⎥ ⎢ ⎥
⎢ xˆ d (k + 1 k) ⎥ = ⎢ Axˆ d (k k) ⎥
⎢ xˆ (k + 1 k) ⎥ ⎢ ⎥
⎣ m ⎦ ⎣⎢ Axˆ m (k k) ⎥⎦
yˆ (k) = C xˆ (k k − 1) + D v(k) + D Cxˆ ( k k − 1) + Cx ˆ (k k − 1)
m m vm dm d m
n (k)
x(k 1) A Bd C 0 x(k) Bu Bv Bd D 0 Bu Bv d
x (k 1) nm (k)
d 0 A 0 xd (k) 0 u(k) 0 v(k) B 0 0 0 n (k)
xm (k 1) 0 0 A xm (k) 0 0 0 B 0 0 u
n (k)
v
nd (k)
x(k)
ym (k) Cm DdmC C xd (k) Dvm v(k) Ddm Dm D 0 D nm (k)
vm
nu (k)
xm (k)
v (k) (2-14)
n
where nu(k) and nv(k) are additional unmeasured white noise disturbances
having unit covariance matrix and zero mean, that are added on the vector of
manipulated variables and the vector of measured disturbances, respectively,
to ease the solvability of the Kalman filter design.
2-21
2 Model Predictive Control Problem Setup
Note also that observability is only checked numerically. Hence, for large
models of badly conditioned system matrices, unobservability may be reported
by the toolbox even if the system is observable.
See also getestim and setestim for details on the methods you can use to
access and modify properties of the state estimator.
2-22
QP Matrices
QP Matrices
This section describes the matrices associated with the model predictive
control optimization problem described in “Optimization Problem” on page 2-5.
Prediction
Assume that the disturbance model in Equation 2-1 and Equation 2-2 is a
unit gain for example, d(k)=nd(k) is a white Gaussian noise). You can denote
this problem as
⎡ x⎤ ⎡ A Bd C ⎤ ⎡ Bu ⎤ ⎡ Bv⎤ ⎡ Bd D ⎤
x ← ⎢ ⎥, A ← ⎢ ⎥ , Bu ← ⎢ ⎥ , Bv ← ⎢ ⎥ , Bd ← ⎢ ⎥ C ← ⎡⎣C Dd C ⎤⎦
x
⎣ d⎦ ⎢⎣ 0 A ⎥⎦ 0
⎣ ⎦ 0
⎣ ⎦ ⎣ B ⎦
Next, consider the problem of predicting the future trajectories of the model
performed at time k=0. Set nd(i)=0 for all prediction instants i, and obtain
⎡ i −1 ⎛ ⎛ h ⎞ ⎞⎤
y(i| 0) = C ⎢ Ai x(0) + ∑ Ai − 1 ⎜ Bu ⎜ u(−1) + ∑ Δu( j) ⎟⎟ + Bv v(h) ⎟⎟⎥⎥ + Dv v(i)
⎢ ⎜ ⎜
⎣ h=0 ⎝ ⎝ j =0 ⎠ ⎠⎦
2-23
2 Model Predictive Control Problem Setup
where
⎡ CBu ⎤
⎡ CA ⎤ ⎢CB + CAB ⎥
⎢ 2⎥ ⎢ u u⎥
⎢ CA ⎥ pny ×nx ⎢ ⎥ ∈ ℜ pny ×nu
Sx = ⎢ ∈ ℜ , S =
⎥ u1
⎢ p−1 ⎥
⎢ ⎥ ⎢ ⎥
⎢ ∑ CA Bu ⎥
h
⎢CA p ⎥
⎣ ⎦
⎢⎣ h=0 ⎥⎦
⎡ CBu 0 0 ⎤
⎢CB + CAB CB 0 ⎥⎥
⎢ u u u
Su = ⎢ ⎥ ∈ ℜ pny × pnu
⎢ p−1 p− 2
⎥
⎢ ⎥
⎢ ∑ CA Bu ∑
h h
CA Bu CBu ⎥
⎢⎣ h=0 h =0 ⎥⎦
⎡ CBv Dv 0 0 ⎤
⎢ CAB CBv Dv 0 ⎥⎥ pn ×( p+1)nv
Hv = ⎢
v
⎢
∈ℜ y .
⎥
⎢ ⎥
⎢⎣CA p−1 Bv CA p−2 Bv CA p−3 Bv Dv ⎥⎦
Optimization Variables
Let m be the number of free control moves, and let z= [z0; ...; zm–1]. Then,
⎡ Δu(0) ⎤ ⎡ z0 ⎤
⎢ ⎥=J ⎢ ⎥
⎢ ⎥ M ⎢ ⎥
⎢⎣ Δu( p − 1) ⎥⎦ ⎢⎣ zm − 1 ⎥⎦ (2-15)
where JM depends on the choice of blocking moves. Together with the slack
variable ε, vectors z0, ..., zm–1 constitute the free optimization variables of
the optimization problem. In the case of systems with a single manipulated
variables, z0, ..., zm–1 are scalars.
2-24
QP Matrices
Consider the blocking moves depicted in Blocking Moves: Inputs and Input
Iincrements for moves=[2 3 2] on page 2-25. This graph corresponds to the
choice moves=[2 3 2], or, equivalently, u(0)=u(1), u(2)=u(3)=u(4), u(5)=u(6),
Δ u(0)=z0, Δ u(2)=z1, Δ u(5)=z2, Δ u(1)=Δ u(3)=Δ u(4)=Δ u(6)=0.
⎡I 0 0⎤
⎢0 0 0 ⎥⎥
⎢
⎢0 I 0⎥
⎢ ⎥
JM = ⎢0 0 0⎥
⎢0 0 0⎥
⎢ ⎥
⎢0 0 I⎥
⎢⎢0 0 0 ⎥⎥⎦
⎣
2-25
2 Model Predictive Control Problem Setup
Cost Function
• “Standard Form” on page 2-26
• “Alternative Cost Function” on page 2-27
Standard Form
The function to be optimized is
T T
⎛ ⎡ u(0) ⎤ ⎡ utarget (0) ⎤ ⎞ ⎛ ⎡ u(0) ⎤ ⎡ utarget (0) ⎤ ⎞ ⎡ Δu(0) ⎤ ⎡ Δu(0) ⎤
⎜ ⎥ ⎟ W2 ⎜ ⎢ ⎥ − ⎢ ⎥⎟ + ⎢
J ( z, ) = ⎜ ⎢⎢ ⎥⎥ − ⎢⎢ ⎥ ⎟ u ⎜⎢ ⎥ ⎢ ⎥⎟ ⎢ ⎥ W2
⎥ Δu
⎢
⎢ ⎥
⎥
⎜ ⎢⎣u( p − 1) ⎥⎦ ⎢utarget ( p − 1) ⎥ ⎟ ⎜ ⎣⎢u( p − 1) ⎥⎦ ⎢utarget ( p − 1) ⎥ ⎟ ⎢⎣ Δu( p − 1) ⎥⎦ ⎢⎣ Δu( p − 1) ⎥⎦
⎝ ⎣ ⎦⎠ ⎝ ⎣ ⎦⎠
T
⎛ ⎡ y(1) ⎤ ⎡ r(1) ⎤ ⎞ ⎛ ⎡ y(1) ⎤ ⎡ r(1) ⎤ ⎞
⎜ ⎟ ⎜ ⎟
+ ⎜ ⎢⎢ ⎥⎥ − ⎢⎢ ⎥⎥ ⎟ Wy2 ⎜ ⎢⎢ ⎥⎥ − ⎢⎢ ⎥⎥ ⎟ + 2
⎜ ⎢ y( p) ⎥ ⎢ r( p) ⎥ ⎟ ⎜ ⎢ y( p) ⎥ ⎢ r( p) ⎥ ⎟
⎝⎣ ⎦ ⎣ ⎦⎠ ⎝⎣ ⎦ ⎣ ⎦⎠
where
(
Wu = diag w0u,1 , w0u,2 ,..., w0u,n ,..., wup−1,1 , wup−1,2 ,..., wup−1,n
u u
)
WΔu = diag ( w0Δ,u
1 , w0,2 ,..., w0,n ,..., w p−1,1 , w p−1,,2 ,..., w p−1,n )
Δu Δu Δu Δu Δu
u u
(
Wy = diag w1y,1 , w1y,2 ,..., w1y,n ,..., w py,1 , w py,2 ,..., w py,n
y y ) (2-16)
⎛ ⎡ r(1) ⎤ T ⎡ v(0) ⎤
T
⎡ utarget (0) ⎤
T ⎞
2 T
⎜⎢ ⎥ ⎢ ⎥ T ⎢ ⎥ T
⎟
J ( z, ) = + z K Δu z + 2 ⎜ ⎢ ⎥ K r + ⎢ ⎥ K v + u(−1) K u + ⎢ ⎥ K ut + x(0) K x ⎟ z
⎜⎜ ⎢ r( p) ⎥ ⎢⎣v( p) ⎥⎦ ⎢⎣utarget ( p − 1) ⎥⎦ ⎟⎟
⎝⎣ ⎦ ⎠
+ constant (2-17)
Note You may want the QP problem to remain strictly convex. If the
condition number of the Hessian matrix KΔU is larger than 1012, add the
quantity 10*sqrt(eps) on each diagonal term. You can use this solution only
when all input rates are unpenalized (WΔu=0) (see “Weights” in the Model
Predictive Control Toolbox reference documentation).
2-26
QP Matrices
Wu = blkdiag ( Ru ,..., Ru )
WΔu = blkdiag ( RΔu ,..., RΔu )
Wy = blkdiag ( Q,..., Q ) (2-18)
In this case, the block-diagonal matrices repeat p times, for example, once for
each step in the prediction horizon.
You also have the option to use a combination of the standard and alternative
forms. See “Weights” in the Model Predictive Control Toolbox reference
documentation for more details.
Constraints
Next, consider the limits on inputs, input increments, and outputs along
with the constraint ε≥ 0.
⎡ y
ymin (1) − Vmin (1) ⎤ ⎡ y
ymax (1) + Vmax (1) ⎤
⎢ ⎥ ⎡ y(1) ⎤ ⎢ ⎥
⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎢ ⎥ ⎢ ⎥ ⎢
y ⎥
⎢ ymin ( p) − Vmin ( p) ⎥ ⎢ y( p) ⎥ ⎢
y
ymax ( p) + Vmax ( p) ⎥
⎢ u ⎥ ⎢ ⎥ ⎢ ⎥
⎢ umin (0) − Vmin (0) ⎥ ⎢ u(0) ⎥ ⎢
u
umax (0) + Vmax (0) ⎥
⎢ ⎥≤⎢ ⎥≤⎢ ⎥
⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎢ umin ( p − 1) − V u ( p − 1) ⎥ ⎢ u( p − 1) ⎥ ⎢ umax ( p − 1) + Vmax u
( p − 1) ⎥
min
⎢ ⎥ ⎢ Δu(0) ⎥ ⎢ ⎥
Δu Δ
⎢ Δumin (0) − Vmin (0) ⎥ ⎢ ⎥ ⎢ u
Δumax (0) + Vmax (0) ⎥
⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎢ Δu ⎥ ⎢⎣ Δu( p − 1) ⎥⎦ ⎢
⎢⎣ Δumax ( p − 1) + Vmax ( p − 1) ⎥⎥⎦
Δu Δu
⎢⎣ min ( p − 1) − Vmin ( p − 1) ⎥⎦
2-27
2 Model Predictive Control Problem Setup
Similar to what you did for the cost function, you can substitute u(k), Δu(k),
y(k), and obtain
⎡ v(0) ⎤
M z z + M ≤ Mlim + Mv ⎢⎢ ⎥⎥ + Mu u(−1) + M x x(0)
⎢⎣v( p) ⎥⎦ (2-19)
In this case, matrices Mz,Mε,Mlim,Mv,Mu,Mx are obtained from the upper and
lower bounds and ECR values.
2-28
Model Predictive Control Computation
T
⎛ ⎡ r(1) ⎤ T ⎡ v(0) ⎤ ⎡ utarget (0) ⎤
T ⎞
⎜
−1 ⎢ ⎥ ⎢ ⎥ T ⎢ ⎥ T
⎟
z* = − K Δu ⎜ ⎢ ⎥ K r + ⎢ ⎥ K v + u(−1) K u + ⎢ ⎥ K ut + x (0) K x ⎟
⎜⎜ ⎢ r( p) ⎥ ⎢ v( p) ⎥ ⎢ u ( p − 1) ⎥ ⎟⎟
⎝⎣ ⎦ ⎣ ⎦ ⎣ target ⎦ ⎠
MPC QP Solver
The model predictive controller QP solver converts an MPC optimization
problem to the general QP form
1 T
Min( f
T
x x Hz )
x 2
such that
2-29
2 Model Predictive Control Problem Setup
Ax b
The toolbox uses the KWIK algorithm [1] to solve the QP problem, which
requires the Hessian to be positive definite. In the very first control step,
KWIK uses a cold start, in which the initial guess is the unconstrained
solution described in “Model Predictive Control Computation” on page 2-29.
If this x satisfies the constraints, it is the optimal QP solution, x*, and
the algorithm terminates. Otherwise this means that at least one of the
linear inequality constraints must be satisfied as an equality. In this case,
KWIK uses an efficient, numerically robust strategy to determine the active
constraint set satisfying the standard optimality conditions. In the following
control steps, KWIK uses a warm start. In this case, the active constraint set
determined at the previous control step becomes the initial guess for the next.
In the last two situations, with an abnormal outcome to the search, the
controller will retain the last successful control output. For more information,
2-30
Model Predictive Control Computation
see, the mpcmove command. You can detect an abnormal outcome and override
the default behavior as you see fit.
References
[1] Schmid, C. and L.T. Biegler. “Quadratic programming methods for
reduced hessian SQP.” Computers & Chemical Engineering. Vol. 18, Number
9, 1994, pp. 817–832.
2-31
2 Model Predictive Control Problem Setup
2-32
3
MPC Library
The MPC Simulink Library provides two blocks you can use to implement
MPC control in Simulink, MPC Controller, and Multiple MPC Controllers.
Access the library using the Simulink Library Browser or by typing mpclib at
the command prompt. The following figure shows the library contents.
Once you have access to the library, you can add one of its blocks to your
Simulink model by clicking-and-dragging or copying-and-pasting.
3-2
MPC Controller Block
The MPC Controller block represents a single MPC controller. You can adjust
plant inputs to control plant outputs, accounting for constraints, including
actuator limits.
3-3
3 Model Predictive Control Simulink® Library
• Type the name of an MPC object saved in your workspace. To review its
settings before running a simulation, click Design to load the named object
into the MPC design tool.
• If your installation includes Simulink Control Design™ software, connect
the MPC Controller block to the plant it controls. Leaving the MPC
3-4
MPC Controller Block
controller field empty, click Design. The block constructs a default MPC
object by linearizing the plant at the default operating point and exports
this defaults controller to the base workspace. If the default operating
point is not the one you want, see “Importing a Plant Model” on page 5-8
for help with importing a new plant model.
Note You can run closed-loop simulations with a linear plant in the design
tool, allowing you to tune the controller parameters. To test the controller
in Simulink, export it from the design tool to the workspace and run the
simulation in Simulink.
Connect Signals
The MPC Controller requires at least two inputs and generates at least one
output. There are also optional inputs and outputs. In most cases, the signals
are vectors comprised of plant variables. Verify that the signal dimensions
and the sequence of elements within each vector signal are consistent with
your controller definition.
Required inputs
Connect the following to the indicated controller inports:
3-5
3 Model Predictive Control Simulink® Library
the reference values at the first step in the controller’s prediction horizon.
By default, the controller assumes these values hold for the entire horizon.
Required outport
During operation, the controller updates the manipulated variable (mv)
outport at each control interval. The mv outport defines adjustments to plant
input variables. Connect this vector signal to the plant.
Sample Time
Every t( 0) time units, the MPC Controller samples its input signals and
updates its output signals. This control interval is defined in the Ts property
of the MPC object.
Optional Ports
If N=1, the previewing is disabled and the signal must contain the vector of
measured disturbances at the current controller sampling instant, tk. N>1
activates previewing. In this case, rows 2 to N must contain estimates of
the measured disturbances at future sampling instants tk+1, ..., tk+N-1.
These estimates allows the controller to preview, or, anticipate future changes
3-6
MPC Controller Block
in these disturbances and compensate for them at time tk. See mpcpreview
for an illustration of the improved performance this approach can provide.
Select the Externally supplied MV signals check box, and click Apply to
add an inport labeled ext.mv. Connect the feedback signal, length nmv.
Select Input and output limits, and click Apply to add the following four
inports:
• umin defines nmv lower bounds on the manipulated variables (the controller’s
mv outport).
• umax is a corresponding vector of nmv upper bounds.
• ymin defines ny lower bounds on the output variables (the same variables to
which the ref inport applies).
• ymax is a corresponding vector of ny upper bounds.
3-7
3 Model Predictive Control Simulink® Library
After adding the inports, connect the appropriate signals. See mpcvarbounds
for more information.
Disabling optimization
Select this option to control whether or not the block performs its optimization
calculations at each sampling instant. For example, if the controller’s mv
outport is being ignored because the plant is manually controlled, then
turning off optimization reduces the computational load. When optimization
is off, the mv output is zero.
If you select this option, the Externally supplied MV signals option also
activates automatically. To prevent "bumps" when optimization is deactivated
temporarily and then reactivates, you must feed the actual MV signal back
to the ext.mv inport.
Select the Optimal cost and click Apply to add a new scalar outport labeled
cost.
If the optimization problem is infeasible, that is, one or more hard constraints
cannot be satisfied or the solver experiences numerical difficulties. The
returned cost is –1.
3-8
MPC Controller Block
labeled mv.seq. At each control instant, the outport contains a p X nmv matrix
signal. The rows correspond to the p steps of the prediction horizon, and the
columns to the nmv manipulated variables. The first row represents current
time, k=0. The last row represents time k+p-1.
Online tuning
Three related options allow you to adjust controller performance during
operation. To activate one, select the appropriate check box, and click Apply.
This adds a new inport with the functionality:
3-9
3 Model Predictive Control Simulink® Library
Input Signals
You must connect appropriate Simulink signals to the MPC Controller block’s
inports. The measured output (mo) and reference (ref) inports are required.
You can add optional inports by selecting check boxes at the bottom of the
mask.
As shown in the figure, MPC Controller Block Mask on page 3-4 , Enable
measured disturbances is a default selection and the corresponding inport
(md) appears in figure MPC Simulink® Library on page 3-2. This provides
feedforward compensation for measured disturbances.
3-10
MPC Controller Block
Enable input and output limits allows you to specify constraints that vary
during a simulation. Otherwise, the block uses the constant constraint values
stored within its MPC Controller object. The example mpcvarbounds shows
how this option works. It enables inports for lower and upper bounds on the
manipulated variables (inports umin and umax) and lower and upper bounds
on the controlled outputs (inports ymin and ymax). An unconnected constraint
inport causes the corresponding variable to be unconstrained.
Enable optimization switch allows you to control whether or not the block
performs its optimization calculations at each sampling instant during a
simulation. If the controller is output is being ignored during the simulation,
e.g., due to a switch to manual control, turning off the optimization reduces
the computational load. When optimization is off, the controller output is
zero. To turn the optimization off, set the switch input signal to a nonzero
value. When the switch input is zero or disconnected, the optimization occurs
and the controller output varies in the normal way.
Output Signals
The block updates its output(s) at regular intervals. The MPC object named
in the block’s MPC controller field contains the control interval (its Ts
property). The object also specifies the number of manipulated variables, nu,
to be calculated and sent to the plant at each control instant. The default
outport (labeled mv) provides these as a vector signal of dimension nu.
• The Enable optimal cost outport option adds an outport labeled cost,
which contains the value of the optimal objective function obtained when
calculating the manipulated variables. See “Optimization Problem” on
page 2-5 for the various forms this can take. If the optimization problem is
infeasible, i.e., some constraints can’t be satisfied or the solver experiences
numerical difficulties, the returned cost is –1 .
3-11
3 Model Predictive Control Simulink® Library
For more information, see the MPC Controller block reference page.
You must create such a signal as a MATLAB structure with two fields: time
and signals. The Simulink From Workspace and To Workspace blocks
use the same format.
For example, to specify a sinusoidal reference signal sin(t) over a time horizon
of 10 seconds, use the following MATLAB commands:
time=(0:Ts:10);
ref.time=time;
ref.signals.values=sin(time);
3-12
MPC Controller Block
Initialization
If Initial controller state is unspecified, as in MPC Controller Block Mask
on page 3-4, the controller uses a default initial condition in simulations.
You can change the initial condition by specifying an mpcstate object. See
“MPC Simulation Options Object” in the Model Predictive Control Toolbox
Reference.
3-13
3 Model Predictive Control Simulink® Library
• Simulink Coder™
• Embedded Coder®
• Simulink PLC Coder™
• Simulink Real-Time™
Note The MPC Controller block is implemented using the MATLAB Function
block. To see the structure, right-click the block and select Mask > Look
Under Mask. Open the MPC subsystem underneath.
Related • “Simulation and Code Generation Using Simulink Coder” on page 4-80
Examples • “Simulation and Structured Text Generation Using PLC Coder” on page
4-84
3-14
Multiple MPC Controllers Block
The Multiple MPC Controllers block allows you to achieve better control of a
nonlinear plant over a range of operating conditions.
A controller that works well initially can degrade if the plant is nonlinear and
its operating point changes. In conventional feedback control, you might
compensate for this degradation by gain scheduling.
Limitations
The Multiple MPC Controllers block does not provide all the optional features
found in the MPC Controller block. The following ports are currently not
available:
Examples
See the mpcswitching and mpccstr examples for applications of the Multiple
MPC Controllers block.
3-15
3 Model Predictive Control Simulink® Library
After the prediction models have been defined for each operating region,
design each corresponding MPC Controller and give it a unique name in your
base workspace.
3-16
Relationship of Multiple MPC Controllers to MPC Controller Block
3-17
3 Model Predictive Control Simulink® Library
3-18
4
Case-Study Examples
Servomechanism Controller
In this section...
“System Model” on page 4-2
“Control Objectives and Constraints” on page 4-4
“Defining the Plant Model” on page 4-4
“Controller Design Using MPCTOOL” on page 4-5
“Using Model Predictive Control Toolbox Commands” on page 4-19
“Using MPC Tools in Simulink” on page 4-23
System Model
A position servomechanism consists of a DC motor, gearbox, elastic shaft,
and a load.
k ⎛ ⎞
L = − ⎜ L − M ⎟ − L L
JL ⎝ ⎠ JL
k ⎛ V − kT M ⎞ M M k ⎛ ⎞
M = T ⎜ ⎟− + ⎜ L − M ⎟
JM ⎝ R ⎠ J M J M ⎝ ⎠
4-2
Servomechanism Controller
where V is the applied voltage, T is the torque acting on the load, L = L
is the load’s angular velocity, M = M is the motor shaft’s angular velocity,
and the other symbols represent constant parameters (see Parameters Used
in the Servomechanism Model on page 4-3 for more information on these).
⎡ 0 1 0 0 ⎤
⎢ k L k ⎥
⎢ 0 ⎥ ⎡ 0 ⎤
⎢ JL JL JL ⎥ ⎢ 0 ⎥
⎢ ⎥ ⎢ ⎥
x p = ⎢ 0 0 0 1 ⎥ xp + ⎢ 0 ⎥V
⎢ ⎢ ⎥
⎢ kT2 ⎥⎥ ⎢ kT ⎥
M + ⎢⎣ RJ M ⎥⎦
⎢ k k R ⎥
⎢J 0 − ⎥
2
⎢⎣ M JM J M ⎥⎦
L = [1 0 0 0] x p
⎡ k ⎤
T = ⎢ k 0 0⎥ x p
⎣ ⎦
4-3
4 Case-Study Examples
The elastic shaft has a finite shear strength, so the torque, T, must stay
within specified limits
|T| ≤ 78.5Nm
|V| ≤ 220V
4-4
Servomechanism Controller
BB=[0;0;0;Kt/(R*JM)];
Hyd=[1 0 0 0];
Hvd=[Kth 0 -Kth/gear 0];
Dyd=0;
Dvd=0;
Note To follow this example on your own system, first create the
servomechanism model as explained in “Servomechanism Controller” on page
4-2. This defines the variable sys in your MATLAB workspace.
4-5
4 Case-Study Examples
mpctool
Once the design tool has appeared, click the Import Plant button. The Plant
Model Importer dialog box appears (see the following figure).
By default, the Import from option buttons are set to import from the
MATLAB workspace, and the box at the upper right lists all LTI models
defined there. In the following figure, sys is the only available model, and it
is selected. The Properties area lists the selected model’s key attributes.
Make sure your servomechanism model, sys, is selected. Then click the
Import button. You won’t be importing more models, so close the import
dialog box.
Meanwhile, the model has loaded, and tables now appear in the design tool’s
main window (see the figure below). Note the previous diagram enumerates
the model’s input and output signals.
4-6
Servomechanism Controller
You also have the option to change the default signal names (In1, Out1,
Out2) to something more meaningful (e.g., V, ThetaL, T), enter descriptive
4-7
4 Case-Study Examples
After you’ve entered all your changes, the design tool resembles the following
figure.
The Plant models node is next in the hierarchy. Click on it to list the plant
models being used in your design. (Each model name is editable.) The middle
section displays the selected model’s properties. There is also a space to enter
notes describing the model’s special features. Buttons allow you to import a
new model or delete one you no longer need.
The next node is Controllers. You might see a + sign to its left, indicating
that it contains subnodes. If so, click on the + sign to expand the tree (as
shown in Design Tool After Importing the Plant Model on page 4-7). All the
controllers in your design will appear here. By default, you have one: MPC1.
In general, you might opt to design and test several alternatives.
Select Controllers to see a list of all controllers, similar to the Plant models
view. The table columns show important controller settings: the plant model
4-8
Servomechanism Controller
being used, the controller sampling period, and the prediction and control
horizons. All are editable. For now, leave them at their default values.
4-9
4 Case-Study Examples
Specifying Constraints
Next, click the Constraints tab. The view shown in Controller Design View,
Constraints Pane on page 4-10 appears. Enter the appropriate constraint
values. Leaving a field blank implies that there is no constraint.
4-10
Servomechanism Controller
The Max down rate should be nonpositive (or blank). It limits the amount a
manipulated variable can decrease in a single control interval. Similarly, the
Max up rate should be nonnegative. It limits the increasing rate. Leave both
unconstrained (i.e., blank).
The shaded columns can’t be edited. If you want to change this descriptive
information, select the root node view and edit its tables. Such changes apply
to all controllers in the design.
Weight Tuning
Next, click the Weight Tuning tab.
The weights specify trade-offs in the controller design. First consider the
Output weights. The controller will try to minimize the deviation of each
output from its setpoint or reference value. For each sampling instant in the
prediction horizon, the controller multiplies predicted deviations for each
output by the output’s weight, squares the result, and sums over all sampling
instants and all outputs. One of the controller’s objectives is to minimize
this sum, i.e., to provide good setpoint tracking. (See “Optimization Problem”
on page 2-5 for more details.)
Here, the angular position should track its setpoint, but the applied torque
can vary, provided that it stays within the specified constraints. Therefore,
set the torque’s weight to zero, which tells the controller that setpoint tracking
is unnecessary for this output.
Similarly, it’s acceptable for the applied voltage to deviate from nominal (it
must in order to change the angular position!). Its weight should be zero
(the default for manipulated variables). On the other hand, it’s probably
undesirable for the controller to make drastic changes in the applied voltage.
The Rate weight penalizes such changes. Use the default, 0.1.
4-11
4 Case-Study Examples
When setting the rates, the relative magnitudes are more important than the
absolute values, and you must account for differences in the measurement
scales of each variable. For example, if a deviation of 0.1 units in variable A is
just as important as a deviation of 100 units in variable B, variable A’s weight
must be 1000 times larger than that for variable B.
The tables allow you to weight individual variables. The slider at the top
adjusts an overall trade-off between controller aggressiveness and setpoint
tracking. Moving the slider to the left places a larger overall penalty on
manipulated variable changes, making them smaller. This usually increases
controller robustness, but setpoint tracking becomes more sluggish.
4-12
Servomechanism Controller
4-13
4 Case-Study Examples
The Look ahead option designates that all future setpoint variations are
known. In that case, the controller can adjust the manipulated variable(s)
in advance to improve setpoint tracking. This would be unusual in practice,
and is not being used here.
Running a Simulation
Once you’re ready to run the scenario, click the Simulate button or the green
arrow on the toolbar.
Note The green arrow tool is available from any view once you’ve defined at
least one scenario. It runs the active scenario, i.e., the one most recently
selected or modified.
We obtain the results shown in Response to Unit Step in the Angular Position
Setpoint on page 4-14. The blue curves are the output signals, and the gray
curves are the corresponding setpoints. The response is very sluggish, and
hasn’t settled within the 30-second simulation period.
4-14
Servomechanism Controller
Note The window shown in Response to Unit Step in the Angular Position
Setpoint on page 4-14 provides many of the customization features available
in Control System Toolbox ltiview and sisotool displays. Try clicking
a curve to obtain the numerical characteristics of the selected point, or
right-clicking in the plot area to open a customization menu.
On the positive side, the applied torque stays well within bounds, as does the
applied voltage.
4-15
4 Case-Study Examples
The angular position now settles within 10 seconds following the step. The
torque approaches its lower limit, but doesn’t exceed it (see Faster Servo
Response on page 4-16) and the applied voltage stays within its limits (see
Manipulated Variable Adjustments on page 4-17).
4-16
Servomechanism Controller
As shown in Servo Response for Step Increase of π Radians on page 4-18 and
Voltage Adjustments on page 4-18, the servo response is essentially as good
as before, and we avoid exceeding the torque constraint at –78.5 Nm, even
though the applied voltage is saturated for about 2.5 seconds (see Voltage
Adjustments on page 4-18).
4-17
4 Case-Study Examples
Voltage Adjustments
4-18
Servomechanism Controller
To export a controller, right-click its node and select Export from the
resulting menu (or select the Controllers node, select the controller in the
list, and click the Export button). A dialog box like that shown in Exporting
a Controller to the Workspace on page 4-19 will appear.
The Controller source is the design from which you want to extract a
controller. There’s only one in this example, but in general you might be
working on several simultaneously. The Controller to export choice
defaults to the controller most recently selected. Again, there’s no choice in
this case, but there could be in general. The Name to assign edit box allows
you to rename the exported controller. (This will not change its name in the
design tool.)
Note When you exit the design tool, you will be prompted to save the entire
design in a MAT file. This allows you to reload it later using the File/Load
menu option or the Load icon on the toolbar.
4-19
4 Case-Study Examples
For example, suppose that you’ve defined the model as discussed in “Defining
the Plant Model” on page 4-4. Consider the following command sequence:
Like the LTI objects used to define linear, time-invariant dynamic models, an
MPC object contains a complete definition of a controller.
ServoMPC.PredictionHorizon = 12;
set(ServoMPC, 'PredictionHorizon', 12);
4-20
Servomechanism Controller
get(ServoMPC)
To access a particular property (e.g., the control horizon), you could type
either:
M = get(ServoMPC, 'ControlHorizon');
M = ServoMPC.ControlHorizon;
display(ServoMPC)
Running a Simulation
The sim command performs a linear simulation. For example, the following
code sequence defines constant setpoints for the two outputs, then runs a
simulation:
TimeSteps = round(10/Ts);
r = [pi 0];
[y, t, u] = sim(ServoMPC, TimeSteps, r);
By default, the model used to design the controller (stored in ServoMPC) also
represents the plant.
The sim command saves the output and manipulated variable sequences
in variables y and u. For example,
subplot(311)
plot(t, y(:,1), [0 t(end)], pi*[1 1])
4-21
4 Case-Study Examples
produces the custom plot shown in Plotting the Output of the sim Command
on page 4-22. The plot includes the angular position’s setpoint. The servo
response settles within 5 seconds with no overshoot. It also displays the
torque’s lower bound, which becomes active after about 0.9 seconds but isn’t
exceeded. The applied voltage saturates between about 0.5 and 2.8 seconds,
but the controller performs well despite this.
4-22
Servomechanism Controller
4-23
4 Case-Study Examples
• The MPC Controller output is the plant input. The Voltage Scope block
plots it (yellow curve). Minimum and maximum voltage values are shown
as magenta and cyan curves.
• The plant output is a vector signal. The first element is the measured
angular position. The second is the unmeasured torque. A Demux block
separates them. The angular position feeds back to the controller and plots
on the Angle scope (yellow curve). The torque plots on the Torque scope
(with its lower and upper bounds).
4-24
Servomechanism Controller
4-25
4 Case-Study Examples
The angular position tracks the sinusoidal setpoint variations well despite
saturation of the applied voltage. The setpoint variations are more gradual
than the step changes used previously, so the torque stays well within its
bounds.
4-26
Paper Machine Process Control
System Model
Ying et al. [1] studied the control of consistency (percentage pulp fibers in
aqueous suspension) and liquid level in a paper machine headbox, a schematic
of which is shown in Schematic of Paper Machine Headbox Elements on page
4-27.
The process is nonlinear, and has three outputs, two manipulated inputs, and
two disturbance inputs, one of which is measured for feedforward control.
x = [ H1 N2 ]
T
H2 N1
where H1 is the liquid level in the feed tank, H2 is the headbox liquid level,
N1 is the feed tank consistency, and N2 is the headbox consistency. The
measured outputs are:
4-27
4 Case-Study Examples
y = [ H2 N2 ]
T
N1
The primary control objectives are to hold H2 and N2 at setpoints. There are
two manipulated variables
T
u = ⎡⎣G p Gw ⎤⎦
where Gp is the flow rate of stock entering the feed tank, and Gw is the
recycled white water flow rate. The consistency of stock entering the feed
tank, Np, is a measured disturbance.
v = Np
d = Nw
Variables are normalized. All are zero at the nominal steady state and
have comparable numerical ranges. Time units are minutes. The process is
open-loop stable.
The mpcdemos folder contains the file mpc_pmmodel.m, which implements the
nonlinear model equations as a Simulink S-function. The input sequence is
Gp, Gw, Np, Nw, and the output sequence is 2, N1, N2.
A = [-1.9300 0 0 0
0.3940 -0.4260 0 0
0 0 -0.6300 0
0.8200 -0.7840 0.4130 -0.4260];
B = [1.2740 1.2740 0 0
0 0 0 0
1.3400 -0.6500 0.2030 0.4060
0 0 0 0];
4-28
Paper Machine Process Control
C = [0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000];
D = zeros(3,4);
(The last two commands are optional; they improve plot labeling.)
step(PaperMach);
4-29
4 Case-Study Examples
MPC Design
Type
mpctool
to open the MPC design tool. Import your LTI Paper Mach model as described
in “Opening MPCTOOL and Importing a Model” on page 4-6.
4-30
Paper Machine Process Control
Servo Response
Finally, select the Scenario1 node and define a servo-response test:
• Duration = 30
• H2 setpoint = 1 (constant)
Simulate the scenario. You should obtain results like those shown in
Servo Response for Unit Step in Headbox Level Setpoint on page 4-32 and
Manipulated Variable Moves on page 4-32.
4-31
4 Case-Study Examples
4-32
Paper Machine Process Control
Weight Tuning
The response time is about 8 minutes. We could reduce this by decreasing
the control interval, reducing the manipulated variable rate weights, and/or
eliminating the up/down rate constraints. The present design uses a
conservative control effort, which would usually improve robustness, so we
will continue with the current settings.
Note the steady-state error in N1 (it’s about –0.25 units in Servo Response
for Unit Step in Headbox Level Setpoint on page 4-32). There are only two
manipulated variables, so it’s impossible to hold three outputs at setpoints.
We don’t have a setpoint for N1 so we have set its weight to zero (see controller
settings in “Initial Controller Design” on page 4-31). Otherwise, all three
outputs would have exhibited steady-state error (try it).
Consistency control is more important than level control. Try decreasing the
H2 weight from 1 to 0.2. You should find that the peak error in N2 decreases
by almost an order of magnitude, but the H2 response time increases from
8 to about 18 minutes (not shown). Use these modified output weights in
subsequent tests.
Feedforward Control
To configure a test of the controller’s feedforward response, define a new
scenario by clicking the Scenarios node, clicking the New button, and
renaming the new scenario Feedforward (by editing its name in the tree
or the summary list).
If response plots from the above servo response tests are still open, close
them. Simulate the Feedforward scenario. You should find that the H2 and
N2 outputs deviate very little from their setpoints (not shown).
Experiment with the “look ahead” feature. First, observe that in the
simulation just completed the manipulated variables didn’t begin to move
until the disturbance occurred at t = 10 minutes. Return to the Feedforward
scenario, select the Look ahead option for the measured disturbance, and
repeat the simulation.
4-33
4 Case-Study Examples
Running the simulation should yield results like those in Feedback Scenario:
Unmeasured Disturbance Rejection on page 4-35. The two controlled outputs
(H2 and N2 ) exhibit relatively small deviations from their setpoints (which
are zero). The settling time is longer than for the servo response (compare
to Servo Response for Unit Step in Headbox Level Setpoint on page 4-32)
which is typical.
4-34
Paper Machine Process Control
One factor limiting performance is the chosen control interval of 2 time units.
The controller can’t respond to the disturbance until it first appears in the
outputs, i.e., at t = 2. If you wish, experiment with larger and smaller intervals
(modify the specification on the controller’s Model and Horizons tab).
To view the default assumptions, select the controller node (MPC1), and
click its Estimation tab. The resulting view should be as shown in Default
Estimator Assumptions: Output Disturbances on page 4-36. The status
message (bottom of figure) indicates that Model Predictive Control Toolbox
default assumptions are being used.
4-35
4 Case-Study Examples
Now consider the upper part of the figure. The Output Disturbances tab is
active, and its Signal-by-signal option is selected. According to the tabular
data, the controller is assuming independent, step-like disturbances (i.e.,
integrated white noise) in the first two outputs.
Click the Input Disturbances tab. Verify that the controller is also assuming
independent step-like disturbances in the unmeasured disturbance input.
4-36
Paper Machine Process Control
The disturbance magnitudes are unity by default. Making one larger than the
rest would signify a more important disturbance at that location.
Click the Measurement Noise tab. Verify that white noise (unit magnitude)
is being added to each output. The noise magnitude governs how much
influence each measurement has on the controller’s decisions. For example,
if a particular measurement is relatively noisy, the controller will give it
less weight, relying instead upon the model predictions of that output. This
provides a noise filtering capability.
mpc_papermachine
4-37
4 Case-Study Examples
Paper Machine Headbox Control Using MPC Tools in Simulink® on page 4-37
is a Simulink model in which the Model Predictive Control Toolbox controller
is being used to regulate the nonlinear paper machine headbox model. The
block labeled S-Function embodies the nonlinear model, which is coded in a
file called mpc_pmmodel.m.
As shown in the following dialog box, the MPC block references a controller
design called MPC1, which was exported to the MATLAB workspace from
the design tool. Note also that the measured disturbance inport is enabled,
allowing the measured disturbance to be connected as shown in Paper
Machine Headbox Control Using MPC Tools in Simulink® on page 4-37.
Test, Output Variables on page 4-39 shows the scope display from the
“Outputs” block for the setup of Paper Machine Headbox Control Using MPC
4-38
Paper Machine Process Control
4-39
4 Case-Study Examples
References
[1] Ying, Y., M. Rao, and Y. Sun “Bilinear control strategy for paper making
process,” Chemical Engineering Communications (1992), Vol. 111, pp. 13–28.
4-40
Transfer Bumplessly Between Manual and Automatic Operations
During startup of a continuous plant, the operators often adjust key actuators
manually until the plant is near the desired operating point, and then switch
to automatic control. If not done correctly, the transfer can cause a bump, i.e.,
large actuator movements.
A Model Predictive Controller must monitor all known plant signals even
when it is not in control of the actuators. This improves its state estimates
and allows a bumpless transfer to automatic operation.
open_system('mpc_bumpless');
num=[1 1];
den=[1 3 2 0.5];
4-41
4 Case-Study Examples
sys=tf(num,den);
step(sys)
The MPC controller object, MPC1, uses a sampling period of 0.5 seconds. In the
dialog for the MPC Controller block, specify MPC1 in the MPC controller box.
4-42
Transfer Bumplessly Between Manual and Automatic Operations
The optional input port for switching off the optimization is also selected,
which adds the inport labeled QP switch to the block (see Simulink® Block
Diagram for the MPC Bumpless Transfer Example on page 4-41).
The example tests the effect of switching the controller from automatic
to manual and back. To simulate this, a Pulse Generator block labeled
switching signal sends either one or zero to a switch. When it sends zero,
the system is in automatic mode, and the MPC block’s output goes to the
plant. Otherwise, the system is in manual mode, and the signal from the
Operator Commands block goes to the plant.
4-43
4 Case-Study Examples
In both cases the actual plant input feeds back to the controller, as shown in
Simulink® Block Diagram for the MPC Bumpless Transfer Example on page
4-41 (unless the plant input saturates at –1 or 1). The controller also monitors
the plant output at all times. Thus, the controller can update its estimate of
the plant state even when in manual.
The example also employs the optimization switching option. When the
system switches to manual, a nonzero signal enters the controller’s QP
Switch inport, turning off the optimization calculations, thereby reducing
computational effort. The benefit is small in this trivial example but it could
be significant in a demanding real-time application.
As shown in Output, Reference and Switching Signal on page 4-44, the system
is in automatic mode for the first 90 time units (switching signal is zero).
During this time the controller smoothly drives the controlled plant output
from its initial value, 0, to the desired reference value, –0.5.
At time 90, manual operation begins (switching signal goes from zero to one).
This causes the Switch element to send the operator commands to the plant
instead of the controller output.
4-44
Transfer Bumplessly Between Manual and Automatic Operations
Once in manual mode, the operator commands set the manipulated variable
to –0.5 for 10 time units, and then to 0. Output, Reference and Switching
Signal on page 4-44 shows the open-loop response between times 90 and 180
when the controller is deactivated.
At time 180, the system switches back to automatic mode. Output, Reference
and Switching Signal on page 4-44 shows that the output returns to the
reference value smoothly, and Manipulated Variable (Actuator) Adjustments
on page 4-45 shows similarly smooth adjustments in the controller output.
Note that the controller’s state estimator has default zero initial conditions,
which are appropriate when this simulation begins. Thus, there is no bump
at startup. In general you should start the system running in manual mode
for long enough to allow the controller to acquire an accurate state estimate
before switching to automatic mode.
4-45
4 Case-Study Examples
When the system switches to manual between 90 and 180, the plant behavior
is the same as before but the controller tries in vain to hold the plant at
the setpoint. Consequently, its output increases and eventually saturates.
It assumes this output is going to the plant, so its state estimates become
inaccurate. Thus, when the system switches to automatic mode at time 180,
there is a large bump.
4-46
Transfer Bumplessly Between Manual and Automatic Operations
4-47
4 Case-Study Examples
4-48
Coordinate Multiple Controllers at Different Operating Points
4-49
4 Case-Study Examples
The control system can adjust the coolant temperature in order to regulate
the reactor state and the rate of the exothermic main reaction. The other two
inputs are independent unmeasured disturbances.
The Simulink diagram for this example appears below. The CSTR model is
a masked subsystem. The feed temperature and composition are constants.
As discussed above, the control system adjusts the coolant temperature (the
Tc input on the CSTR block).
The two CSTR outputs are the reactor temperature and composition
respectively. These are being sent to a scope display and to the control system
as feedback.
In that case why supply the temperature measurement to the controller? The
main reason is to improve state estimation. If this were not done, the control
4-50
Coordinate Multiple Controllers at Different Operating Points
system would have to infer the temperature value from the concentration
measurement, which would introduce an estimation error and degrade the
model’s predictive accuracy.
The rationale for the Switch 1 and Switch 2 blocks appears below.
The figure below shows the Multi MPC Controller mask. The block is
coordinating three controllers (MPC1, MPC2 and MPC3 in that sequence). It is
also receiving the setpoint signal from the workspace, and the Look ahead
option is active. This allows the controller to anticipate future setpoint values
and usually improves setpoint tracking.
4-51
4 Case-Study Examples
In practice, you would probably obtain the three models from data. This
example linearizes the nonlinear model at the above three conditions (for
details see “Using Simulink to Develop LTI Models” in the Getting Started
Guide).
The following code obtains the linear models and designs the three controllers
4-52
Coordinate Multiple Controllers at Different Operating Points
Controllers = cell(1,3);
Concentrations = [8.5 5.5 2];
Y = yp;
for i = 1:Nc
clear Model
Y(2) = Concentrations(i);
[X,U,Y,DX]=trim('CSTR_INOUT',xp(:),up(:),Y(:),[],[1,2]',2)
[a,b,c,d]=linmod('CSTR_INOUT', X, U );
Plant = ss(a,b,c,d);
Plant.InputGroup.MV = 3;
Plant.InputGroup.UD = [1,2];
Model.Plant = Plant;
Model.Nominal.U = [0; 0; up(3)];
Model.Nominal.X = xp;
Model.Nominal.Y = yp;
MPCobj = mpc(Model, Ts);
MPCobj.Weight.OV = [0 1];
D = ss(getindist(MPCobj));
D.b = D.b*10;
set(D,'InputName',[],'OutputName',[],'InputGroup',[], ...
'OutputGroup',[]);
setindist(MPCobj, 'model', D);
Controllers{i} = MPCobj;
end
MPC1 = Controllers{1};
MPC2 = Controllers{2};
MPC3 = Controllers{3}
• All three controllers use the same nominal condition, the values of the plant
inputs and outputs at the initial steady-state. Exception: all unmeasured
disturbance inputs must have zero nominal values.
• Each controller employs a different prediction model. The model structure
is the same in each case (input and outputs are identical in number
and type) but each model represents a particular steady-state reactor
composition.
• It turns out that the MPC2 plant model obtained at 5 kmol/m3 is open-loop
unstable. We must use a model structure that promotes a stable Kalman
4-53
4 Case-Study Examples
4-54
Coordinate Multiple Controllers at Different Operating Points
The above plots show the simulation results. The Multi MPC Controller
block uses the three controllers sequentially as expected (see the switching
signal). Tracking of the concentration setpoint is excellent and the reactor
temperature is also controlled well.
For comparison the plots below show the results for the same scenario if
we force MPC3 to be active for the entire simulation. The CSTR evenually
stabilizes at the desired steady-state but both the reactor temperature and
composition exhibit large excursions away from the desired conditions.
4-55
4 Case-Study Examples
4-56
Using Custom Constraints in Blending Process
3
dv
i
d i1
d j 3
V
d
ij j i
i1
where V is the mixture inventory (in the container), ϕi is the flow rate of the
ith feed, ϕ is the demand, i.e., the rate at which the blend is being removed
from inventory, γij is the concentration of constituent j in feed i, γj is the
concentration of j in the blend, and τ is time. In this example, there are two
important constituents, j = 1 and 2.
The control objectives are targets for the blend’s two constituent
concentrations and the mixture inventory. The challenge is that the demand
ϕ and feed compositions γij vary. The inventory, blend compositions, and
demand are measured, but the feed compositions are unmeasured.
4-57
4 Case-Study Examples
The process design allows manipulation of the total feed entering the mixing
chamber and the individual rates of feeds 2 and 3. In other words, the rate
of feed 1 is:
ϕ 1 = ϕT – ϕ 2 – ϕ 3
0 ≤ ϕi ≤ ϕi,max
The equations are normalized such that—at the nominal steady state—the
mean residence time in the mixing container is τ = 1. The target inventory is
V = 1, and the target blend composition is γ1 = γ2 = 1.
In the model, an MPC controller controls the blending process. The block
labeled Blending incorporates the previously described model equations
and includes unmeasured (step) disturbances in the feed compositions.
4-58
Using Custom Constraints in Blending Process
u = [ϕT ϕ2 ϕ3].
The plant is mildly nonlinear. You can derive a linear model at the nominal
steady state. This approach is quite accurate unless the (unmeasured) feed
compositions change. If the change is sufficiently large, the steady-state
gains of the nonlinear process change sign and the closed-loop system can
become unstable.
4-59
4 Case-Study Examples
% Normalize the linear model such that the target demand is 1 and the
% product composition is 1:
fin_nom = Fin_nom/F_nom;
gij = [cin_nom(1,:)/cout_nom(1)
cin_nom(2,:)/cout_nom(2)];
% Create the state-space model with feed flows |[F1, F2, F3]| as MVs:
A = [ zeros(1,nc+1)
zeros(nc,1) -eye(nc)];
Bu = [ones(1,ni)
gij-1];
% Change MV definition to [FT, F2, F3] where F1 = FT - F2 - F3
Bu = [Bu(:,1), Bu(:,2)-Bu(:,1), Bu(:,3)-Bu(:,1)];
% Add the blend demand as the 4th model input, a measured disturbance
Bv = [-1
zeros(nc,1)];
B = [Bu Bv];
% All the states (inventory and compositions) are measurable
C = eye(nc+1);
% No direct feed-through term
D = zeros(nc+1,ni+1);
% Construct the plant model
Model = ss(A, B, C, D);
Model.InputName = {'F_T','F_2','F_3','F'};
Model.InputGroup.MV = 1:3;
Model.InputGroup.MD = 4;
Model.OutputName = {'V','c_1','c_2'};
% Create the controller object with sampling period, prediction and control
% horizons:
4-60
Using Custom Constraints in Blending Process
Ts = 0.1;
p=10;
m=3;
MPCobj = mpc(Model, Ts, p, m);
% The outputs are the inventory |y(1)| and the constituent concentrations
% |y(2)| and |y(3)|. Specify nominal values of unity after normalization:
MPCobj.Model.Nominal.Y = [1 1 1];
% The manipulated variables are |u1 = FT|, |u2 = F2|, |u3 = F3|. Specify
% nominal values after normalization:
MPCobj.Model.Nominal.U = [1 fin_nom(2) fin_nom(3) 1];
% Specify output tuning weights. Larger weights are assigned to the first
% two outputs because we pay more attention to controlling the inventory
% and composition of the first blending material:
MPCobj.Weights.OV = [1 1 0.5];
The total feed rate and the rates of feed 2 and feed 3 have upper bounds.
Feed 1 also has an upper bound, determined by the upstream unit
supplying it. Under normal conditions, the plant operates far from these
bounds but for the scenario outlined previously, the controller must reduce
the rate of feed 1 drastically, as it is bringing in excess constituent 1. To do
this, the controller must increase the rates of feeds 2 and 3 (keeping the
total feed rate close to the demand rate to maintain the target inventory.)
4 Specify constraints.
Given the specified bounds on the feed 2 and 3 rates (= 0.6), it is possible
that their sum could be as much as 1.2. Because the total feed rate is of
4-61
4 Case-Study Examples
order 0.9 to 1.0, the controller can request a physically impossible condition
in which the sum of feeds 2 and 3 exceeds the total feed rate. This implies a
negative feed 1 rate.
The constraint
0 ≤ ϕ1 = ϕT – ϕ2 – ϕ3 ≤ 0.8
E = [-1 1 1; 1 -1 -1];
5 Simulate the model and plot the input and output signals.
sim('mpc_blendingprocess')
figure
plot(MVs.time,[MVs.signals(1).values(:,2), ...
(MVs.signals(2).values + MVs.signals(3).values), ...
4-62
Using Custom Constraints in Blending Process
(MVs.signals(1).values(:,2)-MVs.signals(2).values-MVs.signals(3).values)])
grid
legend('FT','F2+F3','F1')
The plot shows the evolution of the total feed rate (blue curve) and the sum
of feeds 2 and 3 (green curve). They coincide between τ = 1.7 and τ = 2.2.
If the custom input constraints had not been included, the controller would
have requested a negative feed 1 rate during this period, as shown in by
the red curve.
The controller maintains the inventory very close to its setpoint, but the
severe disturbance in the feed composition causes a prediction error and a
large disturbance in the blend composition (especially for constituent 1).
Despite this, the controller recovers and drives the blend composition back
to its setpoint, as shown in the following output of the CVs scope.
4-63
4 Case-Study Examples
Related Examples
More About
4-64
Refine Controller Tuning Weights Using the Tuning Advisor
You can access the Tuning Advisor from the Scenarios node in the Control
and Estimation Tools Manager. Before you use the Advisor, choose the
controller horizons and sampling period, specify constraints, and select a
disturbance estimator (if the default estimator is inappropriate). The Advisor
does not provide help with these parameters.
The example considered here is a plant with four controlled outputs and
four manipulated variables. There are no measured disturbances and the
unmeasured disturbances are unmodeled.
After starting the design tool and importing the plant model, G, which
becomes the controller design basis, we accept the default values for all
controller parameters. We also load a second plant model, Gp, in which all
parameters of G have been perturbed randomly with a standard deviation of
5%.
4-65
4 Case-Study Examples
The scenario shown in the previous figure specifies the controller based on
G and the plant Gp. In other words, it tests the controllers robustness with
respect to plant-model mismatch. It also defines a series of setpoint changes
and disturbances.
Clicking Tuning Advisor opens the MPC Tuning Advisor window. In the
Tuning Advisor window, we specify the following settings:
• Select the IAE performance function (an arbitrary choice for illustration
only).
• Set all input performance weights to zero because the application does
not have input targets.
• Set all input rate performance weights to zero because the application has
no cost for manipulated variable movement.
4-66
Refine Controller Tuning Weights Using the Tuning Advisor
The Tuning Advisor resembles the previous figure. The sensitivity values
indicate that a decrease in the Out4 weight or an increase in the Out2 weight
would have the most impact. In general, however, the output tuning weights
should reflect the setpoint tracking priorities and it’s preferable to adjust the
input rate tuning weights.
Sensitivities for Input Rate Weights In1 and In4 are of roughly equal
magnitude but the In4 suggestion is a decrease and this weight is already
near its lower bound of zero. Thus, we focus on the In1 weight.
4-67
4 Case-Study Examples
The next figure shows the Advisor after the In1 weight has been increased in
several steps from 0.1 to 4. Performance has improved by nearly 20% relative
to the baseline. Sensitivities indicate that further adjustments to in input
rate tuning weights will have little impact.
The next figure shows the Tuning Advisor after additional adjustments. At
this point, some sensitivities are still rather large, but a small change in the
indicated tuning weight causes the sensitivity to change sign. Therefore,
futher progress will be difficult.
4-68
Refine Controller Tuning Weights Using the Tuning Advisor
4-69
4 Case-Study Examples
The standard MPC cost function is similar to that used in an LQR controller
with output weighting, as shown in the following equation:
J (u) y(k i)T Qy(k i) u(k i 1)T Ru(k i 1)
i1 (4-1)
The LQR and MPC cost functions differ in the following ways:
• The LQR cost function forces y and u towards zero whereas the MPC cost
function forces y and u toward nonzero setpoints.
You can shift the MPC prediction model’s origin to eliminate this difference
and achieve zero setpoints at nominal condition.
• The LQR cost function uses an infinite prediction horizon in which the
manipulated variable changes at each sampling instant. In the standard
MPC cost function, the horizon length is p, and the manipulated variable
changes m times, where m is the control horizon.
The two cost functions are equivalent if the MPC cost function is:
p1
J (u) y(k i)T Qy(k i) u(k i 1)T Ru(k i 1) x(k p)T Qp x(k p)
i1 (4-2)
4-70
Providing LQR Performance Using Terminal Penalty
A = [1 0;0.1 1];
B = [0.1; 0.005];
C = eye(2);
D = zeros(2,1);
Ts = 0.1;
Plant = ss(A, B, C, D, Ts);
Plant.InputName = {'u'};
Plant.OutputName = {'x_1', 'x_2'};
Q = eye(2);
R = 1;
[K, Qp] = lqry(Plant, Q, R);
Q and R are output and input weight matrices, respectively. Qp is the Ricatti
matrix.
NewPlant = Plant;
cholP = chol(Qp);
set(NewPlant,'C',[C;cholP],'D',[D;zeros(2,1)],'OutputName', {'x_1', 'x_2', 'Cx_1', 'Cx_2'});
NewPlant.InputGroup.MV = 1;
NewPlant.OutputGroup.MO = [1 2];
NewPlant.OutputGroup.UO = [3 4];
4-71
4 Case-Study Examples
P = 3;
M = 3;
MPCobj = mpc(NewPlant, Ts, P, M);
When there are no constraints, you can use a rather short horizon (in
this case, p ≥ 1 gives identical results).
c Specify weights for manipulated variable (MV) and output variable (OV).
ywt = sqrt(diag(Q))';
uwt = sqrt(diag(R))';
MPCobj.Weights.OV = [ywt 0 0];
MPCobj.Weights.MV = uwt;
MPCobj.Weights.MVrate = 1e-6;
The two augmented outputs have zero weights during the prediction
horizon.
d Specify terminal weights.
To obtain the desired effect, define unity weights for these at the final
point in the horizon.
U = struct('Weight', uwt);
Y = struct('Weight', [0 0 1 1]);
setterminal(MPCobj, Y, U);
setoutdist(MPCobj,'remove'); % Remove added state estimator
setestim(MPCobj, C); % State estimates = measured values
Tstop = 6;
4-72
Providing LQR Performance Using Terminal Penalty
x0 = [0.2; 0.2];
% compute closed-loop response with LQR
clsys = feedback(Plant,K);
[yLQR tLQR] = initial(clsys,x0,Tstop);
SimOptions = mpcsimopt(MPCobj);
SimOptions.PlantInitialState = x0;
r = zeros(1,4);
[y, t, u] = sim(MPCobj, ceil(Tstop/Ts), r, SimOptions);
Cost = sum(sum(y(:,1:2)*diag(ywt).*y(:,1:2))) + sum(u*diag(uwt).*u);
figure;
h1 = line(tSTD,ySTD,'color','r');
Annotation = get(h1,'Annotation');
set(get(Annotation{2},'LegendInformation'),'IconDisplayStyle','off');
h2 = line(t,y(:,1:2),'color','b');
Annotation = get(h2,'Annotation');
set(get(Annotation{2},'LegendInformation'),'IconDisplayStyle','off');
h3 = line(tLQR,yLQR,'color','m','marker','o','linestyle','none');
Annotation = get(h3,'Annotation');
set(get(Annotation{2},'LegendInformation'),'IconDisplayStyle','off');
xlabel('Time');
ylabel('Plant Outputs');
legend('Standard MPC','MPC with Terminal Weigths','LQR','Location','NorthEast')
4-73
4 Case-Study Examples
In the following plot, the MPC with the terminal weights provides faster
settling to the origin than the standard MPC. The LQR controller and
MPC with terminal weights provide identical control performance.
You can improve the standard MPC by retuning. For example, use the
same state estimation strategy. If the prediction and control horizons
are then increased, it provides essentially the same performance.
This example shows that using a terminal penalty can eliminate the need to
tune the MPC prediction and control horizons for the unconstrained case. If
your application includes constraints, using a terminal weight is insufficient
to guarantee nominal stability. You must also choose appropriate horizons
and possibly add terminal constraints. For an in-depth discussion, see
Rawlings and Mayne [2].
4-74
Providing LQR Performance Using Terminal Penalty
Although you can design and implement such a controller in Model Predictive
Control Toolbox software, you might find designing the standard MPC
controller more convenient.
Related Examples
More About
References
[1] Scokaert, P. O. M. and J. B. Rawlings “Constrained linear quadratic
regulation” IEEE Transactions on Automatic Control (1998), Vol. 43, No.
8, pp. 1163-1169.
4-75
4 Case-Study Examples
The example uses the Matrikon™ Simulation OPC server to simulate the
behavior of an industrial process on Windows® operating system.
Download and install the server and set it running either as a service or
as an application.
if ~mpcchecktoolboxinstalled('opc')
disp('The example needs OPC Toolbox(TM).')
end
if mpcchecktoolboxinstalled('opc')
% Clear any existing opc connections.
opcreset
% Flush the callback persistent variables.
clear mpcopcPlantStep;
clear mpcopcMPCStep;
try
h = opcda('localhost','Matrikon.OPC.Simulation.1');
connect(h);
catch ME
disp('The Matrikon(TM) OPC Simulation Server must be running on the
return
end
end
4-76
Real-Time Control with OPC Toolbox
In practice the plant would be a physical process, and the OPC tags which
define its I/O would already have been created on the OPC server. However,
since in this case a simulation OPC server is being used, the plant behavior
must be simulated. This is achieved by defining tags for the plant manipulated
and measured variables and creating a callback (mpcopcPlantStep) to
simulate plant response to changes in the manipulated variables. Two OPC
groups are required, one to represent the two manipulated variables to be
read by the plant simulator and another to write back the two measured plant
outputs storing the results of the plant simulation.
if mpcchecktoolboxinstalled('opc')
% Build an opc group for 2 plant inputs and initialize them to zero.
plant_read = addgroup(h,'plant_read');
imv1 = additem(plant_read,'Bucket Brigade.Real8', 'double');
writeasync(imv1,0);
imv2 = additem(plant_read,'Bucket Brigade.Real4', 'double');
writeasync(imv2,0);
% Build an opc group for plant outputs.
plant_write = addgroup(h,'plant_write');
opv1 = additem(plant_write,'Bucket Brigade.Time', 'double');
opv2 = additem(plant_write,'Bucket Brigade.Money', 'double');
set(plant_write,'WriteAsyncFcn',[]) % Suppress command line display.
end
Specify the MPC Controller Which Will Control the Simulated Plant
4-77
4 Case-Study Examples
y1 = mpcmove(mpcobj,state,[1;1]',[1 1]');
Build two OPC groups, one to read the two measured plant outputs and the
other to write back the two manipulated variables.
if mpcchecktoolboxinstalled('opc')
% Build an opc group for MPC inputs.
mpc_read = addgroup(h,'mpc_read');
impcpv1 = additem(mpc_read,'Bucket Brigade.Time', 'double');
writeasync(impcpv1,0);
impcpv2 = additem(mpc_read,'Bucket Brigade.Money', 'double');
writeasync(impcpv2,0);
impcref1 = additem(mpc_read,'Bucket Brigade.Int2', 'double');
writeasync(impcref1,1);
impcref2 = additem(mpc_read,'Bucket Brigade.Int4', 'double');
writeasync(impcref2,1);
% Build an opc group for mpc outputs.
mpc_write = addgroup(h,'mpc_write');
additem(mpc_write,'Bucket Brigade.Real8', 'double');
additem(mpc_write,'Bucket Brigade.Real4', 'double');
% Suppress command line display.
set(mpc_write,'WriteAsyncFcn',[]);
end
Build OPC Groups to Trigger Execution of the Plant Simulator & Controller
Build two opc groups based on the same external opc timer to trigger
execution of both plant simulation and MPC execution when the contents of
the OPC time tag changes.
4-78
Real-Time Control with OPC Toolbox
if mpcchecktoolboxinstalled('opc')
gtime = addgroup(h,'time');
time_tag = additem(gtime,'Triangle Waves.Real8');
set(gtime,'UpdateRate',1);
gtime.DataChangeFcn = {@mpcopcPlantStep plant_read plant_write disc_pla
gmpctime = addgroup(h,'mpctime');
additem(gmpctime,'Triangle Waves.Real8');
set(gmpctime,'UpdateRate',1);
gmpctime.DataChangeFcn = {@mpcopcMPCStep mpc_read mpc_write mpcobj};
end
Log the plant measured outputs from tags ’Bucket Brigade.Money’ and
’Bucket Brigade.Money’.
if mpcchecktoolboxinstalled('opc')
set(mpc_read,'RecordsToAcquire',40);
start(mpc_read);
while mpc_read.RecordsAcquired < mpc_read.RecordsToAcquire
pause(3)
fprintf('Logging data: Record %d / %d',mpc_read.RecordsAcquired,...
mpc_read.RecordsToAcquire)
end
stop(mpc_read);
end
if mpcchecktoolboxinstalled('opc')
[itemID, value, quality, timeStamp, eventTime] = getdata(mpc_read,'doub
plot((timeStamp(:,1)-timeStamp(1,1))*24*60*60,value)
title('Measured Outputs Logged from Tags Bucket Brigade.Time,Bucket Bri
xlabel('Time (secs)');
end
4-79
4 Case-Study Examples
Required Products
if ~mpcchecktoolboxinstalled('simulink')
disp('Simulink(R) is required to run this example.')
return
end
if ~mpcchecktoolboxinstalled('simulinkcoder')
disp('Simulink(R) Coder(TM) is required to run this example.');
return
end
Setup
You must have write-permission to generate the relevant files and the
executable. So, before starting simulation and code generation, change the
current directory to a temporary directory.
cwd = pwd;
tmpdir = tempname;
mkdir(tmpdir);
cd(tmpdir);
4-80
Simulation and Code Generation Using Simulink Coder
mdl = 'mpc_rtwdemo';
open_system(mdl);
sim(mdl);
The controller effort and the plant output are saved into base workspace
as variables u and y, respectively.
if ispc
disp('Running executable...');
status = system(mdl);
else
disp('The example only runs the executable on Windows system.');
end
4-81
4 Case-Study Examples
Compare the responses from the generated code (rt_u and rt_y) with the
responses from the previous simulation in Simulink (u and y).
bdclose(mdl);
You can also configure the MPC block to use single-precision in simulation
and code generation.
mdl = 'mpc_rtwdemo_single';
open_system(mdl);
To do that, open the MPC block dialog and select "single" as the "output data
type" at the bottom of the dialog.
The controller effort and the plant output are saved into base workspace
as variables u1 and y1, respectively.
4-82
Simulation and Code Generation Using Simulink Coder
if ispc
disp('Running executable...');
status = system(mdl);
else
disp('The example only runs the executable on Windows system.');
end
Compare the responses from the generated code (rt_u1 and rt_y1) with the
responses from the previous simulation in Simulink (u1 and y1).
bdclose(mdl);
cd(cwd)
4-83
4 Case-Study Examples
Required Products
To run this example, Simulink® and Simulink® PLC Coder™ are required.
if ~mpcchecktoolboxinstalled('simulink')
disp('Simulink(R) is required to run this example.')
return
end
if ~mpcchecktoolboxinstalled('plccoder')
disp('Simulink(R) PLC Coder(TM) is required to run this example.');
return
end
Setup
You must have write-permission to generate the relevant files and the
executable. So, before starting simulation and code generation, change the
current directory to a temporary directory.
cwd = pwd;
tmpdir = tempname;
mkdir(tmpdir);
cd(tmpdir);
4-84
Simulation and Structured Text Generation Using PLC Coder
mdl = 'mpc_plcdemo';
open_system(mdl);
To generate structured text for the MPC Controller block, complete the
following two steps:
• Configure the MPC block to use single precision. Select "single" in the
"Output data type" combo box in the MPC block dialog.
• Put MPC block inside a subsystem block and treat the subsystem block as
an atomic unit. Select the "Treat as atomic unit" checkbox in the subsystem
block dialog.
To generate code with the PLC Coder, use the plcgeneratecode command.
4-85
4 Case-Study Examples
The Message Viewer dialog box shows that PLC code generation was
successful.
bdclose(mdl);
cd(cwd)
4-86
Setting Targets for Manipulated Variables
if ~mpcchecktoolboxinstalled('simulink')
disp('Simulink(R) is required to run this example.')
return
end
N1=[3 1];
D1=[1 2*.3 1];
N2=[2 1];
D2=[1 2*.5 1];
sys=ss(tf({N1,N2},{D1,D2}),'min');
A=sys.a;B=sys.b;C=sys.c;D=sys.d;
x0=[0 0 0 0]';
clear MV
MV(1)=struct('RateMin',-.5,'RateMax',.5);
4-87
4 Case-Study Examples
MV(2)=struct('RateMin',-.5,'RateMax',.5);
The following sets up a target set-point u=2 for the first manipulated variable.
bdclose('mpc_utarget')
4-88
Specifying Alternative Cost Function with Off-Diagonal Weight Matrices
Let us assume default value for weights and build the MPC object.
MPCobj=mpc(model,Ts,p,m);
clear MV
MV(1)=struct('Min',-3,'Max',3,'RateMin',-100,'RateMax',100);
MV(2)=struct('Min',-2,'Max',2,'RateMin',-100,'RateMax',100);
MPCobj.MV=MV;
4-89
4 Case-Study Examples
close all
[y,t,u]=sim(MPCobj,Tf,r);
subplot(211)
plot(t,y(:,1)-r(1,1)-y(:,2)+r(1,2));grid
title('(y_1-r_1)-(y_2-r_2)');
subplot(212)
plot(t,u);grid
title('u');
if ~mpcchecktoolboxinstalled('simulink')
disp('Simulink(R) is required to run this part of the example.')
return
end
[A,B,C,D]=ssdata(sys);
4-90
Specifying Alternative Cost Function with Off-Diagonal Weight Matrices
open_system('mpc_weightsdemo');
sim('mpc_weightsdemo',Tstop)
bdclose('mpc_weightsdemo');
4-91
4 Case-Study Examples
Inputs:
Outputs:
The fuel gas blending process was studied by Muller et al.: "Modeling,
validation, and control of an industrial fuel gas blending system", C.J. Muller,
I.K. Craig, N.L. Ricker, J. of Process Control, in press, 2011.
Use the following linear plant model as the prediction model for the controller.
This state-space model, applicable at a typical steady-state operating point,
uses the time unit of hours.
4-92
Review Model Predictive Controller for Stability and Robustness Issues
Transport delay is added to plant outputs to reflect the delay in the sensors.
The sampling time is that of the sensors (20 seconds). The prediction horizon
is approximately equal to the plant settling time (39 intervals). The control
4-93
4 Case-Study Examples
horizon uses four blocked moves that have lengths of 2, 6, 12 and 19 intervals
respectively. The nominal operating conditions are non-zero. The output
measurement noise is white noise with magnitude of 0.001.
Since all the manipulated variables are flow rates of gas streams, their lower
bounds are zero. All the MV constraints are hard (MinECR and MaxECR
= 0) by default.
MVmin = zeros(1,6);
MVmax = [15, 20, 5, 5, 30, 30];
for i = 1:6
Obj.MV(i).Min = MVmin(i);
Obj.MV(i).Max = MVmax(i);
end
The bounds are set large enough to allow full range of movement in
one interval. All the MV rate constraints are hard (RateMinECR and
RateMaxECR = 0) by default.
for i = 1:6
Obj.MV(i).RateMin = -MVmax(i);
Obj.MV(i).RateMax = MVmax(i);
end
4-94
Review Model Predictive Controller for Stability and Robustness Issues
for i = 1:4
Obj.OV(i).Min = OVmin(i);
Obj.OV(i).Max = OVmax(i);
end
MV weights are specified based on the relative cost of the blended streams.
This tells MPC controller how to move the six manipulated variables in order
to minimize the cost of the blended fuel gas.
Obj.Weights.MVrate = 1.22*ones(1,6);
The OV weights reflect the relative magnitudes of the output variable signals,
considering that the predictive model is not scaled. Since the nominal value
of the header pressure (the 4th output) is relatively large, set its weight
smaller to compensate.
review(Obj)
The summary table shown above lists two warnings. The first warning is that
the controller does not drive the output variables to their targets at steady
state. Click Closed-Loop Steady-State Gains to see a list of the non-zero
gains.
4-95
4 Case-Study Examples
The first entry in the list shows that adding a sustained disturbance of
unit magnitude to the HHV output would cause the HHV to deviate 0.0156
units from its steady-state target, assuming no constraints are active. The
second entry shows that a unit disturbance in WI would cause a steady-state
deviation ("offset") of -0.0469 in HHV, etc.
Since there are six MVs and only four OVs, enough degrees of freedom are
available in control system and you might be surprised to see non-zero
steady-state offset. The root cause is the non-zero MV weights we use to force
the plant toward the most economical operating condition.
The non-zero steady-state offsets are often undesirable but they are acceptable
in this case because: # The primary objective is to minimize the blend cost
and the gas quality is allowed to float as long as it stays within the specified
limits # When a process disturbance is present small offset gain magnitudes
indicate that the impact of disturbance would be limited. # Small violations of
those limits would be acceptable as well because output constraints are soft.
If an external event causes the NG to go far below its specified minimum, the
constraint on its rate of increase might make it impossible to return the NG
within bounds in one interval. In other words, when you specify both MV.Min
and MV.RateMax, the controller would not be able to find an optimal solution
if the most recent MV value is less than (MV.Min - MV.RateMax). Similarly,
there is a potential conflict when you specify both MV.Max and MV.RateMin.
for i = 1:6
4-96
Review Model Predictive Controller for Stability and Robustness Issues
Obj.MV(i).RateMinECR = 0.1;
Obj.MV(i).RateMaxECR = 0.1;
end
review(Obj)
Assuming that a new design requirement allows the controlled outputs vary
freely within their limits, consider eliminating the weights on them:
Obj.Weights.OV = zeros(1,4);
review(Obj)
We see that the review has flagged the zero weights on all four output
variables. But since the zero weights come from design requirement and the
other Hessian tests indicate that the quadratic programming problem should
have a unique solution, this warning can be safely ignored.
4-97
4 Case-Study Examples
Click Soft Constraints to see a list of soft constraints -- in this case an upper
and lower bound on each OV.
The Impact Factor column shows that using the default MinECR and
MaxECR values gives the pressure (P) a much higher priority than the other
OVs. If we want the priorities to be more comparable, we should increase the
pressure constraint ECR values and adjust the others too. For example, use
Obj.OV(1).MinECR = 0.5;
Obj.OV(1).MaxECR = 0.5;
Obj.OV(3).MinECR = 3;
Obj.OV(3).MaxECR = 3;
Obj.OV(4).MinECR = 80;
Obj.OV(4).MaxECR = 80;
review(Obj)
Notice from the Sensitivity Ratio column that all the sensitivity ratios are
now less than unity. This means that the soft constraints will receive less
4-98
Review Model Predictive Controller for Stability and Robustness Issues
attention than other terms in the MPC objective function, such as deviations
of the MVs from their target values. Thus, it is likely that an output
constraint violation would occur.
In order to give the output constraints higher priority than other MPC
objectives, increase the Weights.ECR parameter from default 1e5 to a higher
value to harden all the soft OV constraints.
Obj.Weights.ECR = 1e8;
review(Obj)
Click Memory Size for MPC Data to see the estimated memory size needed
to store the MPC data matrices used on the hardware.
mpcverbosity(MPC_verbosity);
[~, hWebBrowser] = web;
close(hWebBrowser);
4-99
4 Case-Study Examples
Bibliography
[1] Seborg, D. E., T. F. Edgar, and D. A. Mellichamp Process Dynamics and
Control, 2nd Edition (2004), Wiley, pp. 34–36.
[2] Rawlings, J. B., and David Q. Mayne “Model Predictive Control: Theory
and Design” Nob Hill Publishing, 2010.
4-100
5
This chapter is the reference manual for the Model Predictive Control Toolbox
design tool (graphical user interface).
mpctool
The design tool is part of the Control and Estimation Tools Manager. When
invoked as shown above, the design tool opens and creates a new project
named MPC Design Task.
If you started the tool previously, the above command makes the tool visible
but does not create a new project.
5-2
Working with the Design Tool
and click the Design button. If the MPC controller field is empty, the
design tool will create a default controller. Otherwise, it will load the named
controller object, which must be in your base workspace. You can then view
and modify the controller design.
1 Select the Workspace node in the Control and Estimation Tools Manager.
5-3
5 Reference for the Design Tool GUI
3 In the New Project dialog box, click the Select check box for Model
Predictive Control Task: MPC Controller or Model Predictive
Control Task: Multiple MPC Controllers.
Click OK.
Menu Bar
The design tool’s menu bar appears whenever you’ve selected a Model
Predictive Control Toolbox project or task in the tree (see “Tree View” on page
5-7). The menu bar’s MPC option distinguishes it from other control and
estimation tools. See the example below. The following sections describe
each menu option.
File Menu
Load. Loads a saved design. A dialog box asks you to specify the MAT-file
containing the saved design. If the MAT-file contains multiple projects, you
must select the one(s) to be loaded (see example below).
5-4
Working with the Design Tool
You can also load a design using the toolbar (see “Toolbar” on page 5-6).
Save. Saves a design so you can use it later. The data are saved in a
MAT-file. A dialog allows you to specify the file name (see below). If you are
working on multiple projects, you can select those to be saved.
You can also select the Save option using the toolbar (see “Toolbar” on page
5-6).
Close. Closes the design tool. If you’ve modified the design, you’ll be asked
whether or not you want to save it before closing.
MPC Menu
• Plant model – Import a plant model using the model import dialog box
(see “Importing a Plant Model” on page 5-8).
• Controller – Import a controller using the controller import dialog box
(see “Importing a Controller” on page 5-14).
5-5
5 Reference for the Design Tool GUI
Export. Export a controller using the export dialog box (see “Exporting a
Controller” on page 5-16). This option is disabled until your project includes
at least one controller.
Simulate. Simulate the current scenario, i.e., the one most recently simulated
or selected in the tree (see “Tree View” on page 5-7). You can select this
option from the keyboard by pressing Ctrl+R, or using the toolbar icon (see
“Toolbar” on page 5-6).
The Simulate option is disabled until your project includes at least one valid
simulation scenario.
Toolbar
The toolbar, shown in the following figure, lets you perform the following
tasks:
For more information on the first three tasks, see the following:
The text output area is at the bottom of the tool. It displays progress messages
and diagnostics. In the above view, the toggle button is pushed in, so the
text display area appears. If you are working on a small screen, you might
use the toggle button to hide the text area, allowing more room to display
the controller design.
5-6
Working with the Design Tool
Tree View
The tree view appears in a frame on the design tool’s left-hand side (see
example below). When you select one of the tree’s nodes (by clicking its name
or icon) the larger frame to its right shows a dialog pane that allows you to
view and edit the specifications associated with that item.
Node Types
The above example shows two Model Predictive Control Toolbox design project
nodes, Distillation Control and CSTR Control, and their subnodes. For
more details on each node type, see the following:
Renaming a Node
You can rename following node types:
5-7
5 Reference for the Design Tool GUI
• Scenario specifications
• Click the name, wait for an edit box to appear, type the desired name, and
press the Enter key to finalize your choice.
• Right-click the name, select the Rename menu option, and enter the
desired name in the dialog box.
• To rename a controller, select Controllers and edit the controller name
in the table.
• To rename a scenario, select Scenarios and edit the scenario name in
the table.
The Plant Model Importer dialog box opens (see the dialog box in “Import
from” on page 5-14 for an example). Within the dialog box you can import an
LTI model from the workspace or, when you have Simulink Control Design
software, you can import a linearized plant model from the Simulink model.
5-8
Working with the Design Tool
Note Once you have imported a model, any additional models you import to
the same MPC project or task must have the identical structure, i.e., the same
number of input and output signals, each appearing in the same sequence
and having the same signal type designations. If you attempt to import a
model that violates one of these conditions, the design tool issues a warning
message. If you persist, all previously loaded models will be deleted and the
controller design will be re-initialized using the latest model.
Import from
Use these options to set the location from which the model will be imported.
5-9
5 Reference for the Design Tool GUI
MATLAB workspace.
This is the default option and is the case shown in the above example. The
Items in your workspace area in the upper-right corner lists all candidate
models in your MATLAB workspace. Select one by clicking it. The Properties
area lists the selected model’s properties (the DC model in the above example).
MAT-file. The upper part of the dialog box changes as shown below.
5-10
Working with the Design Tool
The MAT-file name edit box becomes active. Type the desired MAT-file
name (if it’s not on the MATLABpath, enter the complete file path). You can
also use the Browse button which opens a file chooser window.
In the above example, file DCmodels.mat contains two models. Their names
appear in the Items in your MAT-file area in the upper-right corner. As
with the workspace option, the selected model’s properties appear in the
Properties area.
Import to
The combo box at the bottom of the dialog box allows you to specify the MPC
project/task into which the plant model will be imported (see example below).
It defaults to the active project.
Buttons
Import. Select the model you want to import from the Items list in the
upper-right corner of the dialog box. Verify that the Import to option
designates the correct project/task. Click the Import button to import the
model.
To verify that the model has been loaded, select Plant models in the tree.
(See “Tree View” on page 5-7, and “Plant Models View” on page 5-23.)
The import dialog box remains visible until you close it so you can import
additional models.
Close. Click Close to close the dialog box. You can also click the Close icon
on the title bar.
5-11
5 Reference for the Design Tool GUI
2 Open the Plant Model Importer dialog box (see “Importing a Plant
Model” on page 5-8).
3 Click the Linearized Plant from Simulink tab (see the following
example).
Note If you haven’t activated the design tool within Simulink, the
Linearized Plant from Simulink tab is unavailable.
Linearization Process. If you click OK, the design tool uses Simulink
Control Design software to create a linearized plant model. It performs the
following tasks automatically:
3 When the Create a new operating condition from MPC I/O values
option is selected, the Model Predictive Control Toolbox software
5-12
Working with the Design Tool
The linearized plant model appears as a new node under Plant Models.
For details of the linearization process, refer to the Simulink Control Design
documentation.
• To specify a name for the linearized plant model, enter the name in the
Linearization model name edit box.
• To use an alternative operating condition, you can:
- Select one from the menu next to Use the previously computed
operating condition. This list contains all operating conditions that
exist within the current project.
- Select Create a new operating condition from MPC I/O values to
compute an operating condition by optimization, using the nominal plant
values as constraints. See “Linearize Simulink Models” for an example
involving a nonlinear chemical reactor.
• To replace the nominal plant values with the operating point used in the
linearization, select the check box next to Replace the MPC nominal I/O
values with those derived from the operating condition.
• When there are multiple MPC blocks in the Simulink diagram, use the
Import to menu to select the one that will receive the plant model.
5-13
5 Reference for the Design Tool GUI
Importing a Controller
To import a controller, do one of the following:
The MPC Controller Importer dialog box opens. The following sections
describe its options:
Import from
Use these options to set the location from which the controller will be
imported.
5-14
Working with the Design Tool
MATLAB Workspace.
This is the default option and is the case shown in the above example. The
Items in your workspace area in the upper-right corner lists all MPC
objects in your workspace. Select one by clicking it. The Properties area lists
the properties of the selected model.
MAT-File. The upper part of the dialog box changes as shown below.
The MAT-file name edit box becomes active. Type the desired MAT-file name
here (if it’s not on the MATLAB path, enter the complete file path). You can
also use the Browse button which opens a standard file chooser dialog box.
5-15
5 Reference for the Design Tool GUI
In the above example, file Controllers.mat contains two MPC objects. Their
names appear in the Items in your MAT-file area in the upper-right corner.
Import to
This allows you to specify the MPC task into which the controller will be
imported (see example below). It defaults to that most recently active.
Buttons
Import. Select the controller you want to import from the Items list in the
upper-right corner. Verify that the Import to option designates the correct
project/task. Click the Import button to import the controller.
The imported controller contains a plant model, which appears in the Plant
models list. (See “Plant Models View” on page 5-23.)
Close. Click Close to close the dialog box. You can also click the Close icon
on the title bar.
Exporting a Controller
To export a controller, do one of the following:
5-16
Working with the Design Tool
• In the tree, right-click the controller you want to export and select the
Export Controller menu option.
The MPC Controller Exporter dialog box opens (see example below). The
following sections describe its options:
Name to assign. Use this to assign a valid MATLAB variable name (no
spaces). It defaults to the selected controller’s name (with spaces removed,
if any).
Export to MATLAB workspace. Select this option if you want the controller
to be exported to the MATLAB workspace.
5-17
5 Reference for the Design Tool GUI
Buttons
In either case, the dialog box remains visible, allowing you to export additional
controllers.
Close. Click Close to close the dialog box. You can also click the Close icon
on the title bar.
5-18
Working with the Design Tool
5-19
5 Reference for the Design Tool GUI
Buttons
Import Plant. Clicking this opens the Plant Model Importer dialog box (see
“Importing a Plant Model” on page 5-8).
Import Controller. Clicking this opens the MPC Controller Importer dialog
box (see “Importing a Controller” on page 5-14).
Note You won’t be allowed to proceed with your design until you import a
plant model. You can do so indirectly by importing a controller or loading
a saved project.
Input Signal Properties. The plant’s input signals appear as table rows
(see example below).
5-20
Working with the Design Tool
Note Your design must include at least one manipulated variable. The
other input signal types need not be included.
Output Signal Properties. The plant’s output signals appear as table rows
(see example below).
5-21
5 Reference for the Design Tool GUI
Note Your design must include at least one measured output. Inclusion
of unmeasured outputs is optional.
• Import Plant Model – Opens the Plant Model Importer dialog box (see
“Importing a Plant Model” on page 5-8).
• Import Controller – Opens the MPC Controller Importer dialog box (see
“Importing a Controller” on page 5-14).
• Clear Project – Erases all plant models, controllers, and scenarios in your
design, returning the project to its initial empty state.
• Delete Project – Deletes the selected project node.
5-22
Working with the Design Tool
5-23
5 Reference for the Design Tool GUI
The Name field is editable. Each model must have a unique name. The name
you assign here will be used within the design tool only.
The Type field is noneditable and indicates the model’s LTI object type (see
the Control System Toolbox documentation for a detailed discussion of LTI
models).
The Sampling Period field is zero for continuous-time models, and a positive
real value for discrete-time models.
The Imported on field gives the date and time the model was imported.
Model Details
This scrollable viewport shows details of the model currently selected in the
plant models list (see “Plant Models List” on page 5-24). An example appears
below.
5-24
Working with the Design Tool
Additional Notes
You can use this editable text area to enter comments, distinguishing model
features, etc.
Buttons
Import. Opens the Plant Model Importer dialog box (see “Importing a Plant
Model” on page 5-8).
Delete. Deletes the selected model. If the model is being used elsewhere
(i.e., in a controller or scenario), the first model in the list replaces it and a
warning message appears.
Right-Click Options
Right-clicking the Plant models node causes the following menu option to
appear.
Import Model. Opens the Plant Model Importer dialog box (see “Importing a
Plant Model” on page 5-8).
Controllers View
Selecting Controllers in the tree displays this view (see example below).
5-25
5 Reference for the Design Tool GUI
Controllers List
This table lists all the controllers in your project. The example below lists two
controllers, MPC1 and MPC2 .
5-26
Working with the Design Tool
The Name field is editable. The name you assign here must be unique. You
will refer to it elsewhere in the design tool, e.g., when you use the controller
in a simulation scenario. Each listed controller corresponds to a subnode of
Controllers (see “Tree View” on page 5-7). Editing the name in the table will
rename the corresponding subnode.
The Plant Model field is editable. To change the selection, click the cell and
choose one of your models from the list. (All models appearing in the Plant
Models view are valid choices. See “Plant Models View” on page 5-23.)
The Control Interval field is editable and must be a positive real number.
You can also set it in the Controller Specifications view (see “Model and
Horizons Tab” on page 5-33 for more details).
The noneditable Last Update field gives the date and time the controller
was most recently modified.
Controller Details
This scrollable viewport shows details of the controller currently selected in
the controllers list (see “Controllers List” on page 5-26). An example appears
below.
5-27
5 Reference for the Design Tool GUI
Note This view shows controller details once you have used the controller in
a simulation. Prior to that, it is empty. If necessary, you can use the Display
button to force the details to appear.
Additional Notes
You can use this editable text area to enter comments, distinguishing
controller features, etc.
Buttons
Import. Opens the MPC Controller Importer dialog box (see “Importing
a Controller” on page 5-14).
Export. Opens the MPC Controller Exporter dialog box (see “Exporting
a Controller” on page 5-16).
5-28
Working with the Design Tool
Right-Click Options
Right-clicking the Controllers node causes the following menu options to
appear.
Import Controller. Opens the MPC Controller Importer dialog box (see
“Importing a Controller” on page 5-14).
Export Controller. Opens the MPC Controller Exporter dialog box (see
“Exporting a Controller” on page 5-16).
5-29
5 Reference for the Design Tool GUI
Scenarios List
This table lists all the scenarios in your project. The example below lists two,
Scenario1 and Scenario2 .
5-30
Working with the Design Tool
The Name field is editable. The assigned name must be unique. Each listed
scenario corresponds to a subnode of Scenarios (see “Tree View” on page 5-7).
Editing the name in the table will rename the corresponding subnode.
The Controller field is editable. To change the selection, click the cell and
select one of your controllers from the list. (All controllers appearing in the
Controllers view are valid choices. See “Controllers View” on page 5-25.) You
can also set this using the Scenario Specifications view (for more discussion,
see “Simulation Scenario View” on page 5-54).
The Plant field is editable. To change the selection, click the cell and select
one of your plant models from the list. (All models appearing in the Plant
Models view are valid choices. See “Plant Models View” on page 5-23.) You
can also set this in the scenario specifications (for more discussion, see
“Simulation Scenario View” on page 5-54).
The Closed Loop field is an editable check box. If cleared, the simulation
will be open loop. You can also set it in the scenario specifications (for more
discussion see “Simulation Scenario View” on page 5-54).
The Duration field is editable and must be a positive, finite real number. It
sets the simulation duration. You can also set it in the scenario specifications
(for more discussion, see “Simulation Scenario View” on page 5-54).
5-31
5 Reference for the Design Tool GUI
Scenario Details
This area is blank at all times.
Additional Notes
You can use this editable text area to enter comments, distinguishing scenario
features, etc.
Buttons
Right-Click Options
Right-clicking the Scenarios node causes the following menu option to appear
5-32
Working with the Design Tool
Plant Model.
This combo box allows you to specify the plant model the controller uses for
its predictions. You can choose any of the plant models you’ve imported. (See
“Importing a Plant Model” on page 5-8.)
5-33
5 Reference for the Design Tool GUI
Horizons.
The Control interval option sets the elapsed time between successive
controller moves. It must be a positive, finite real number. The calculations
assume a zero-order hold on the manipulated variables (the signals adjusted
by the controller). Thus, these signals are constant between moves.
The Prediction horizon option sets the number of control intervals over
which the controller predicts its outputs when computing controller moves.
It must be a positive, finite integer.
The Control horizon option sets the number of moves computed. It must be
a positive, finite integer, and must not exceed the prediction horizon. If less
than the prediction horizon, the final computed move fills the remainder of
the prediction horizon.
For more discussion, see “Typical Sampling Instant” on page 1-14, and
“Prediction and Control Horizons” on page 1-18.
Blocking.
5-34
Working with the Design Tool
The sum of the vector elements should equal the prediction horizon (15 in
this case). If not, the last move is extended or truncated automatically.
Note When Blocking is off, the controller uses the Beginning allocation
with Number of moves computed per step equal to the Control
horizon.
5-35
5 Reference for the Design Tool GUI
Constraints Tab
This tab allows you to specify constraints (bounds) on manipulated variables
and outputs. Constraints can be hard or soft. By default, all variables are
unconstrained, as shown in the view below.
5-36
Working with the Design Tool
The Name and Units columns are noneditable. To change them, use the
signal definition view. (See “Signal Definition View” on page 5-18. Any
changes there apply to the entire design.)
The remaining entries are editable. If you leave a cell blank, the controller
ignores that constraint. You can achieve the same effect by entering -Inf or
Inf (for a minimum or maximum, respectively).
The Max down rate and Max up rate values set the amount the MV can
change in a single control interval. The Max down rate must be negative or
zero. The Max up rate must be positive or zero.
Constraint values must be consistent with your nominal values (see “Input
Signal Properties” on page 5-20). In other words, each MV’s nominal value
must satisfy the constraints.
5-37
5 Reference for the Design Tool GUI
The Name and Units columns are noneditable. To change them, use the
signal definition view. (See “Signal Definition View” on page 5-18. Any
changes there apply to the entire design.)
The remaining entries are editable. If you leave a cell blank (as above), the
controller ignores that constraint. You can achieve the same effect by entering
-Inf (for a Minimum) or Inf (for a Maximum).
Constraint values must be consistent with your nominal values (see “Output
Signal Properties” on page 5-21). In other words, each output’s nominal value
must satisfy the constraints.
Constraint Softening
A hard constraint cannot be violated. Hard constraints are risky, especially
for outputs, because the controller will ignore its other objectives in order to
satisfy them. Also, the constraints might be impossible to satisfy in certain
situations, in which case the calculations are mathematically infeasible.
5-38
Working with the Design Tool
To open this dialog box, click the Constraint softening button at the bottom
of the Constraints tab in the Controller Specification view (see “Constraints
Tab” on page 5-36).
5-39
5 Reference for the Design Tool GUI
The Name and Units columns are noneditable. To change them, use the
signal definition view. (See “Signal Definition View” on page 5-18. Any
changes there apply to the entire design.)
The Minimum, Maximum, Max down rate, and Max up rate columns
are editable. Their values are the same as on the main Constraints tab
(see “Constraints on Manipulated Variables” on page 5-37). You can specify
them in either location.
The remaining columns specify the relaxation band for each constraint. An
empty cell is equivalent to a zero, i.e., a hard constraint.
The example above shows a relaxation band of 2 moles/min for the steam flow
rate’s lower and upper bounds. The lack of a relaxation band setting for the
reflux flow rate’s constraints means that these will be hard.
Note The relaxation band is a relative tolerance, not a strict bound. In other
words, the actual constraint violation can exceed the relaxation band.
5-40
Working with the Design Tool
The Name and Units columns are noneditable. To change them, use the
signal definition view. (See “Signal Definition View” on page 5-18. Any
changes there apply to the entire design.)
The Minimum and Maximum columns are editable. Their values are the
same as on the main Constraints tab (see “Constraints on Output Variables”
on page 5-37). You can specify them in either location.
The remaining columns specify the relaxation band for each constraint. An
empty cell is equivalent to 1.0, i.e., a soft constraint.
The example above shows a relaxation band of 0.5 mole % for the distillate
purity lower bound, and a relaxation band of 2 mole % for the bottoms purity
lower bound (the softer of the two constraints).
Note The relaxation band is a relative tolerance, not a strict bound. In other
words, the actual constraint violation can exceed the relaxation band.
You can move the slider or edit the value in the edit box, which must be
between 0 and 1.
5-41
5 Reference for the Design Tool GUI
The following sections discuss the three tab areas in more detail. For
additional information, see “Optimization Problem” on page 2-5.
Each table entry may be a scalar or a vector. A scalar entry defines a weight
that is constant for the entire prediction horizon. A vector entry defines a
time-varying weight. See “Entering Vectors in Table Cells” on page 5-44 for
the required format.
5-42
Working with the Design Tool
Input Weights.
Note To set the nominal values, use the signal definition view. (See “Signal
Definition View” on page 5-18. Any changes there apply to the entire design.)
The Rate Weight value sets a penalty on MV changes, i.e., on the magnitude
of each MV move. Increasing the penalty on a particular MV causes the
controller to change it more slowly. The table entries must be zero or positive
real numbers. These values have no effect in steady state.
Output Weights.
5-43
5 Reference for the Design Tool GUI
If you don’t need to hold a particular output at a setpoint, set its Weight to
zero. This may be the case, for example, when an output doesn’t have a target
value and is being used as an indicator variable only.
The slider adjusts the weights on all variables simultaneously. Moving the
slider to the left increases rate penalties relative to setpoint penalties, which
often (but not always!) increases controller robustness. The disadvantage is
that disturbance rejection and setpoint tracking become more sluggish.
You can also change the value in the edit box. It must be a real number
between 0 and 1. The actual effect is nonlinear. You will generally need to
run trials to determine the best setting.
You can also define a constraint or weight that varies with time by entering a
vector. For the rationale and theoretical basis, see “View and Alter Controller
Properties” and “Optimization Problem” on page 2-5.
5-44
Working with the Design Tool
Enter vectors using the standard MATLAB syntax. For example, [1, 2, 3]
defines a vector containing three elements, the values 1, 2, and 3.
Estimation Tab
Use these specifications to shape the controller’s response to unmeasured
disturbances and measurement noise.
The example below shows Model Predictive Control Toolbox default settings
for an application with two output variables and no unmeasured disturbance
inputs.
5-45
5 Reference for the Design Tool GUI
The following sections cover each estimation feature in detail. For additional
information, see “Estimating States from Measured Data” on page 1-9 for an
introduction, and “State Estimation” on page 2-17 for detailed information.
Button (MPC Default Settings). If you edit any of the Estimation tab
settings, the display near the top will appear as follows.
To return the settings to the default state, click the Use MPC Defaults
button, causing the display to revert to the default condition shown below.
5-46
Working with the Design Tool
You can also change the value in the edit box. It must be between zero and
1. The effect is nonlinear, and you might need to run trial simulations to
achieve the desired result.
Output Disturbances
The example below shows the tab’s appearance with the Signal-by-signal
option selected for an application having two plant outputs.
5-47
5 Reference for the Design Tool GUI
Use the table to specify the disturbance character for each output.
The Name and Units columns are noneditable. To change them, use the
signal definition view. (See “Signal Definition View” on page 5-18. Any
changes there apply to the entire design.)
The Type column sets the disturbance character. To edit this, click the cell
and select from the resulting menu. You have the following options:
The Magnitude column specifies the standard deviation of the white noise
assumed to create the disturbance. Set it to zero if you want to turn off a
particular disturbance.
5-48
Working with the Design Tool
If these options are too restrictive, select the LTI model in workspace
option. The tab appearance changes to the view shown below.
The model must have the same number of outputs as the plant.
The white noise entering the model is assumed to have unity standard
deviation.
5-49
5 Reference for the Design Tool GUI
Note This option is available only if your plant model includes unmeasured
disturbance inputs.
The example below shows the tab’s appearance with the Signal-by-signal
option selected for a plant having one unmeasured disturbance input. The
graphic shows the disturbance location.
Use the table to specify the character of each unmeasured disturbance input.
The Name and Units columns are noneditable. To change them, use the
signal definition view. (See “Signal Definition View” on page 5-18. Any
changes there apply to the entire design.)
The Type column sets the disturbance character. To edit this, click the cell
and select from the resulting menu. You have the following options:
5-50
Working with the Design Tool
The Magnitude column specifies the standard deviation of the white noise
assumed to create the disturbance. Set it to zero if you want to turn off a
particular disturbance.
If the above options are too restrictive, select the LTI model in workspace
option. The tab appearance changes to the view shown below.
You must specify an LTI disturbance model residing in your workspace. The
Browse button opens a dialog box listing all LTI models in your workspace,
and allows you to choose one. You can also type the model name in the edit
box, as shown above.
5-51
5 Reference for the Design Tool GUI
The number of model outputs must equal the number of plant unmeasured
disturbance inputs. The white noise entering the model is assumed to have
unity standard deviation.
Noise. Use these settings to model noise in the plant’s measured outputs.
The example below shows the tab’s appearance with the Signal-by-signal
option selected for a plant having two measured outputs. The graphic shows
the noise location.
The Name and Units columns are noneditable. To change them, use the
signal definition view. (See “Signal Definition View” on page 5-18. Any
changes there apply to the entire design.)
The Type column sets the noise character. To edit this, click the cell and
select from the resulting menu. You have the following options:
5-52
Working with the Design Tool
The Magnitude column specifies the standard deviation of the white noise
assumed to create the noise. Set it to zero if you want to specify that an
output is noise-free.
If the above options are too restrictive, select the LTI model in workspace
option. The tab appearance changes as follows.
You must specify an LTI model residing in your workspace. The Browse
button opens a dialog box listing all LTI models in your workspace, and
allows you to choose one. You can also type the model name in the edit box,
as shown above.
The number of noise model outputs must equal the number of plant measured
outputs.
The white noise entering the model is assumed to have unity standard
deviation.
5-53
5 Reference for the Design Tool GUI
Right-Click Menus
Copy Controller. Creates a new controller having the same settings and
a default name.
Export Controller. Opens the MPC Controller Exporter dialog box (see
“Exporting a Controller” on page 5-16).
5-54
Working with the Design Tool
The middle table won’t appear unless you have designated at least one input
signal to be a measured disturbance.
5-55
5 Reference for the Design Tool GUI
Simulation Settings
The Control interval field is display-only, and reflects the setting in your
Controller selection. You can change it there if necessary (see “Model and
Horizons Tab” on page 5-33).
Setpoints
Use this table to specify the setpoint for each output. In the example below,
which is for an application having two plant outputs, the first would be
constant at 0.0, and the second would change step-wise.
5-56
Working with the Design Tool
The Name and Units columns are display-only. To change them, use the
signal definition view. (See “Signal Definition View” on page 5-18. Any
changes apply to the entire design.)
The Type column specifies the setpoint variation. To change this, click the
cell and select a choice from the resulting menu.
The significance of the Initial Value, Size, Time, and Period columns
depends on the Type. If a cell is gray (noneditable), it doesn’t apply to the
Type you’ve chosen.
For details on the signal types, see “Signal Type Settings” on page 5-60.
If the Look Ahead option is selected (i.e., on), the controller will use future
values of the setpoints in its calculations. This improves setpoint tracking,
but knowledge of future setpoint changes is unusual in practice.
Measured Disturbances
Use this table to specify the variation of each measured disturbance. In
the example below, which is for an application having a single measured
disturbance, the “Steam Rate” input would be constant at 0.0.
5-57
5 Reference for the Design Tool GUI
The Name and Units columns are display-only. To change them, use the
signal definition view. (See “Signal Definition View” on page 5-18. Any
changes apply to the entire design.)
The Type column specifies the disturbance variation. To change this, click
the cell and select a choice from the resulting menu.
The significance of the Initial Value, Size, Time, and Period columns
depends on the Type. If a cell is gray (noneditable), it doesn’t apply to the
Type you’ve chosen.
For details on the signal types, see “Signal Type Settings” on page 5-60.
If the Look Ahead option is selected (i.e., on), the controller will use future
values of the measured disturbance(s) in its calculations. This improves
disturbance rejection, but knowledge of future disturbances is unusual in
practice. It has no effect in an open-loop simulation.
Unmeasured Disturbances
Use this table to specify the variation of each measured unmeasured
disturbance. In the example below, all would be constant at 0.0.
5-58
Working with the Design Tool
All of the above will appear as rows in the table. In the case of a measured
output or manipulated variable, the disturbance is an additive bias.
The Name and Units columns are display-only. To change them, use the
signal definition view. (See “Signal Definition View” on page 5-18. Any
changes apply to the entire design.)
The Type column specifies the disturbance variation. To change this, click
the cell and select a choice from the resulting menu.
The significance of the Initial Value, Size, Time, and Period columns
depends on the Type. If a cell is gray (noneditable), it doesn’t apply to the
Type you’ve chosen.
For details on the signal types, see “Signal Type Settings” on page 5-60.
For example, suppose Reflux Rate is an MV, and the corresponding row in the
table below represents an unmeasured disturbance in this MV.
5-59
5 Reference for the Design Tool GUI
Constant. The signal will be held at the specified Initial Value for the
entire simulation.
y = y0 for t ≥ 0.
Step. Prior to Time, the signal = Initial Value. At Time, the signal changes
step-wise by Size units. Its value thereafter = Initial Value + Size.
Ramp. Prior to Time, the signal = Initial Value. At Time, the signal begins
to vary linearly with slope Size.
Sine. Prior to Time, the signal = Initial Value. At Time, the signal begins
to vary sinusoidally with amplitude Size and period Period.
5-60
Working with the Design Tool
Pulse. Prior to Time, the signal = Initial Value. At Time, a square pulse
of duration Period and magnitude Size occurs.
y = y0 for t ≥ t0 + T
Gaussian. Prior to Time, the signal = Initial Value. At Time, the signal
begins to vary randomly about Initial Value with standard deviation Size.
Simulation Button
Click the Simulate button to simulate the scenario. You can also press
Ctrl+R, use the toolbar icon (see “Toolbar” on page 5-6), or use the
MPC/Simulate menu option (see “Menu Bar” on page 5-4).
Right-Click Menus
Copy Scenario. Creates a new simulation scenario having the same settings
and a default name.
5-61
5 Reference for the Design Tool GUI
Rename Scenario. Opens a dialog box allowing you to rename the scenario.
5-62
Analyze Sensitivity Using the Tuning Advisor
When you design MPC controllers, you can use the Tuning Advisor to help
you determine which weight has the most influence on the closed-loop
performance. The Tuning Advisor also helps you determine in which direction
to change the weight to improve performance. Using the Advisor, you can
know numerically how each weight impacts the closed-loop performance,
which makes designing MPC controllers easier when the closed-loop responses
does not depend intuitively on the weights.
5-63
5 Reference for the Design Tool GUI
The Tuning Advisor populates the Current Tuning column with the most
recent tuning weights of the controller displayed in the Controller in
Design. In this case, Obj is the controller. The Advisor also initializes the
Performance Weight column to the same values. The Scenario in Design
displays the scenario from which you started the Tuning Advisor. The Advisor
uses this scenario to evaluate the controller’s performance.
The columns highlighted in grey are Tuning Advisor displays and are
read-only. For example, signal names come from the “Signal Definition View”
on page 5-18 and are blank unless you defined them there.
5-64
Analyze Sensitivity Using the Tuning Advisor
• ISE (Integral of Squared Error, the default). This is the standard linear
quadratic weighting of setpoint tracking errors, manipulated variable
movements, and deviations of manipulated variables from targets (if any).
The formula is
Tstop ⎛ ny nu ⎞
J= ∑ ⎜⎜ ∑ (w yj eyij )2 + ∑ [(wuj euij )2 + (wΔj u Δuij )2 ]⎟⎟
i =1 ⎝ j =1 j =1 ⎠
Tstop ⎛ ny nu ⎞
J= ∑ ⎜⎜ ∑|w yj eyij | + ∑ (|wuj euij | + |wΔj u Δuij |) ⎟⎟
i =1 ⎝ j =1 j =1 ⎠
5-65
5 Reference for the Design Tool GUI
Tstop ⎛ ny nu ⎞
J= ∑ iΔt ⎜ ∑ (w yj e yij )2 +
⎜ j =1 ∑ [(wuj euij )2 + (wΔj u Δuij )2 ]⎟⎟
i =1 ⎝ j =1 ⎠
which penalizes deviations at long times more heavily than the ISE, i.e., it
favors controllers that rapidly eliminate steady-state offset.
• ITAE (time-weighted Integral of Absolute Errors)
Tstop ⎛ ny nu ⎞
J= ∑ iΔt ⎜ ∑ | w yj e yij | + ∑ (| wuj euij | + | wΔj u Δuij |) ⎟
⎜ j =1 ⎟
i =1 ⎝ j =1 ⎠
which is like the ITSE but with less emphasis on large deviations.
Each of the above formulae use the same three performance weights, w yj , wuj ,
and wΔj u . All must be non-negative real numbers. Use the weights to:
variable rarely has a target value, in which case you should set its wuj to
zero. Similarly if a plant output is monitored but doesn’t have a setpoint,
5-66
Analyze Sensitivity Using the Tuning Advisor
Baseline Performance
After you define the performance metric and specify the performance weights,
compute a baseline J for the scenario by clicking Baseline. The next figure
shows how this transforms the above example (the two wΔj u performance
weights have also been set to zero because manipulated variable changes are
acceptable if needed to achieve good setpoint tracking for the two (equally
weighted) outputs. The computed J = 3.435 is displayed in Baseline
Performance, to the right of the Baseline button.
The Tuning Advisor also displays response plots for the scenario with the
baseline controller (not shown but discussed in “Customize Response Plots”
on page 5-71).
5-67
5 Reference for the Design Tool GUI
You must also consider the tuning weight’s current magnitude. For example,
if the current value were 0.01, a 1-unit increase would be extreme and a
1-unit decrease impossible, whereas if it were 1000, a 1-unit change would
be insignificant.
It’s best to focus on a small subset of the tuning weights for which the
sensitivities suggest good possibilities for improvement.
5-68
Analyze Sensitivity Using the Tuning Advisor
In the above example, the wΔj u are poor candidates. The maximum possible
change in the suggested direction (decrease) is 0.1, and the sensitivities
indicate that this would have a negligible impact on J. The wuj are already
zero and can’t be decreased.
The w yj are the only tuning weights worth considering. Again, it seems
unlikely that a change will help much. The display below shows the effect of
doubling the tuning weight on the bottoms purity (second) output. Note the 2
in the last column of this row. After you click Analyze, the response plots
(not shown) make it clear that this output tracks its setpoint more accurately
but at the expense of the other, and the overall J actually increases.
Notice also that the sensitivities have been recomputed with respect to the
revised controller tuning weights. Again, there are no obvious opportunities
for improved performance.
Thus, we have quickly determined that the default controller tuning weights
are near-optimal in this case, and further tuning is not worth the effort.
5-69
5 Reference for the Design Tool GUI
5-70
Customize Response Plots
By default, each plant signal plots in its own graph area (as shown above). If
the simulation is closed loop, each output signal plot include the corresponding
setpoint.
5-71
5 Reference for the Design Tool GUI
Data Markers
You can use data markers to label a curve or to display numerical details.
5-72
Customize Response Plots
To delete a single data marker, right-click it and select the Delete option.
Right-Click Options
Right-click a data marker to use one of the following options:
5-73
5 Reference for the Design Tool GUI
Revising a Scenario
If you modify and recalculate a scenario, its data are replotted, replacing the
original curves.
Therefore, you can control the variables being plotted. To do so, right-click in
a plot’s white space and select Channel Selector from the resulting menu. A
dialog box appears, on which you can opt to show or hide each variable.
5-74
Customize Response Plots
To return to the default mode, use the Channel Grouping: None option.
For example, the plot below shows two plant outputs together (Channel
Grouping: All option). The outputs have very different magnitudes. When
plotted together, it’s hard to see much detail in the smaller response.
The plot below shows the normalized version, which displays each curve’s
variations clearly.
5-75
5 Reference for the Design Tool GUI
Marker” on page 5-72). Note that the two data markers on the plot below
are at the same normalized y-axis location, but correspond to very different
amplitudes in the original (unnormalized) coordinates.
5-76