Mathworks MODEL PREDICTIVE CONTROL TOOLBOX 3 user guide

Model Predictive C
User’s Guide
Alberto Bemporad Manfred Morari N. Lawrence Ricker
ontrol Toolbox™ 3
How to Contact The MathWorks
www.mathworks. comp.soft-sys.matlab Newsgroup www.mathworks.com/contact_TS.html T echnical Support
suggest@mathworks.com Product enhancement suggestions
bugs@mathwo doc@mathworks.com Documentation error reports service@mathworks.com Order status, license renewals, passcodes
info@mathwo
rks.com
rks.com
Web
Bug reports
Sales, prici
ng, and general information
508-647-7000 (Phone)
508-647-7001 (Fax)
The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site.
Model Predictive Control Toolbox™ User’s Guide
© COPYRIGHT 2005–2010 by The MathWorks, Inc.
The software desc ribed in this document is furnished under a license agreeme nt. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Docum entation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern theuse,modification,reproduction,release,performance,display,anddisclosureoftheProgramand Documentation by the federal government (or other entity acquiring for or through the federal governme nt) and shall supersede any conflicti ng contractual terms or conditions. If this License fails to meet the government’s needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused , to The MathWorks, Inc.
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
The 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)
Introduction
1
Model Predictive Control of a SISO Plant ............ 1-2
Typical Sampling Instant Prediction and Control Horizons
........................... 1-5
..................... 1-8
Contents
MIMO Plants
Optimization and Constraints Estimating States from Measured Data Blocking
...................................... 1-10
....................... 1-10
............... 1-14
......................................... 1-14
Model Predictive Control Problem Setup
2
Prediction Model .................................. 2-2
Offsets
Optimization Problem
Standard Form Alternative Cost Function Remarks on the Constraint Formulation
State Estimation
Measurement Noise Model Output Disturbance Model State Observer
.......................................... 2-4
............................. 2-5
................................... 2-5
.......................... 2-7
............... 2-8
................................... 2-9
.......................... 2-9
.......................... 2-10
.................................... 2-10
QP Matrices
Prediction Optimization Variables Cost Function Constraints
....................................... 2-13
........................................ 2-13
.................................... 2-16
...................................... 2-18
............................. 2-14
v
Model Predictive Control Computation .............. 2-20
Unconstrained MPC Constrained Model Predictive Control
............................... 2-20
................. 2-20
Using Identified Models
............................ 2-21
Model Predictive Control Simulink Library
3
MPC Library ...................................... 3-2
MPC Controller Block
MPC Controller Block Mask Input Signals Look Ahead and Signals from the Workspace Initialization Using Model Predictive Control Toolbox Software with
Real-Time Workshop Software
Multiple MPC Controllers
..................................... 3-4
..................................... 3-6
.............................. 3-3
......................... 3-3
........... 3-5
..................... 3-6
.......................... 3-8
vi Contents
Case-Study Examples
4
Introduction ...................................... 4-2
Servomechanism Controller
System Model Control Objectives and Constraints Defining the Plant Model Controller Design Using MPCTOOL Using Model Predictive Control Toolbox Commands Using MPC Tools in Simulink
.................................... 4-3
........................ 4-3
................... 4-5
........................... 4-5
.................. 4-6
....................... 4-23
..... 4-20
Paper Machine Process Control ..................... 4-27
Linearizing the Nonlinear Model MPC Design Controlling the Nonlinear Plant in Simulink
...................................... 4-29
..................... 4-28
........... 4-36
Bumpless Transfer in MPC
Nonlinear Control Using Multiple Models
Using the Tuning Advisor
Bibliography
...................................... 4-59
......................... 4-39
............ 4-46
.......................... 4-54
Reference for the Design Tool GUI
5
Opening the MPC Design Tool ...................... 5-2
Menu Bar
File Menu MPC Menu
Toolbar
......................................... 5-4
........................................ 5-4
....................................... 5-5
........................................... 5-7
Tree View
Node Types Renaming a Node
Importing a Plant Model
Import from Import to Buttons Importing a Linearized Plant Model
Importing a Controller
Import from
......................................... 5-8
...................................... 5-8
................................. 5-8
........................... 5-10
...................................... 5-11
........................................ 5-12
......................................... 5-12
............................. 5-16
...................................... 5-16
.................. 5-13
vii
Import to ........................................ 5-18
Buttons
......................................... 5-18
Exporting a Controller
Dialog Box Options Buttons
Signal Definition View
MPC Structure Overview Buttons Signal Properties Tables Right-Click Menu Options
Plant Models View
Plant Models List Model Details Additional Notes Buttons Right-Click Options
Controllers View
Controllers List Controller Details Additional Notes Buttons Right-Click Options
......................................... 5-20
......................................... 5-22
......................................... 5-28
......................................... 5-31
................................ 5-19
................................. 5-26
................................. 5-27
..................................... 5-27
.................................. 5-28
................................ 5-28
.................................. 5-29
................................... 5-30
................................. 5-30
.................................. 5-31
................................ 5-32
............................. 5-19
............................. 5-21
........................... 5-22
............................ 5-22
.......................... 5-24
viii Contents
Simulation Scenarios List
Scenarios List Scenario Details Additional Notes Buttons Right-Click Options
Controller Specifications View
Model and Horizons Tab Constraints Tab Constraint Softening Weight Tuning Tab Entering Vectors in Table Cells Estimation Tab
.................................... 5-34
.................................. 5-35
.................................. 5-35
......................................... 5-35
................................ 5-35
................................... 5-40
................................ 5-46
................................... 5-49
.......................... 5-33
............................ 5-37
............................... 5-43
...................... 5-36
...................... 5-49
Right-Click Menus ................................ 5-58
Simulation Scenario View
Simulation Settings Setpoints Measured Disturbances Unmeasured Disturbances Signal Type Settings Simulation Button Tuning Advisor Button Right-Click Menus
Tuning Advisor
Defining the Performance M etric Baseline Performance Sensitivities and Tuning Advice Updating the Controller Restoring Baseline Tuning Modal Dialog Behavior Scenarios for Performance Measurement
Response Plots
Data Markers Displaying Multiple Sc enarios Viewing Selected Variables Grouping Variables in a Single Plot Normalizing Response A m plitudes
........................................ 5-61
................................. 5-66
................................ 5-66
.................................... 5-68
.................................... 5-76
.................................... 5-77
.......................... 5-59
............................... 5-60
............................ 5-62
.......................... 5-62
............................... 5-64
............................. 5-66
.............................. 5-71
...................... 5-72
............................ 5-75
.......................... 5-75
............................. 5-75
....................... 5-78
......................... 5-79
..................... 5-69
.............. 5-75
................... 5-80
................... 5-80
Index
ix
x Contents

Introduction

“Model Predictive Control of a SISO Plant” on pag e 1-2
“MIMO Plants” on page 1-10
1
1 Introduction

Model Predictive Control of a SISO Plant

The usual Mo del Predictive Control Toolbox™ application involves a plant having multiple inputs and multiple outputs (a MIMO plant).
Consider instead the simpler applicatio n shown in the following figure, Block Diagram of a SISO Model Predictive Control Toolbox™ Application on page 1-2. See the nomenclature summary in the table, Model Predictive Control Toolbox™ Signals on page 1-3. This plant could be a manufacturing process, such as a unit operation in an oil refinery, or a device, such as an electric motor. The main objective is to hold a single output, (or setpoint), r, by adjusting a single manipulated variable (or actuator) u. This is wh at is generally termed a SISO (single-input single-output) plant. The block labeled MPC represents a M odel Predictive Controller designed to achieve the control objective.
The SISO plant actually has multiple inputs, as shown in the following figure. In addition to the manipulated variable input, u, there may be a measured disturbance, v, and an unmeasured disturbance, d.
,atareference value
1-2
Block Diagram of a SISO Model Predictive Control Toolbox™ Application
The unmeasured disturbance is always present. As shown in the previous figure, it is an independent input–not affected by the controller or the plant. It represents all the unknown, unpredictable events that upset plant operation.
Model Predictive Control of a SISO Plant
(In the context of Model Predictive Control, it can also represent unmodeled dynamics.) When such an event occurs, the only indication is its effect on the measured output, y.Thisoutputisfed back to the controller as show n in the Block Diagram of a SISO M odel Predictive Control Toolbox™ Application on page 1-2 figure.

Model Predictive Control Toolbox Signals

Symbol Description
d
Unmeasured disturbance. Unknown but for its effect on the
plant output. The controller provides feedback compensation for such d isturbances.
r
u
Setpoint (or reference). The target value for the output.
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). Thesignaltobeheldat the setpoint. This is the “true” value, uncorrupted by measurement noise.
y
z
Measured output. Used to estimate the true value,
rement noise. Represents electrical noise, sampling
Measu
rs, drifting calibration, and other effects that impair
erro
urement precision and accuracy.
meas
.
Some applications have unmeasured disturbances only. A measured disturbance, v, is another independent input affecting
.Incontrasttod, the controller receives the measured v directly, as shown in the figure Block Diagram of a SISO Model Predictive Control Toolbox™ Application on page 1-2. This allows the controller to compensate for v’s impact on
immediately rather than waiting until the effect appears in the y measurement. This is called feedforward control.
1-3
1 Introduction
In other wo rds, Model Predictive Control Toolbox design always provides feedback compensation for unmeasured disturbances and feedforward compensation for any measured disturbance.
Model P redictive Control Toolbox design requires a model of the impact that v and u have on calculate the u adjustments needed to keep
This calculation considers the effect of any known constraints on the adjustments (typically an actuator upper or lower bound, or a constraint on how rapidly u can vary). One may also specify bounds on specifications are a distin guishing f eature of Model Predictive Control Toolbox design and can be particularly valuable when one has multiple control objectives to be achieved via multiple adjustments (a MIMO plant). In the context of a SISO system, such contraint handling is often termed an anti-windup feature.
If the plant model is accurate, the plant responds quickly to adjustments in u, and no constraints are encountere d, feedforwa r d compensation can counteract the impact of v perfectly. In reality, model imperfections, physical limitations, and unmeasured disturbances cause the y to deviate from its setpoint. Therefore, Model Predictive Contro l Toolbox design includes a disturbance model ( uses its calculation also considers the known constraints.
(symbolically, and ). It uses this plant model to
at its setpoint.
. These constraint
)toestimate dandpredict its impact on .Itthen
model to calculate appropriate adjustments (feedback). This
1-4
Various noise effects can corrupt the measurement. The signal z in the B lock Diagram of a SISO Model Predictive Control Toolbox™ Application on page 1-2 figure represents such effects. They could vary randomly with a zero mean, or could exhibit a non-zero, drifting bias. Model Predictive Control Toolbox design uses a remove the estimated noise com p on ent (filtering).
The above feedforward/feedback actions comprise the controller’s regulator mode. Model Predictive Control Too lbox design also provides a servo mode, i.e.,itadjustsu such that
The tracking accuracy depends on the plant characteristics (including constraints), the accuracy of the
model in combination with its model to
tracks a time-varying setpoint.
model, and whether or not future
Model Predictive Control of a SISO Plant
setpoint variations can be anticipated, i.e., known in advance. If so, it provides feedforward compensation for these.

Typical Sampling Instant

Model Predictive Control Toolbox design generates a discrete-tim e controller—one that takes action at regularly spaced, discrete time instants. The sampling instants are the times at which the controller acts. The interval separating successive sampling instants is the sampling period, Δt (also called the control interval). This section provides more details on the events occuring at each sampling instant.
1-5
1 Introduction
1-6
roller State at the kth Sampling Instant
Cont
figure, Controller State at the kth Sam pling Instant on page 1-6, shows
The
state of a hypothetical SISO model preditive control system. This system
the
been operating for many s ampling instants. Integer k represents the
has
rent instant. The latest measured output, y
cur
, y
y
k
, ..., are known and are the f il led circles in th e figure Controller
-1
k-2
, and previous measurements,
k
Model Predictive Control of a SISO Plant
State at the kth Sampling Instant on page 1-6 (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-6 (b) shows the controller’s previous moves, u
k-41
,...,u
,asfilledcircles. Asisusually
k-1
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-6 (b).
To calculate its next move, u
1 Estimation. In order to make an intelligent move, the controller needs
the controller operates in two phases:
k
to know the current state. This includes the true value of the controlled variable,
, and any internal variables that influence the future trend,
, ..., . To accomplish this, the controller uses all past and current
measurements and the models
, , ,and .For
details, see “Prediction” on page 2-13 and “State Estimation” on page 2-9.
2 Optimization. Values of setpoints, measured disturbances, and constraints
are specified over a finite horizon of future sampling instants, k+1 , k+2, ..., k+P,whereP (a finite integer 1) is the prediction horizon —see figure Controller State at the kth Sampling Instant on page 1-6 (a). The controller computes M moves u
, u
,... u
k
k+1
,whereM ( 1, P)isthecontrol
k+M-1
horizon—see figure Controller State at the kth Sampling Instant on page
1-6 (b). In the hypothetical example shown in the figure, P =9andM =4. The moves are the solution of a constrained optimization problem. For details of the formulation, see “Optimization Problem” on page 2-5.
In the example, the optimal moves are the four open circles in figure Controller State at the kth Sampling Instant on page 1-6 (b). The controller predicts that the resulting output values will be the nine open c ircles in figure Controller State at the kth Sampling Instant on page 1-6 (a). Notice that both
are within their constraints,
and .
When it’s finished calculating, the controller sends move u
to the plant. The
k
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. Thiscyclerepeatsindefinitely.
1-7
1 Introduction
Reformulation at each sampling instant is essential for good control. The predictions made during the optimization stage are imperfect. Periodic measurement feedback allows the controller to correct for this error and for unexpected disturbances.

Prediction and Control Horizons

You might wonder why the controller bothers to optimize over P future sampling periods and calculate M future moves when it discards all but the firstmoveineachcycle. Indeed,undercertain conditions a controller using P = M = 1 would be identical to one using P = M = . More often, however, the horizon values have an important impact. Some examples follow:
Constraints. Given sufficiently long horizons, the controller can “see” a
potential constraint and avoid it—or at least min i mize its adverse effects. For example, consider t h e situation depicted below in wh ich one controller objective is to keep plant output y below an upper bound y sampling instant is k, and the model predicts the upward trend y controller were looking P
steps ahead, it wouldn’t be concerned by the
1
constraint until more time had elapsed. If the prediction horizon were P it would begin to take corrective action immediately.
. The current
max
k+i
.Ifthe
2
,
1-8
Plan
tdelays. Suppose that the plant includes a pure time delay equivalent
to D s
fect until y
no ef P D,
example, suppose D =5,P =7,M = 3, the current time instant is k,
For
thethreemovestobecalculatedareu
and
ld have some impact within the prediction horizon, but move u
wou
ve none until y
ha
ampling instants. In other words, the controller’s current move,
. In this situation it is essential that P >> D and M <<
k+D+1
k
as this forces the controller to consider the full effect of each move.
, u
, which is outside. Thus, u
k+8
,andu
k
k+1
is indeterminant. Setting
k+2
. Moves uk, u
k+2
k+2
would
,has
k+1
Model Predictive Control of a SISO Plant
P =8(orM = 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, but a longer term response in the opp osite direction. The optimiza tio n should focus primarily on the longer-term behavior. Otherwise, the controller would mov e in the wro ng direction.
Most designers choose P and M such that controller performance is insensitive to small adjustments in these horizons. Here are typical rules of thumb for a lag-dominant, stable process:
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).
2 Choose prediction horizon P to be the number of sampling periods used
in step 1.
3 Use a relatively small control horizo n M, e.g., 3–5.
If performance is poor, you should examine other aspects of the optimization problem and/or check for inaccurate controller predictions.
1-9
1 Introduction

MIMO Plants

One advantage of Model Predictive Control Toolbox design (relative to classical multi-loop control) is that it generalizes directly to plants having multiple inputs and outputs. Moreover, the plant can be non-square,i.e., having an unequal number of actuators and outputs. Industrial applications involving hundreds of actuators and controller outputs have been reported.
The m ain 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., w h en it encounters constraints. Model Predictive Control Toolbox features support such prioritization.

Optimization and Constraints

As discussed in more detail in “Optimization Problem” on page 2-5, the Model Predictive Control Toolbox controller solves an optimization problem much like the LQG optimal control described in the Control System Toolbox™ product. The main difference is that theModel Predictive Control Toolbox optimization problem includes explicit constraints on u and y.
1-10
Setpoint Tracking
Consider first a case with no constraints. A primary control o bjective is to force the plant outputs to track their setpoints.
Specifically, the controller predicts how much each output w ill deviate from its setpoint within the prediction hori zon . It multipli es each de vi ati on by the output’s weight, and computes the weighted sum of squared deviations,
,asfollows:
ere k is the current sampling interval, k+i is a future sampling interval
wh
ithin the prediction horizon), P is the prediction hor izo n, n
(w
is the number
y
MIMO Plants
of plant outputs, is the weight for output j ,and is the predicted deviation at future instant k+i.
If
necessary. If deviations r
the controller does its best to track rj, sacrificing ritracking if
, on the other hand, the controller completely ignores
.
j–yj
Choosing the weights is a critical step. You w ill usually need to tune your controller, varying the weights to achieve the desired behavior.
As an example, consider the following figure, which depicts a type of chemical reactor (a CSTR). Feed enters continuously with reactant concentration C
.
Ai
A reaction takes place inside the vessel at temperature T. Product exits continuously, and contains residual reactant at concentration C
The reaction liberates heat. A coolant having temperature T
(<CAi).
A
flows through
c
coils immersed in the reactor to r e m ov e excess heat.
CSTR Schematic
From the Model Predictive Control Toolbox point for view, T and CAwould be plant outputs, and C
and Tcwould be inputs. More specifically, C
Ai
Ai
would be an independent disturbance input, and Tcwould be a manipulated variable (actuator).
Thereisonemanipulatedvariable(thecoolanttemperature),soit’simpossible to hold both T and C
at setpoints. Controlling T would usually be a high
A
priority. Thus, you might set the output weight for T much larger than that for C
.Infact,youmightsettheCAweight to zero, allowing CAto float within
A
an acceptable operating region (to be defined by constraints).
1-11
1 Introduction
Move Suppression
If the controller focuses exclusively on setpoint tracking, it might choose to make large manipulated-variable adjustments. These could be impossible to achieve. They could also accelerate equipment wear or lead to control system instability.
Thus, the Model Predictive Controlle r also monitors a weighted sum o f controller adjustments, calculated according to the following equation:
where M is the control horizon, nmvis the number of m an ipu l ate d variables,
is the predicted adjustment (i.e., move) in manipulated
variable j at future (or current) sampling interval
weight, w
to make smaller, more cautious will have the following effects:
The controller’s se tpoint tracking will degrade.
The controller w ill be less sensitive to prediction inaccuracies (i.e., more
robust).
hich must be zero or positive. Increasing
moves. In many cases (but not all) this
,and is a
forces the controller
Setpoints on Manipulated Variables
In most applications, the controller’s manipulated variables (MVs) should move freely (within a constrained region) to compensate for disturbances and stepointchanges. AnattempttoholdanMVatapointwithintheregion would degrade output setpoint tracking.
Ontheotherhand,someplantshavemore MVs than output setpoints. In such a plant, if all manipulated variables we re allowed to m ov e 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.
1-12
MIMO Plants
A common approach is to define setpoints for “extra” MV s. The se setpoints usually represent operating conditions that improve safety, economic return, etc. Mo de l Predictive Control Toolbox design includes an additional term to accommodate such cases, as follows:
where is the manipulated variable setpoint (nominal value) for the jthMV,
and
is the corresponding weig h t.
Constraints
Constraints may be either hard or soft. A hard constraint must not be violated. Unfortunately, under some conditions a constraint violation might be unavoidable (e.g., an unexpected, large disturbance), and a realistic controller must allow for this.
Model Predictive Control Toolbox software does so by softening each constraint, making a violation mathematically acceptable, though discouraged. The designer may specify the degree of softness in each case, making selected constraints less likely to be violated than others. See 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 th e 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.
1-13
1 Introduction

Estimating States from Measured Data

At the beginning of each sampling instant the controller estimates the current plant state. Accurate knowledge of the state improves prediction accuracy, which, in turn, improves controlle r performance.
If all plant states are measured, the state estimation problem is relative ly 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 a vailable measurements. It also estimate the values of any sustained, unmeasured disturbances.
Model Predictive Control Toolbox software provides a default state estimation strategy, which the designer may customize. For details, see “State Estimation” on page 2-9.

Blocking

In figure Controller State at the kth Sampling Instant on page 1-6 (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-14
The following figure shows an alternative block ed strategy—again with 4 planned moves—in which the first occurs at sampling instant k, the next at k+2, the next at k+4, and the final at k+6. A block isoneormoresuccessive sampling periods during which the manipulated variable is constant. The block durations are the number of sampling periods in each block. In figure Blocking Example with Four Moves on page 1-15 the block durations are 2, 2, 2, and 3. (Their sum must equal P.)
Blocking Example with Four Moves
MIMO Plants
As for the default (unblocked) mode, only the current move, uk,actuallygoes to the plant. Thus, as shown in the figure above, the controller has made a plantadjustmentateachsamplinginstant.
So why use blocking? When P >> M (as is g enerally 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-15
1 Introduction
1-16

Model Predictive Control Problem Setup

“Prediction Model” on page 2-2
“Optimization Problem” on page 2-5
“State Estimation” on page 2-9
“QP Matrices” on page 2-13
“Model Predictive Control Computation” on page 2-20
2
“Using Identified Models” on page 2-21
2 Model Predictive Control Problem Setup

Prediction Model

The linear model used in Model Predictive Control Toolbox software for prediction and optimization is depicted in the following figure.
Model Used for Optimization
The model consists of:
2-2
A model of the plant to be controlled, whose inputs are the manipulated
variables, the measured disturbances, and the unmeasured disturbances
A model generating the unmeasured disturbances
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-10 and
The model of the plant is a linear time-invariant system described by the equations
setindist).
Prediction Model
where x(k)isthenx-dimensional state vector of the plant, u(k)isthe n
-dimensional vector of manipulated variables (MV), i.e., the command
u
inputs, v(k)isthen is the n plant, y
-dimensional vector of unmeasured disturbances (UD ) entering the
d
(k) is the vector of measured outputs (MO), and yu(k)isthevector
m
of unmeasured outputs (UO). The overall n collects y
(k)andyu(k).
m
-dimensional vector of measured disturbances (MD), d(k)
v
-dimensional output vector y(k)
y
Model Predictive Control Toolbox software accepts both plant models specified as LTI objects, and models obtained from input/output data using System Identification Toolbox™ (IDMODEL obje cts), see “Using Identified Models” on page 2-21.
In the above equations d(k) collects both state disturbances (B disturbances (D
0).
d
0) and output
d
Note A valid plant model for Model Predictive Control Toolbox software cannot have direct feedthrough of manipulated variables u(k)ontheoutput vector y(k).
The unmeasured disturbance d(k) is modeled as the output of the linear time invariant system:
(2-1)
(2-2)
The system described by the above equations is driven by the random Gaussian noise n
(k), having zero mean and unit covariance matrix. For
d
instance, a step-like unmeasured disturbance is modeled as the output of an integrator. Input disturbance models as in the equations above can be manipulated by using the methods
getindist and setindist.
Note If continuous-time models are supplied, they are internally sampled with the controller’s sampling time.
2-3
2 Model Predictive Control Problem Setup

Offsets

In m a ny practica l applications, the matrices A, B, C, D of the model representing the process to control are obtained by linearizing a nonlinear dynamical system, such as
,
at some nominal value x=x
, u=u0, v=v0, d=d0. In these equations x´ denotes
0
eitherthetimederivative(continuous time model) or the successor x(k+1) (discrete time model). As an example, x
TRIM on a Simulink
and A, B, C, D by using
The matr matrice
The lin and H=h inter into B
Nonze obta pred outp
ices A, B, C, D of the model are readily obtained from the Jacobian
s appearing in the equations above.
earized dynamics are affected by the constant terms F=f(x
(x
, u0, v0, d0). For this reason the model predictive control algorithm
0
nally adds a measured disturbance v=1, so that F and H can be embedded
and Dv, respectively, as additional columns.
v
ro offset values d
ining the linearized model matrices, are not relevant for the model
ictive control problem setup. In fact, only d-d ut measurements.
®
model describing the nonlinear dy n amical equations,
LINMOD. The linearized model has the form:
for unmeasured disturbances, while relevant for
0
, u0, v0, d0maybeobtainedbyusing
0
, u0, v0, d0)
0
can be estimated from
0
2-4

Optimization Problem

Standard Form

Assume that the estimates of x(k), xd(k) are available at time k (for state estimation, see “State Estimation” on page 2-9). The model predictive control action at time k is obtained by solving the optimization problem
Optimization Problem
(2-3)
where the subscript “( ) denotes the value predicted for time k+i based on the information available at time k; r(k) is the current sample of the output reference, subject to
espect to the sequence of input increments {Δu(k|k),.. .,Δu(m-1+k|k)}
with r
o the slack variable ε, and by setting u(k)=u(k-1)+Δu (k|k)*, where
and t
|k)* is the first element of the o ptimal sequence.
Δu(k
e Although only the measured output vector y
Not
el predictive controller, r(k) is a reference for all the outputs (measured
mod
unmeasured).
and
en the reference r is not known in advance, the current reference r(k)is
Wh
ed over the whole prediction horizon, so r(k+i+1)=r(k)inEquation2-3.
us
”denotes the j-th component of a vector, “(k+i|k)”
j
(k) is fed back to the
m
2-5
2 Model Predictive Control Problem Setup
In model predictive control the exploitation of future references is referred to as anticipative action (or look-ahead or preview). A similar anticipative action can be performed with respect to measured disturbances v(k), namely v(k+i)=v(k) if the measured disturbance is not known in advance (e.g. is coming from a Simulink block) or v(k+i) is obtained from the workspace. In the prediction, d(k+i) is instead obtained by setting n Diagram of a SISO Model Predictive Control Toolbox™ Application on page 1-2 and Controller State at the kth Sampling Instant on page 1-6.
Δu
w
smaller w, the less important is the behavior of the corresponding variable to the overall performance index.
u
, w
, w
i,j
i,j
(k+i)=0 in figures Block
d
y
, are nonnegative weights for the corresponding variable. The
i,j
u
j,minuj,max
, Δu
j,min
, Δu
j,max
, y
j,min
, y
are lower/upper bounds on the
j,max
corresponding variables. In Equation 2-4, the constraints on u, Δu,andy are relaxed by introducing the slack variable ε0. The weight ρε on the slack variable ε penalizes the violation of the constraints. The larger ρ
with respect
ε
to input and output weights, the more the constraint violation is penalized.
u
u
The Equal C oncern for the Relaxation (ECR ) vectors V
Du
V
max
, V
y
min
, V
y
have nonnegative entries which represent the concern for
max
min
, V
max
, V
Δu
min
,
relaxing the corresponding constraint; the larger V,thesofter the constraint. V=0 means that the constraint is a hard one that cannot be violated. By
default, all input constraints are hard (V
y
all output constraints are soft (V
min
=V
y
u
=V
min
=1). As hard output constraints
max
max
=V
Δu
min
=V
Δu
=0) and
max
u
may cause infeasibility of the op ti mization problem (for instance, because of unpredicted disturbances, model mismatch, or just because of numerical
y
round off), a warning messag e is produced if V
min
, V
y
are smaller than a
max
given small value and automatically adjusted at that value. By default,
(2-4)
Note that also ECRs can be time varying.
Vector u
(k+i) is a setpoint for the input vector. One typically uses u
target
target
if the number of inputs is greater than the number of outputs, as a sort of lower-priority setpoint.
2-6
Optimization Problem
As mentioned earlier, only Δu(k|k)isactuallyusedtocomputeu(k). The remaining samples Δ u(k+i|k) are discarded, and a new optimization problem based on y
(k+1) is solved at the next sampling step k+1.
m
The algorithm implemented in the Model Predictive Control Toolbox software uses different procedures depending on the presence of constraints. If all the bounds are infinite, then the slack variable ε is removed, and the problem in Equation 2-3 and Equation 2-4 is solved analytically. Otherwise a Quadratic Programming (QP) solver is used. The matrices associated with the quadratic optimization problem are described in “QP Matrices” on page 2-13 .
Sinceoutputconstraintsarealwayssoft,theQPproblemisneverinfeasible. If for numerical reasons the QP problem becomes infe asible, the second sample from the previous optimal sequence is applied, i.e. u(k)=u(k-1)+Δ
*
u(k|k-1).
Note To improve numerical robustness for constrained model predictive control problems the default value Δu
for unbounded input rates is
j,min
-10 and the maximum allowed lower bound is -1e5. The default value for unconstrained problems is minus infinity.

Alternative Cost Function

You have the option to use the following quadratic objective instead of the standard one (Equation 2-3):
(2-5)
where Q is an n positive semi-definite. Equation 2-5 allows non-zero off-diagonal weights but uses the same weights at each step in the prediction horizon.
by nymatrix, and and Ruare nuby numatrices, all
y
2-7
2 Model Predictive Control Problem Setup
Equation 2-3 and Equation 2-5 are equivalent when the weights , ,
and
and Ruare diagonal with the squares of the weights , ,and respectively as their diagonal elements.
Note When using the alternative cost function you must define the controller using MATLAB tool does not provide this option.
are constant for all , and when the matrices Q,
®
commands. The Model Predictive Control Toolbox d esign

Remarks on the Constraint Formulation

The constraints listed in Equation 2-3 are bounds of various types . They are generalinthesensethateachboundcanvaryateachstepintheprediction horizon. In addition, the linear model relating the plant inputs and outputs is a set of linear equality constraints and is included implicitly.
Quadratic programming allows general equalities and inequalities that are linear combinations of the decision variables. The current Model Predictive Control Toolbox does not allow you to include such constraints explicitly in your controller design.
If you have a small number of such constraints, consider incorporating them as new variables in your model. For example, suppose you would like a linear combination of selected inputs and outputstobekeptlessthanorequalto a given constant value. You can define a new model output to represent the linear combination. If the com binat ion involves manipulated variables, include a unit delay (to eliminate direct transfer from a manipulated variable to an output) or declare the combination to be an unmeasured output. Then define a bound on this output in your controller design.
2-8
If there is sufficient demand for generalized constraints, the feature may be included in a future toolbox release.

State Estimation

As the states x(k), xd(k) are not directly measurable, predictions are obtained from a state estim a tor. In order to provide more flexibility, the estimator is based on the m odel depicted in the following figure.
State Estimation
Model Used for State Estimation

Measurement Noise Model

We assume that the measured output vector ym(k) is corrupted by a measurement noise m(k). The measurement noise m(t)istheoutputofthe linear time-invariant system
system described by these equationsisdrivenbytherandomGaussian
The
se n
noi
(k), having zero me an and unit covariance matrix.
m
2-9
2 Model Predictive Control Problem Setup
Note The objective of the model predictive controller is to bring yu(k)and
[y
(k)-m(k)]ascloseaspossibletothereferencevectorr(k). For this reason,
m
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.

Output Disturbance Model

In order to guarantee asymptotic rejection of output disturbances, the overall model is augmented by an output disturbance model. By default, in order to reject constant disturbances due for instance to gain nonlinearities, the output disturbance model is a collection of integrators driven by white noise on measured outputs. Output integrators are added according to the following rule:
1 Measured outputs are ordered b y decreasing output w eight (in case
of time-varying weights, the sum of the absolute values over time is considered for each output channel, and in case of e qual output weight the order within the output vector is followed).
2-10
2 By following such order, an output integrator is added per measured
outputs, unless there is a violation of observability or the user forces it (through the
OutputVariables.Integrators property described in
“OutputVariables” in the Model Predictive Control Toolbox Reference ).
An arbitrary output disturbance model can be specified through the function
setoutdist.Seealsosetoutdist for ways to remove the default output
integrators.

State Observer

The state observer is designed to provide estimates of x(k), xd(k), xm(k), where x(k)isthestateoftheplantmodel,x
and output disturbance m odel, x model. The estimates are computed from the measured output y linear state observer
(k) is the overall state of the input
d
(k)isthestateofthemeasurementnoise
m
(k)bythe
m
State Estimation
where m denotes the rows of C,D corresponding to measured outputs.
To prevent numerical difficulties in the absence of unmeasured disturbances, the gain M is designed using Kalman filtering techniques (see
kalman in the
Control System Toolbox™ documentation) on the extended model
(2-6)
where n
(k)andnv(k) are additional unmeasured white noise disturbances
u
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-11
2 Model Predictive Control Problem Setup
Note The overall state-space realization of the combination of plant and
disturbance models m ust be observable for the state estimation design to succeed. Model Predictive Control Toolbox softw are first checks for observability of the plant, provided that this is given in state-space form. After all models have b een converted to discrete-time, delay-free, state-space form and combined together, observability of the overall extended model is checked (see Predictive Control Toolbox Reference).
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 that you can use to access and modify properties of the state estimator.
setestim and “Construction and Initialization” in the Model
2-12

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” on page 2-13
“Optimization Variables” o n page 2-14
“Cost Function” on page 2-16
“Constraints” on page 2-18

Prediction

Assume for simplicity that the disturbance model in Equation 2-1 and Equation 2-2 is a unit gain (i.e., d(k)=n simplicity, denote by
(k) is a w hite Gaussian noise). For
d
Then, the prediction model g iven by
.
Consider for simplicity the prediction of the future trajectories of the model performed at time k=0. We set n
which gives
(i)=0 for all prediction instants i,andobtain
d
2-13
2 Model Predictive Control Problem Setup
where
2-14

Optimization Variables

Let m be the number of free control moves and denote by z=[z0; ...; z
]. Then,
m-1
QP Matrices
(2-7)
where J
depend
M
variable ε,ve optimization
z
, ..., z
0
re scalars).
a
m-1
s on the choice of blocking moves. Together with the slack
ctors z
,...,z
0
constitute the free optimization variables of the
m-1
problem (in case of systems with a single manipulated variables,
Blocking Moves: Inputs and Input Iincrements for moves=[2 3 2]
Consider for instance the blocking moves depicted in Blocking Moves: Inputs and Input Iincrements for moves=[2 3 2] on page 2-15, which 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.
Then, the corresponding matrix J
is
M
2-15
2 Model Predictive Control Problem Setup

Cost Function

Standard Form
The function to be optimized is
2-16
where
Finally, after substituting u(k ), Δu(k), y(k), J(z) can be rewritten as
QP Matrices
(2-8)
(2-9)
Note In order to keep the QP problem always strictly convex , if the condition number of the Hessian matrix K
10*sqrt(eps) is added on each diagonal term. This may only occur when all
input rates are not weighted (W
Δu
=0) (see “Weights” in the Model Predictive
is larger than 1012, the quantity
ΔU
Control Toolbox Reference).
Alternative Cost Function
If the alternative cost function shown in Equation 2-5 is being used, Equation 2-8 is replaced by the following:
(2-10)
where the block-diagonal matrices repeat p times, i.e., once for each step in the prediction horizon.
2-17
2 Model Predictive Control Problem Setup
You also have the option to use a combination of the standard and alternative forms. See “Weights” in the M odel Predictive Control Toolbox Refe rence for more details.

Constraints

Let us now consider the limits on inputs, input increments, and outputs along with the constraint ε 0.
2-18
Note Up input
Simil Δu(k
where matrices M bounds and ECR values.
per and lower bounds that are not finite are removed, as well as the
and input-increment bounds over blocked moves.
arly to what was done for the cost function, we can substitute u(k),
), y(k), and obtain
z,Mε,Mlim,Mv,Mu,Mx
are obtained from the upper and lower
(2-11)
Function m pc_buildmat constructs the QP problem matrices.
QP Matrices
2-19
2 Model Predictive Control Problem Setup

Model Predictive Control Computation

This section describes how the model predictive control optim ization problem is solved at each time step k (in
mpcloop_engine.mex) by using the matrices built at initialization describe d
in “QP Matrices” on page 2-13.

Unconstrained MPC

The optimal solution is computed analytically
and the model predictive controller sets Δu(k)=z*0, u(k)=u(k-1)+Δu(k).
mpcmove, mpc_sfun.mex,and
2-20

Constrained Model Predictive Control

The optimal solution z*, ε* is computed by solving the quadratic program described in Equation 2-9 and Equation 2-11, using the QP solver coded in the
qpsolver.mex function (see qpdantz for more details).

Using Identified Models

ModelPredictiveControlToolboxsoftwareisabletohandleplantmodels generated by System Identification Toolbox software from input/output measurements.
Model Predictive Control Toolbox software labels control input signals as ‘Manipulated’, measured input disturbances as ‘Measured’, and unmeasured input disturbances as ‘Unmeasured’. On the other hand, System Identification Toolbox software has a different naming rule, as it calls ‘Measured’ the inputs that are measurable quantities, and ‘Noise’ those that are not.
When you specify an identified model in the Model Predictive Control constructor as the plant model, Model Predictive Control Toolbox software treats ‘Noise’ signals as ‘Unmeasured’ input signals, and ‘Measured’ signals as ‘Manipulated’ signals, a ssuming that all measured inputs are also manipulated variables. You can later change later signal types, for instance to specify that some m easured inputs are measured disturbances, rather than manipulated variables (see
Using Identified Models
setname).
Model Predictive Control Toolbox software internally converts the identified model you have provided as a plant model into the classical (A,B,C,D) state-space format. The columns of the B matri x originally related to ‘Noise’ channels are treated as the effect of unmeasured input disturbances on the state of the plant. On the other hand, the columns of the D matrix related to ‘Noise’ channels as treated as the effect of measurement noise superimposed on the output signal. Accordingly, Model Predictive Control Toolbox software treats as the plant model the state-space model obtained from (A,B,C,D) by zeroing the columns of D related to ‘Noise’ channels. Those columns are instead used as a static noise model, or cascaded to an existing noise model if you have specified one. A unit static gain is assumed as the disturbance model, unless you have specified another one.
2-21
2 Model Predictive Control Problem Setup
2-22

Model Predictive Control Simulink Library

“MPC Library” on page 3-2
“MPC Controller Block” on page 3-3
“Multiple MPC Controllers” on page 3-8
3
3 Model Predictive Control Simulink

MPC Library

The MPC Simulin k Library provides two blocks you can use to model MPC control in Simulink.
®
Library
Access the library using the Simulink Library Browser or by typing the command prompt. The latter reveals the library’s contents as shown in the following figure.
MPC Simulink®Library
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.
mpclib at
3-2

MPC Controller Block

The MPC Controller block provides a user friendly way to model MPC control in Simulink. It represents a single MPC controller in which the design parameters remain constant throughout a simulation.

MPC Controller Block Mask

Once you have placed an M PC Controller block in your Simulink model, you need to specify its properties. Double-click on the blo ck to ope n its mask. The following figure shows the mas k’s default settings.
MPC Controller Block
MPC Controller Block Mask
By default, the MPC controller field is empty. Before running a simulation you must enter the name of a valid MPC object. There are two ways to do this:
1 In the MPC controller field, type the name of an MPC object that already
exists in your workspace. If you want to review the settings before running
3-3
3 Model Predictive Control Simulink
a simulation, click the Design button to load the named object into the MPC design tool.
®
Library
2 If your installation includes the Simulink
®
Control Design™ software, connect the MPC Controller block to the plant it will control (see the following sections for connection details). Leaving the MPC controller field empty, click the Design button. The MPC Controller block constructs a default MPC object by linearizing the plant defined in the Simulink diagram. See “Importing a Plant Model” on page 5-10 for more information about creating linearized plant models using Model Predictive Control Toolbox software. Refer to the Simulink Co ntro l D es ig n documentation for more information about the linearization process.
Note Youcanrunclosed-loopsimulations while a controller is being edited in the design tool. In this case, the latest settings from the design to ol are used in each the Simulink simulation. This makes it convenient to tune the controller parameters. When you close the design tool, export the final controller design to the workspace so it can be used in subsequent simulations.

Input Signals

You must connect appropriate Simulink signals to the MPC Controller block’s inports. The measured output ( You can add optional inports by selecting check boxes at the bottom of the mask.
mo) and reference (ref) inports are required.
3-4
As shown in the figure, MPC Controller Block Mask on page 3-3 , Enable input port for 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.
Enable input port for externally supplied manipulated variables to plant allows you to keep the controller informed of the actual manipulated
variable values. Ideally, the actual manipulated variables are those specified by the controller block output
mv. In practice, unexpected constraints,
disturbances, or plant nonlinearities can modify the values actually implemented in the plant. If the actual values are known and fed back to the controller, its predictions improve. This feature can also improve the
MPC Controller Block
transition between manual and automatic operation. See “Bumpless Transfer in MPC” on page 4-39.
Enable input port for 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 demo
mpcvarbounds shows how this option works. It enables inports for lower
and upper bounds on the manipulated variables (inports and lower and upper bounds on the controlled outputs (inports
ymax). An unconnected constraint inport causes the corresponding variable
umin and u max)
ymin and
to be unconstrained.
Enable input port for switching optimization off allows you to control whether or not the block performs its optimization calculations at e ach 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.
If you select the switching option, the Enable input port for externally supplied manipulated variables to plant option must also be activated. See “Bumpless Transfer in M PC” on page 4-39 for an example application.

Look Ahead and Signals from the Workspace

The mask’s Input signals section allows you to define the reference and/or measured disturbance signals as variables in the workspace. In this case, the block ignores the signals connected to its corresponding inports.
You must create such a signal as a MATLAB structure with two fields: and signals.TheSimulinkFrom W orkspace and To Workspace blocks use the same format.
For example, to specify a sinusoidal reference signal sin(t)overatimehorizon of 10 seconds, use the following MATLAB commands:
time=(0:Ts:10); ref.time=time;
time
3-5
3 Model Predictive Control Simulink
ref.signals.values=sin(time);
where Ts is the controller sampling period. After the variable is created, select the Use custom reference signal check box and enter the variable name in the edit box.
An alternative would be to run a Simulink simulation in which you connect an appropriate block (Sine,intheaboveexample)toaTo Workspace block.
The Look ahead check box enables an anticipative action on the corresponding signal. This option becomes available when you define reference a nd measured disturbance signals in the workspace. For example, if you define the reference signal as described above, the Look ahead option becomes available. Selecting it causes the controller to compensate for the known future reference variations, which usually improves setpoint tracking. When Look ahead is disabled or unselected, the controller assumes that the current reference (or measured disturbance) value applies throughout its prediction horizon.
®
Library
3-6
See the demo reading signals from the workspace.
mpcpreview for an illustrative example of enabling preview and

Initialization

If Initial controller state is unspecified, as in MPC Controller Block Mask on page 3-3, the controller uses a default initial condition in simulations. You can change the initial condition by s pecifying an “MPC Simulation Options Object” in the Model Predictive Control Toolbox Reference.
mpcstate object. See
Using Model Predictive Control Toolbox Software with Real-Time Workshop Software
After designing an MPC controller in Simulink software using the MPC Controller block, you can use Real-Time Workshop controller and deploy it to the following targets for r eal-time control:
Generic Real-Time Target
Real-Time Workshop
®
Embedded Coder™
®
software to build this
MPC Controller Block
Real-Time Windows Target™
Rapid Simulation Target
Target for Freescale™ MPC5xx
xPC Target™
dSpace Target
Target for Infineon
®
TriCore
®
The following targets are either not supported or not recommended because they result in significant performance issues:
Target Support Package™ for Use with TI’s C2000™
Target Support Package for Use with T I’s C6000™
Target Support Package for Use with Infineon
®
C166
®
Tornado®(VxWorks) Real-Time Target
Note The Multiple MPC Controllers block has not been tested with the
targets supported by Real-Time W orkshop software.
The C sources of the S-function executing the MPC Controller block code are available in the
mpcutils/src folder. You can build a real-time executable
by pressing Ctrl+B on your Simulink diagram to invoke Real-Time Windows Target and build the model.
In some cases, it is necessary to copy the source files (
mpc_common.c, mat_macros.h, dantzgm p.h, dantzgmp_solver.c)toavisible
folder, such as the current folder
'.',or'C: \MAT LAB\rtw\c\src'.
mpc_sfun.c, mpc_sfun.h,
3-7
3 Model Predictive Control Simulink
®
Library

Multiple MPC Controllers

The Multiple MPC Controllers (MMPC) block allows you to control a nonlinear plant over a large range of operating points. You can design multiple MPC controllers inside this block, and switchbetweentheminreal-timeusingan input switching signal to the block.
A controller that initially works well can degrade dramatically if the plant is nonlinear and its operating point changes. In conventional feedback control, you might compensate for nonlinear behavior with gain scheduling. Similarly, the MMPC block allows you to tran si t ion between multiple MPC controllers in a pre-ordained manner. Each MPC controller is designed to work well in a particular region. When the plant moves away from this operating point, the control system switches to another MPC controller.
As with the standard MPC Controller block described in “MPC Controller Block” on page 3-3, you copy the MM PC block into your Simulink model and then double-click the m ask to reveal its settings. Multiple MPC Controller Block Mask Default Settings on page 3-10 shows the default settings.
3-8
The key difference between this block and the standard MPC Controller block is the way you designate the controllers to be used. You enter them as an ordered list containing use and each name designates a valid MPC object existing in the MATLAB workspace. Each named controller must be designed to use the identical set of plant signals. For example, same measured outputs and same manipulated variables.
Use the Add and Delete buttons as needed to add and remove MPC controllers from the list.
Note You can als o load one or more controllers into the design tool where you can view controller properties and modify them. Select controller(s) using the Design It checkboxes. Then click the Design button, which causes the design tool to open and loads the selected controller(s). After the design is complete, export the controller(s) from the design tool to the MATLAB workspace.
Nc names, where Nc is the number of controllers to
Multiple MPC Controllers
Use your knowledge of the process to identify the operating points and des ign the controllers for the plant. If you have already designed the controllers in the MATLAB workspace, import the MPC object to the Multiple MPC Controllers block. Y ou can also use the Simulink Control Design software to compute the operating points, obtain linear models and design the controllers. To learn more, see the Simulink Contro l D esign documentation.
After you ad d the controllers to the Multiple MPC Controllers block, determine the switching mechanism for the controllers. For example, you can choose one or more m easurements from the process to determine when a specific controller is active. This switching signal must round to an integer 1 when the first controller is to be used, to 2 when the second is to be used, and so on. The MMPC block automatically rounds the switching signal to the nearest integer. If the switch signal is less than or equal to zero, or greater than
Nc, none of the controllers activates and the block output goes to zero. In
general, you will need to use measurements and plant-specific information in order to decide on the controller to be used at a given moment. Thus, generation of the switching signal will usually require special provisions in your Simulink model.
To allow the control system to switch between controllers based on the switching signal when a simulation is running, connect the switching signal to the block’s
switch inport.
The inactive controllers automatically receive the current manipulated variable and measured output signals so they can update their state estimates. This minimizes bumps in controller transitions (see “Bumpless Transfer in MPC” on page 4-39). It is good practice to select Enable input port for externally supplied manipulated variables to plant and connect the actual plant input signal to the
ext.mv block inport, in which case
the block fee ds this signal to all its controllers.
3-9
3 Model Predictive Control Simulink
®
Library
3-10
Multiple MPC Controller Block Mask Default Settings
The other block mask settings shown i n Multiple MPC Controller Block Ma sk DefaultSettingsonpage3-10havethesamepurposeasinthestandardMPC Controller block. See “MPC Controller Block” on page 3-3 for details.
Seealsothe
mpcswitching and mpccstr demos for example u se s of the
MMPC block.

Case-Study Examples

“Introduction” on page 4-2
“Servomechanism Controller” on page 4-3
“Paper Machine Process Control” on page 4-27
“Bumpless Transfer in MPC” o n page 4-39
“Nonlinear Control Using Multiple Models” on page 4-46
“Using the Tuning Advisor” on page 4-54
“Bibliography” on pag e 4-59
4
4 Case-Study Examples

Introduction

This chapter describes some typical model predictive control applications. Familiarity with LTI models (from the Con t rol System Toolbox product) and Simulink block diagrams will make the examples easier to understand, but you can skip the modeling details to focus on the control aspects.
Thefirstexampledesignsaservomechanism controller. The specifications require a fast servo response despite constraints on a plant input and a plant output.
The second example controls a paper machine headbox. The process is nonlinear, and has three outputs, two manipulated inputs, and two disturbance inputs, one of which is measured for feedforward control.
The third example demonstrates Model Predictive Control Toolbox bumpless transfer between manual and automatic operation. The context is a Simulink simulation involving the MPC Controller b lock and a single-input, single-output, LTI plant.
4-2
The fourth example is a nonlinear chemical reactor (CSTR). It has three inputs and two outputs. The challenge is to mov e the reactor operating conditions from an intial steady-state point to a much different condition. The transition passes through a region in which the plant is open-loop unstable. The solution uses the Simulink Multiple MPC Controller block to coordinate the use of three controllers, each of which has been designed for a particular operating region.

Servomechanism Controller

Servomechanism Controller
Position Se
System Mod
Aposition aload(se equation
where V is the applied voltage, T isthetorqueactingontheload, is
the load’s angular velocity, and the other symbols represent constant parameters (see Parameters Used in the Servomechanism Model on page 4-4 for more information on these).
If we define the state variables as the above model to an LTI state-space form:
rvomechanism Schematic
el
servomechanism consists of a DC motor, gearbox, elastic shaft, and
e Position Servomechanism Schematic on page 4-3). The differential
s representing this system are
is the motor shaft’s angular velocity,
,wecanconvert
4-3
4 Case-Study Examples
Parameter
Symbol Value (SI Units) Definition
R
s Used in the Servomechanism Model
1280.2
10
0.5
50
20
0.1
25
20
Torsional rigidity
Motor constant
Motor inertia
Load inertia
Gear ratio
Motor viscous friction coefficient
Load viscous friction coefficient
mature resistance
Ar
4-4
Servomechanism Controller
Control Objecti
The controller by adjusting th
feedback is
must set t he load’s angular positio n,
.
ves and Constraints
,atadesiredvalue
e applied voltage, V. The only measurement available for
The elastic shaft has a finite shear strength, so the torque, T,muststay within specified limits
Nm
Also, the applied voltage must stay within the range
V
From an i manipul
to the controller,
nput/output viewpoint, the plant has a single input, V,whichis
ated by the controller. It has two outputs, one measured and fed back
, and one unmeasured, T.

Defining the Plant Model

The first step in a d esign is to define the plant model. The following commands are from the MPC demos file mpcmotormodel.m, which you can run instead of entering the commands manually.
motor with elastic shaft
% DC-
%
rameters (MKS)
%Pa
---------------------------------------------------------
%--
aft=1.0; %Shaft length
Lsh
haft=0.02; %Shaft diameter
ds
aftrho=7850; %Shaft specific weight (Carbon steel)
sh
81500*1e6; %Modulus of rigidity
G=
uam=50*1e6; %Shear strength
ta
motor=100; %Rotor mass
M
motor=.1; %Rotor radius
R
motor=.5*Mmotor*Rmotor^2; %Rotor axial moment of inertia
J
motor=0.1; %Rotor viscous friction coefficient (A CASO)
B
R=20; %Resistance of armature
Kt=10; %Motor constant
4-5
4 Case-Study Examples
gear=20; %Gear ratio
Jload=50*Jmotor; %Load inertia
Bload=25; %Load viscous friction coefficient
Ip=pi/32*dshaft^4; %Polar momentum of shaft (circular) section
Kth=G*Ip/Lshaft; %Torsional rigidity (Torque/angle)
Vshaft=pi*(dshaft^2)/4*Lshaft; %Shaft volume
Mshaft=shaftrho*Vshaft; %Shaft mass
Jshaft=Mshaft*.5*(dshaft^2/4); %Shaft moment of inertia
JM=Jmotor;
JL=Jload+Jshaft;
Vmax=tauam*pi*dshaft^3/16; %Maximum admissible torque
Vmin=-Vmax;
%Input/State/Output continuous time form
%----------------------------------------------------------
AA=[0 1 0 0;
-Kth/JL -Bload/JL Kth/(gear*JL) 0;
000 1;
Kth/(JM*gear) 0 -Kth/(JM*gear^2) -(Bmotor+Kt^2/R)/JM];
4-6
BB=[0;0;0;Kt/(R*JM)];
Hyd=[1 0 0 0];
Hvd=[Kth 0 -Kth/gear 0];
Dyd=0;
Dvd=0;
% Define the LTI state-space model
sys=ss(AA,BB,[Hyd;Hvd],[Dyd;Dvd]);

Controller Design Using MPCTOOL

The servomechanism m odel is linear, so you can use the Mode l Predictive Control Toolbox design tool (
Note To follow this example on your ow n system, first create the servomechanism model as explained in “Servomechanism Controller” on page 4-3. This defines the variable
mpctool) to configure a controller and test it.
sys in your MATLAB workspace.
Servomechanism Controller
Opening MPCTOOL and Importing a Model
To begin, open the design tool by typing the following at the MATLAB p rom pt:
mpctool
Once the design tool has appeared, click the Import Plant button. The Plant Model Importer d ialog box appears (see the followin g 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, is selected. The Properties area lists the selected model’s key attributes.
sys istheonlyavailablemodel,andit
Import Dialog Box with the Servomechanism Model Selected
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 diagram at the top ennumerates the model’s input and output signals.
4-7
4 Case-Study Examples
4-8
Design Tool After Importing the Plant Model and Specifying Signal Properties
Specifying Signal Properties
It’s essential to specify signal types before going on. By default, the design tool assumes all plant inputs are manipulated, which is correct in this case. But it also assumes all outputs are measured, which is not. Specify that the second output is unmeasured by clicking on the appropriate table cell and selecting the Unmeasured option.
Youalsohavetheoptiontochangethedefaultsignalnames(
Out2) to something more meaningful (e.g., V, ThetaL, T), enter descriptive
information in the blank Description and Units columns, and specify a nominal initial value for each signal (the default is zero).
In1, Out1,
Servomechanism Controller
After you’ve entered all your changes, you should see a view similar to Design Tool After Importing the Plant Model and Specifying Signal Properties on page 4-8. Notice that the upper graphic designates one output as measured, the other as unmeasured.
Navigation Using the Tree View
Now consider the design tool’s left-hand frame. This tree is an ordered arrangement of nodes. Selecting (clicking) a node causes the corresponding view to appear in the right-hand frame. When the design tool starts, it creates a root node named MPCdesign and selects it, as in Design Tool After Importing the Plant Model and Specifying Signal Properties on page 4-8.
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 and Specifying Signal Properties on page 4-8). 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 m odels view. The table columns show important controller settings: the plant model being used, the controller sampling period, and the prediction and control horizons. All are editable. For now, leave them at their default values.
The buttons on the Controllers view allow you to:
Import a controller designed previously and stored either in your
workspace or in a MAT-file.
Export the selected controller to your workspace.
Create a New controller, which will be initialized to the Model Predictive
Control Toolbox defaults.
Copy the selected controller to create a duplicate that you can modify.
4-9
4 Case-Study Examples
Delete the selected controller.
Specifying Controller Properties
Select the MPC1 subnode. The main pane should change to the controller design as shown in the following figure.
4-10
Controller Design View, Models and Horizons Pane
If the selected Prediction model is continuous-time, as in this example, the Control interval (sampling p eriod) defaults to 1. You need to change this to an application-appropriate value. Set it to 0.1 seconds (as shown in Controller Design View, Models and Horizons Pane on page 4-10). Leave the other values at their defaults for now.
Servomechanism Controller
Controller Design View, Constraints Pane
Specifying Constraints
Next, click the Constraints tab. The view shown in Controller Design View, Constraints Pane on page 4-11 appears. Enter the appropriate constraint values. Leaving a field blank implies that there is no constraint.
In general, it’s good practice to include all known manipulated variable constraints, but it’s unwise to enter constraints on outputs unless they are an essential aspect of your application. The limit on applied torque is such a constraint, as are the limits on applied voltage. The angular position has physical limits but the controller shouldn’t atte mpt to enforce them, so you should leave the corresponding fields blank (see Controller Design View, Constraints Pane on page 4-11).
4-11
4 Case-Study Examples
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 an d edit its tables. Such changes apply to all controllers in the design.
Weight Tuning
Next, click the Weight Tuning tab to obtain a view like that shown in Controller Design View, Weight Tuning Pane on page 4-13.
The weights specify trade-offs in the controller design. First consider the Output weights. The controller will try to minimize the deviation of e ach 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.)
4-12
Here, the angu lar position should track its setpoi nt, but the a pp l ied torque can vary, provided that it stays within the specifie d 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 s hould 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 d efault, 0.1.
When setting the rates, the relative magnitudesaremoreimportant 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.
Servomechanism Controller
Controller Design View, Weight Tuning Pane
The tables allow you to weig ht individual variables. The slider at the top adjusts an overall trade-off between controller agressiveness 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.
The Estimation tab allows you to adjust the controller’s response to unmeasured disturbances (not use d in this example).
4-13
4 Case-Study Examples
4-14
Simulation Settings View for “Scenario1”
Defining a Simulation Scenario
If you haven’t already done so, expand the Scenarios node to show the Scenario1 subnode (see Design Tool After Importing the Plant Model and
Specifying Signal Properties on page 4-8). Select Scenario1 to obtain the view shown in Simulation Settings View for “Scenario1” on page 4-14.
A scenario is a set of simulation conditions. As shown in Simulation Settings View for “Scenario1” on page 4-14, you choose the controller to be used (from among controllers in your design), the model to act as the plant, and the simulation duration.
You must also specify all setpoints and disturbance inputs.
Duplicate the settings shown in Simulation Settings View for “Scenario1” on page 4-14, which will test the controller’s servo response to a unit-step change
Servomechanism Controller
in the angular position setpoint. All other inputs are being held constant at their nominal values.
Note The ThetaL and V unmeasured disturbances allow you to simulate additive disturbances to these variables. B y default, these disturbances are turned off, i.e., zero.
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.
Response to Unit Step in the Angular Position Setpoint
ning a Simulation
Run
Once you’re ready to run the scenario, click the Simulate button or the green arrow on the toolbar.
4-15
4 Case-Study Examples
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 ResponsetoUnitStepintheAngularPosition Setpoint on page 4-15. The blue curves are the output signals, and the gray curves are the corresponding setpoints. Theresponseisverysluggish,and hasn’t settled within the 30-second simulation period.
Note The window shown in Response to Unit Step in the Angular Position Setpoint on page 4-15 provides many of the customization features available in Control System Toolbox a curve to obtain the numerical characteristics o f the selected point, or right-clicking in the plot area to open a customizatio n menu.
ltiview and sisotool displays. Try clicking
4-16
The corresponding applied voltage adjustments appear in a separate window (not shown) and are also very sluggish.
On the positive side, the applied torque stays well within bounds, as does the applied voltage.
Retuning to Achieve a Faster Servo Response
To obtain a more rapid servo response, navigate to the MPC1 W eight Tuning pane (select the MPC1 node to get the controller design view, then click the Weight Tuning tab) and move the slider all the way to the right. Then click the green arrow in the toolbar. Your results should now resemble Faster Servo Response on page 4-17 and Manipulated Variable Adjustments on page 4-17.
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-17) and the applied voltage stays within its limits (see Manipulated Variable Adjustments on page 4-17).
Faster Servo Response
Servomechanism Controller
Manipulated Variable Adjustments
Modifying the Scenario
Finally, increase the step size to π radians (select the Scenario1 node and edit the tabular value).
4-17
4 Case-Study Examples
As shown in Servo Response for Step Increase of π Radians on page 4-18 and Voltage Adjustments on page 4-19, 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-19).
4-18
Servo Re
sponse for Step Increase of Radians
Servomechanism Controller
Voltage Adjustments
Saving Your Work
Once you’re satisfied with a controller’s performance, you can export it to the workspace, for use in a Simulink block diagram or for analysis (or you can save it in a MAT -file).
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 aControllertotheWorkspaceonpage4-20willappear.
The Controller source is the design from which you w ant to extract a controller. There’s only one in this examp le , but in general you might be working on several simultaneously. The Controller to export choice defaults to the controller m ost recently selected. Again, there’s no choice in this case, but there could be in general. The Name to assign edit b o x allows you to rename the exported co ntro ller . (This will not change its name in the design tool.)
4-19
4 Case-Study Examples
Exporting a Contro
Note When you exi
design in a MAT fi menu option or th
Using Model Pre
Once you’ve be to build a cont
For example, the Plant Mod
ManipulatedVariables = struct('Min', -220, 'Max', 220, 'Units', 'V'); OutputVariables(1) = struct('Min', -Inf, 'Max', Inf, 'Units', 'rad'); OutputVariables(2) = struct('Min', -78.5, 'Max', 78.5, 'Units', 'Nm'); Weights = struct('Input', 0, 'InputRate', 0.05, 'Output', [10 0]); Model.Plant = sys; Model.Plant.OutputGroup = {[1], 'Measured' ; [2], 'Unmeasured'}; Ts = 0.1; PredictionHorizon = 10; ControlHorizon = 2;
ller to the Workspace
t the design tool, you will be prompted to save the entire
le. This allows you to reload it later using the File/Load
e Load icon on the toolbar.
dictive Control Toolbox Commands
come familiar with the toolbox, you may find it more convenient
roller and run a simulation using commands.
suppose that you’ve defined the model as discussed in “Defining
el” on page 4-5. Consider the following command sequence:
4-20
This creates several structure variables. For example, ManipulatedVariables defines the display units and constraints for the applied voltage (the manipulated plant input). in Controller Design View, Weight Tuning Pane on page 4-13 (but the numerical values used here provide better performance).
Weights defines the tuning weights shown
Model designates
Servomechanism Controller
the plant model (stored in sys, which w e defined earlier). The code also sets the
Model.Plant.OutputGroup property to designate the second output as
unmeasured.
Constructing an MPC Object
Use the mpc command to construct an MPC object called ServoMPC:
ServoMPC = mpc(Model, Ts, PredictionHori zon, ControlHorizon);
Like the LTI objects used to define linear, time-invariant dynamic models, an MPC object contains a complete definition of a con tro ller.
Setting, Getting, and Displaying Object Properties
Once you’ve constructed an MPC object, you can change its properties as you would for other objects. For example, to change the prediction horizon, you could use one of the following commands:
ServoMPC.PredictionHorizon = 12; set(ServoMPC, ' Pre dictionHorizon', 12) ;
For a listing of all the object’s properties, you could type:
get(ServoMPC)
To access a particular p roperty (e.g., the control horizon), you could type either:
M = get(ServoMPC, 'ControlHorizon'); M = ServoMPC.ControlHorizon;
You can also set multiple properties simultaneously.
Set the following properties before continuing with this ex ample:
set(ServoMPC, 'Weights', Weights, ...
'ManipulatedVariables', ManipulatedVariables, ... 'OutputVariables', OutputVariables);
4-21
4 Case-Study Examples
Typingthenameofanobjectwithoutaterminating semicolon generates a formatted display of the object’s properties. You can achieve the same effect using the display command:
display(ServoMPC)
Running a Simulation
The sim command performs a linear simulatio n. 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.
4-22
The
sim command saves the output and manipulated variable sequences
in variables
subplot(311) plot(t, y(:,1), [0 t(end)], pi*[1 1]) title('Angular Position (radians)'); subplot(312) plot(t, y(:,2), [0 t(end)], [-78.5 -78.5]) title('Torque ( nM) ') subplot(313) stairs(t, u) title('Applied Voltage (volts)') xlabel('Elapsed Time (seconds)')
y and u . For example,
produces the custom plot shown in Plotting the Output of the sim Command on page 4-23. The plot includes the angular position’s setpoint. The servo response settles within 5 seconds with no overshoot. It al so displays the torque’s lower bound, which becomes active after about 0.9 seconds but isn’t exceeded. T he applied voltage saturates between about 0.5 and 2.8 seconds, but the controller performs well despite this .
Servomechanism Controller
Plotting the Output of the sim Command

Using MPC Tools in Simulink

Block Diagram for the Servomechanism Example on page 4-24 is a Simulink block diagram for the servomechanism example. Most of the blocks are from the standard Simulink library. There are two exceptions:
Servomechanism Model is an L TI System block from the Control System
Toolbox library. The LTI model defines its dynamic behavior. To review how to create this model, see “Defining the Plant Model” on page 4-5.
MPC Controller is from the MPC Blocks library. Model Predictive Control
Toolbox™ Simulink
®
Block Dialog Box on page 4-24 shows the dialog box obtained by double-clicking this block. You need to supply an MPC object, and
ServoMPC is being used here. It must be in the workspace before you
run a simulation. The Design button opens the design tool, which allows
sys (which must exist in the workspace)
4-23
4 Case-Study Examples
you to create or modify the object. To review how to use commands to create
ServoMPC, see “Constructing an MPC Object” on page 4-21.
Block Diagram for the Servomechanism Example
4-24
Model Predictive Control Toolbox™Simulink®Block Dialog Box
The key features of the diagram are as follows:
Servomechanism Controller
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 ontheAnglescope(yellowcurve). The torque plots on the Torque scope (with its lower and upper bounds).
The position setpoint varies sinusoidally with amplitude π radians and
frequency 0.4 rad/s. It also appears on the Angle scope (magenta curve).
Servomechanism Simulation Scopes on page 4-26 shows the scope displays for a 20-second simulation. The angular position tracks the sinusoidal setpoint variations well despite satura t ion 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-25
4 Case-Study Examples
4-26
Servomechanism Simulation Scopes

Paper Machine Process Control

Schematic of Paper Machine Headbox Elements
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 model is a set of o rdina ry differential equations (ODEs) in bilinear form. The states are
Paper Machine Process Control
where H1is the liquid level in the feed tank, H2is the headbox liquid level, N
is the feed tank consistency, and N2is the headbox consistency. The
1
measured outputs are:
rimary control objectives are to hold H
The p
anipulated variables
two m
and N2at setpoints. There are
2
where Gpis the flow rate of stock entering the feed tank, and Gwis the recycled white water flow rate. The consistency of stock entering the feed tank, N
, is a measured disturbance.
p
4-27
4 Case-Study Examples
The white water consistency is an unmeasured disturbance.
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
G
, Gw, Np, Nw, and the output sequence is2, N1, N2.
p

Linearizing the Nonlinear Model

The paper machi n e headbox model is easy to lineari ze analytically, yie lding the following state space matrices:
A = [-1.9300000
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
0000
1.3400 -0.6500 0.2030 0.4060 0000];
C = [0 1.0000 0 0
0 0 1.0000 0 0 0 0 1.0000];
D = zeros(3,4);
4-28
Use these to create a continuous-time LTI state-space model, as follows:
PaperMach = ss(A, B, C, D); PaperMach.InputName = {'G_p', 'G_w', 'N_p ', 'N_w'}; PaperMach.OutputName = {'H_2', 'N_1', 'N_ 2'};
(The last two commands are optional; they improve plot labeling.)
As a quick check of model validity, plot its step re sponses as follows:
Paper Machine Process Control
step(PaperMach);
Theresultsappearinthefollowingfigure. Notethefollowing:
The two manipulated variables affect all three outputs.
They have nearly identical effects on H
The
pairing exhibits an inverse response.
.
2
Thesefeaturesmakeitdifficulttoachieve accurate, independent control of H
and N2.
2
Linearized Paper Machine Model’s Step Responses

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-7.
4-29
4 Case-Study Examples
Next, define signal properties, being sure to designate Npand Nwas measured and unmeasured disturbances, respectively. Your sp e cifications should resemble Signal Properties for the Paper Machine Application on page 4-30.
Signal Properties for the Paper Machine Application
4-30
Initial Controller Design
If necessary, review “Specifying Controller Properties” on page 4-10. Then click the MPC1 node and specify the following controller parameters (leaving others at their default values):
Models and Horizons. Control interval = 2 minutes
Constraints.ForbothG
and Gw,Minimum=-10,Maximum=10,Max
p
down rate = -2, Max u p rate = 2.
Weight Tuning.ForbothG
For N
, Weight = 0. (Other outputs have Weight = 1.)
1
and Gw,Weight=0,Rateweight=0.4.
p
Servo Response
Finally, select the Scenario1 node and d efine a servo-response test:
Duration = 30
H
setpoint = 1 (constant)
2
Paper Machine Process Control
Simulate the scenario. You should obtain results like those shown in Servo Response for Unit Step in Headbox Level Setpoint on page 4-31 and Manipulated Variable Moves on page 4-31.
Servo Res
Manipulated Variable Moves
ponse for Unit Step in Headbox Level Setpoint
4-31
4 Case-Study Examples
Weight Tuning
Theresponsetimeisabout8minutes. We could reduce this by decreasing the control interval, reducing the manipulated variable rate weights, and/or eliminating the up/down rate constraints. T he 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 N
(it’s about -0.25 units in Servo Response
1
for Unit Step i n Headbox Level Setpoint on page 4-31). There are only two manipulated variables, so it’s impossible to hold three outputs at setpoints. We don’t have a setpoint for N
so we have set its weight to zero (see controller
1
settings in “Initial Controller Design” on page 4-30). Otherwise, all three outputs would have exhibited steady-state error (try it).
Consistency control is more important than level control. Try decreasing the
H
weight from 1 to 0.2. You should find that the peak error in N2decreases
2
by almost an order of magnitude, but the H
response time increases from
2
8 to about 18 minutes (not shown). Use these modified output weights in subsequent tests.
Feedforward Control
To configure a test of the con tro ller’s feedforward response , define a new scenario by clicking the Scen arios node, clicking the New bu tton , and renaming the new scenario Feedforward (by editing its name in the tree or the summary list).
In the Feedforward scenario, define a step change in the measured disturbance, N setpoints should be zero. Set the Duration to 30 time units.
If response plots from the above servo response tests are still open, close them. Simulate the Feedforward scenario. You should find that the H
N
outputs deviate very little from their setpoints (not shown).
2
,withInitial value =0,Size =1,Time = 10. All output
p
2
and
4-32
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 Feed forward scenario, select the Look ahead option for the measured disturbance, and repeat the simulation.
Paper Machine Process Control
Notice that the manipulated variables begin changing in advance of the disturbance. This happens because the look ahe ad option uses known future values of the disturbance when computing its control action. For example, at time t = 0 the controller is using a prediction horizon of 10 co ntrol intervals (20 time units), so it “sees” the impending disturbance at t =10andbegins to prepare for it. The output setpoint tracking improves slightly, but it was already so good that the improvement is insignificant. Also, it’s unlikely that there would be advanced knowledge of a consistency disturbance, so c lear the Look ahead check box for subsequent simulations.
Unmeasured Input Disturbance
To test the response to unmeasured disturbances, define another new scenario called Feedback. Configure it as for Feedforward, but set the measured disturbance, N
1.0 (constant). This simulates a sudden, sustained, unmeasured disturbance occurring at time zero.
Running the simulation should yield results like those in Feedback Scenario: Unmeasured Disturbance Rejection on page 4-34. The two controlled outputs (H
and N2) exhibit relatively small deviations from their setpoin t s (which
2
are zero). The settling time is longer than for the servo respo nse (compare to Servo Response for Unit Step in Headbox Level Setpoint on page 4-31) which is typical.
, to zero (constant), and the unmeasured disturbance, Nw,to
p
4-33
4 Case-Study Examples
Feedback Scenario: Unmeasured Disturbance Rejection
4-34
One factor limiting performance is the c h osen 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).
Effect of Estimator Assumptions
Anotherfactorinfluencingtheresponse to unmeasured disturbances (and model prediction error) is the estimator configuration. The results shown in Feedback Scenario: Unmeasured Disturbance Rejection on page 4-34 are for the default configuration.
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-35. The status message (bottom of figure) indicates that Model Predictiv e Control Toolbox default assumptions are being used.
Paper Machine Process Control
Default Estimator Assumptions: Output Disturbances
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 unme asu re d d isturb an ce in pu t.
Thus, there are a total of three independent, sustained (step-like) disturbances. This allows the con trol ler to eliminate offset in all three measured outputs.
4-35
4 Case-Study Examples
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 N oise 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 wil l give it less weight, relying instead upon the model predictions of that output. T his provides a noise filtering capability.
Inthepapermachineapplication,thedefaultdisturbanceassumptionsare reasonable. It is difficult to improve disturbance rejection significantly by modifying them.

Controlling the Nonlinear Plant in Simulink

It’s good practice to run initial tests using the linear plant model as described in “Servo Response” on page 4-30 and “Unmeasured Input D isturbance” on page 4-33. Such tests don’t introduce prediction error, and are a useful benchmark for more demanding tests with a nonlinear plant model. The controller’s prediction model is linear, so such tests introduce prediction error.
4-36
Paper Machine Headbox Control Using MPC Tools in Simulink
Paper Machine Headbox Control Using MPC Tools in Simulink®on page 4-36 is a Simulink diagra m in which the Model Predictive Control Toolbox controller is being used to regulate the nonlinear paper machine headbox model. The block labeled S-Func tion embodies the nonli near model, which is coded in a file called
mpc_pmmodel.m.
®
Paper Machine Process Control
As shown in the follow ing dialog box, the MP C block references a controller design called MPC1, which was e xported 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-36.
Test, Output Varia bles on page 4-38 shows th e scope display from the “Outputs” block for the setup of Paper Machine Headbox Control Using MPC Tools in Simulink curve is H
, the magenta is N1,andthecyanisN2. Comparing to Feedback
2
®
on page 4-36, i.e., an unmeasured disturbance. The yellow
Scenario: Unmeasured Disturbance Rejectiononpage4-34,theresultsare almost identical, indicating that the effects of nonlinearity and prediction error were insignificant in this case. Simulink
®
Test, Manipulated Variables on page 4-38 shows the corresponding manipulated variable moves (from the “MVs” scope in Paper Machine Headbox Control Using MP C Tools in Simulink
®
on page 4-36) which are smooth yet reasonably fast.
As disturbance size increases, nonlinear effects begin to appear. For a disturbance size of 4, the results are still essentially the same as shown
4-37
4 Case-Study Examples
in Test, Output Variables on page 4-38 and Simulink®Test, Manipulated Variables on page 4-38 (scaled by a factor of 4), but for a disturbance size of 6, the setpoint deviations are relatively larger, and the curve shapes differ (not shown). There are marked qualitative and quantitative d ifferences when the disturbance size is 8. When it is 9, deviations become very large, and the MVs saturate. If such disturbances were likely, the controller would have to be retuned to accommodate them.
4-38
Test, Output Variables
Simulink®Test, Manipulated Variables

Bumpless Transfer in MPC

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 caus e a bump, i.e., large actuator movements.
A Model Predictive Controller must monitor all known plant signals even when it is no t in control of the actuators. This improves its state estimates and allows a bumpless transfer to automatic operation.
A Model Predictive Control Toolbox demo illustrates this behavior. The following figure shows the block diagram.
Bumpless Transfer in MPC
Simulink®Block Diagram for the MPC Bumpless Transfer Demo
The plant is a stable single-input single-output system. Open-Loop Unit Step Response on page 4-40 shows its open-loop unit step response.
4-39
4 Case-Study Examples
Open-Loop Unit Step Response
MPC Block Configuration Settings on page 4-41 shows the MPC block configuration settings for this case. The demo creates the
MPC1 controller
object. Its sampling period is 0.5. For additional design details, see the demo documentation.
4-40
As shown in MPC Block Configuration Settings on page 4-41, the block’s optional input port for externally supplied manipulated variables is selected. This adds the inport labeled
ext.mv to the block (Simulink
®
Block Diagram for the MPC Bumpless Transfer Demo on page 4-39 shows how this is connnected).
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 Demo on page 4-39).
Bumpless Transfer in MPC
MPC Block Configuration Settings
The demo tests the effect o f switching the controller from automatic to manual and back. To simulate this, a Pulse Generator block labeled
signal
sends either one or zero to a switch. When it sends zero, the s ystem is
switching
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.
In both cases the actual plant input feeds back to the controller, as shown in Simulink
®
Block Diagram for the MPC Bumpless Transfer Demo on page 4-39 (unless the plant input saturates at -1 or 1). The controller also monitors the plant ouput at all times. Thus, the controller can update its estimate of the plant state even when in manual.
Thedemoalsoemploystheoptimizationswitchingoption. Whenthesystem switches to manual, a nonzero signal enters the controller’s QP Switch inport, turning off the optimization calculations, thereby reducing computational
4-41
4 Case-Study Examples
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-42, 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.
4-42
Output, Reference and Switching Signal
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.
Simultaneously, the nonzero signal entering the controller’s turns off the optimization calculations and the controller output goes to zero (see Manipulated Varia bl e (Actuator) Adjustments on page 4-43).
Once in manual mode, the operato r commands set the manipulated variable to -0.5 for 10 time units, and then to 0. Output, Reference and Switching Signal on page 4-42 shows the open-loop response betw een times 90 and 180 when the controller is deactivated.
QP Switch inport
Loading...