P. 1
Mpc Gui Manual

Mpc Gui Manual

|Views: 129|Likes:
Published by Surya Budi Widagdo

More info:

Published by: Surya Budi Widagdo on May 17, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

06/02/2011

pdf

text

original

The MPC Graphical User Interface

N. L. Ricker M. Morari A. Bemporad

User’s Guide
Version 1

How to Contact N. L. Ricker:

u
MAIL INTERNET FAX

Dept. of Chemical Engr. Box 351750 University of Washington Seattle, WA 98195-1750

http://weber.u.washington.edu/~control/

E-MAIL

@

ricker@u.washington.edu

The MPC Graphical User Interface © COPYRIGHT 1998 by N. L. Ricker, M. Morari, and A. Bemporad
The software described in this document is covered by the MPC Tools license agreement. The software may be used or copied only under the terms of the license agreement. This manual may be photocopied and reproduced, but no part may be included in any other document without prior written consent from the authors. U.S. GOVERNMENT: If Licensee is acquiring the Programs on behalf of any unit or agency of the U.S. Government, the following shall apply: (a) For units of the Department of Defense: the Government shall have only the rights specified in the license under which the commercial computer software or commercial software documentation was obtained, as set forth in subparagraph (a) of the Rights in Commercial Computer Software or Commercial Software Documentation Clause at DFARS 227.7202-3, therefore the rights set forth herein shall apply; and (b) For any other unit or agency: NOTICE: Notwithstanding any other lease or license agreement that may pertain to, or accompany the delivery of, the computer software and accompanying documentation, the rights of the Government regarding its use, reproduction, and disclosure are as set forth in Clause 52.227-19 (c)(2) of the FAR. MATLAB, Simulink, Handle Graphics, and Real-Time Workshop are registered trademarks and Stateflow and Target Language Compiler are trademarks of The MathWorks, Inc. Other product or brand names are trademarks or registered trademarks of their respective holders.

Printing History: Sept 1998

Online Draft

MPC Graphical User Interface

Contents
Disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . State of Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . In Case of Difficulty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
vi vi vi vi vi

Introduction

1
GUI Philosophy and Overview . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Modeling Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Controller Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Starting the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . System Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Leisurely Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1-3 1-3 1-3 1-4 1-4

MPC Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 Overview: Single-Input, Single-Output (SISO) MPC . . . . . . . . 1-5 Sampling period and sampling instants . . . . . . . . . . . . . . . . 1-7 An MPC sampling instant . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 Prediction and control horizons . . . . . . . . . . . . . . . . . . . . . . . 1-9 Blocking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10 Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11 Choosing the optimization weights . . . . . . . . . . . . . . . . . . . 1-12 Solving the Optimization Problem . . . . . . . . . . . . . . . . . . . . 1-13 Output Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13 Multiple Inputs and Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14

i

MPC Worksheet Basics

2
The Worksheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Parts of the Worksheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 Loading a Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . LTI Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . System Identification Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . MPC Tools Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Unsupported Model Formats . . . . . . . . . . . . . . . . . . . . . . . . . Paper machine headbox example . . . . . . . . . . . . . . . . . . . . . . . . Loading the LTI model of the headbox . . . . . . . . . . . . . . . . . .
2-4 2-4 2-4 2-4 2-4 2-4 2-4 2-4 2-5

Manipulating Icons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 Organizing the Worksheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 Viewing/modifying icon properties . . . . . . . . . . . . . . . . . . . . . . . 2-8 Designing a Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 Simulation – Open Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Simulation Dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step Response – Headbox Example . . . . . . . . . . . . . . . . . . . . . Viewing Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Viewing/Editing Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2-16 2-16 2-17 2-18 2-20

Simulation – Closed-Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22

Using Simulink Models in MPC

3
Loading a Simulink Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Open the Model Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Check Input and Output Signals . . . . . . . . . . . . . . . . . . . . . . . . Load the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3-2 3-2 3-2 3-3

ii

Contents

Specify Signal Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 Set Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 MPC Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 Simulations using Simulink Models . . . . . . . . . . . . . . . . . . . . . 3-8 Using Simulink to Define Inputs and Select Outputs . . . . 3-10 Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12 Specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12 Verifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12

Disturbance Detection and Estimation

4
Disturbance Estimation Goals . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Paper Machine Headbox Example . . . . . . . . . . . . . . . . . . . . . . MPC Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Noise Signal Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Disturbance Estimator for Noisy Signal . . . . . . . . . . . . . . . . . . . Sustained Disturbances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Plant with Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . MPC Design with Default Estimator . . . . . . . . . . . . . . . . . . . . Steady-state Offset in MPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . MPC Design to Eliminate Offset . . . . . . . . . . . . . . . . . . . . . . . .
4-3 4-3 4-3 4-5 4-7 4-13 4-13 4-13 4-14 4-16

General Open-Loop Unstable Plants . . . . . . . . . . . . . . . . . . . 4-18 Theoretical Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-19 One measured output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-19 Multiple measured outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21

iii

Signal Anticipation

5
Working with Plots

6
Plot Editing in MPC – An Example . . . . . . . . . . . . . . . . . . . . . . 6-2 Plot Editing Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 Context Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 The Curve Context Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 The Plot Context Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Paste Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Zoom with Mouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Edit Axis Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Change Title . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Change X-Axis Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Change Y-Axis Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 Import Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 Export Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 Export All . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 Hide/Show Legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 Add/Delete Axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6 Font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6 Editing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6 Text Objects in the MPC GUI . . . . . . . . . . . . . . . . . . . . . . . . . 6-6 TeX Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7 Zooming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7 The Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-10

Worksheet Icons

7
Icon Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2

iv

Contents

Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Export . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Delete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Rename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Icon Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Model Icons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . LTI Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . STEP Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . MDL Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Controller Icons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . LTI Internal Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . STEP Internal Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Result Icons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7-2 7-2 7-3 7-3 7-3 7-4 7-4 7-5 7-6 7-6 7-7 7-8 7-9 7-9

v

Preface
Disclaimer
State of Development
The MPC GUI is in a developmental (beta) stage. It is not an official MathWorks product. It has been tested extensively, but it is likely that some problems remain. Please review all calculations with a critical eye. We will also be improving GUI features in response to your comments.

In Case of Difficulty
This beta version of the GUI is not being supported by The MathWorks. If you encounter a problem, please check the FAQ (see "Updates" below). If that doesn’t help, please send a detailed description by e-mail to N. L. Ricker at the following address:
ricker@u.washington.edu

He would also be happy to have your suggestions for improvements in the usability of the GUI, its documentation, and the MPC Toolbox in general.

Updates
The FAQ and latest beta version of the GUI will be maintained for download at
http://weber.u.washington.edu/~control/LARRY/GUI/index.html

Acknowledgements
Oscar Crisalle provided many detailed comments on the initial version of the GUI. We also appreciate the help of Dominique Bonvin, Jan Maciejowski, Chris Primus, Frank Doyle, Jay Lee, Pascal Gahinet, and Greg Wolodkin.

vi

1
Introduction

GUI Philosophy and Overview . . . . . . . . . . . . 1-2 Modeling Options . . . . . . . . . . . . . . . . . . 1-2 Controller Options . . . . . . . . . . . . . . . . . . 1-2 Starting the GUI . System Requirements Installation . . . . Quick Start . . . . Leisurely Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 1-3 1-3 1-4 1-4

MPC Fundamentals . . . . . . . . . . . . . . . . . 1-5 Overview: Single-Input, Single-Output (SISO) MPC . . . . 1-5 Multiple Inputs and Outputs . . . . . . . . . . . . . . 1-14

1

Introduction

GUI Philosophy and Overview
If you’re an MPC expert who likes to program MATLAB commands you’ll probably want to customize your own applications. Direct use of the MPC commands gives you maximum flexibility and power, and the resulting code runs as efficiently as possible. But if you don’t want to learn all the commands there’s another way: the MPC GUI. It’s designed to help you analyze and simulate the most common plant MPC controller and plant model combinations. It also provides a “worksheet” that helps you keep track of your progress as you test different designs.

Modeling Options
The GUI supports the following model types: • Linear. Either an LTI object (transfer function, state-space, etc. – see the Control Toolbox), or a step-response model. • Nonlinear. A Simulink block diagram.

Controller Options
You can use all of the standard linear MPC design options. If your plant model is nonlinear, you can linearize it to design the controller, then simulate linear MPC of the nonlinear plant.

1-2

Starting the GUI

Starting the GUI
System Requirements
You’ll need the following MATLAB software: • MPC Toolbox for MATLAB Version 5, including the GUI commands (which are currently an add-on to the standard MPC Tools release). • MATLAB Version 5.2 or greater. • Simulink Version 2 or greater. • Control Toolbox.

Installation
1 Make a backup copy of your MPC Tools directory (which should be located

in your MATLAB directory, e.g., MATLAB/toolbox/mpc). This will allow you to restore your original configuration if the GUI installation interferes in some unexpected way.
2 Download the latest version of the GUI from

http://weber.u.washington.edu/~control/LARRY/GUI/index.html

It’s a ZIP archive. Extract the contents using one of the many available utility programs (e.g., WinZip). This should create a new gui directory within the mpc directory. It should also add and update files in your mpccmds and mpcdemos directories.

IMPORTANT: The gui ZIP archive is not a full version of MPC Tools. You must have existing mpc/mpccmds and mpc/mpcdemos directories. The files from the archive only update these directories.

3 Set your MATLAB Path so the new mpc/gui directory is included. Verify

that the original mpc/mpccmds and mpc/mpcdemos directories are also on the path.

1-3

1

Introduction

4 Type “mpc” in the MATLAB Command window. You should see the MPC

Worksheet.
5 If it doesn’t work or you have other problems, see section In Case of

Difficulty in the preface to this document.

Quick Start
1 Type “mpc” in the command window and wait for the MPC Worksheet to

appear.
2 Click on the “Help” button (just to the right of “Models” near the top of the

window). The resulting Help window will contain a brief tutorial example.
3 Follow the steps in the tutorial. 4 Try it with your own applications!

Leisurely Start
The following sections of this document provide tutorial examples and additional details. If possible, work through the steps in MATLAB as you read.

1-4

MPC Fundamentals

MPC Fundamentals
This section reviews MPC concepts and defines key terms. If you’re already familiar with MPC you may prefer to read Chapter 2, “MPC Worksheet Basics” next.

Overview: Single-Input, Single-Output (SISO) MPC
Figure 1-1 shows a situation in which MPC is trying to hold a single variable, y , at a target value, r, by adjusting the “manipulated variable” (or “actuator”) u. See Table 1-1 for a brief description of the signals appearing in Figure 1-1. The box labeled “plant” is the real process or mechanism that produces y . It responds to changes in u as well as to two types of disturbance signals: measured, v, and unmeasured, d. (Some applications have unmeasured disturbances only; the v signal is optional.) The unmeasured disturbance represents the usual mysterious events that upset plant operation, causing variations in y . The only sign that such an event has occurred is a change in the measured output, y.

Measured Disturbance Noise

v
Setpoint

v MPC
Actuator

z Plant y
Plant Output

r y

u d

+ +

y

Unmeasured Disturbance

Measured Output (Controlled Variable) Figure 1-1 Block diagram of a single-input, single-output MPC application.

1-5

1

Introduction

Table 1-1 Summary of MPC signals (see also Figure 1-1). Symbol Description

d

Unmeasured disturbance. A disturbance unknown to MPC that affects the plant output. MPC provides feedback compensation for such disturbances. Setpoint (or reference signal). The target value for the controlled variable. Actuator (or manipulated variable). The signal MPC adjusts in order to achieve its control objectives. Measured disturbance (optional). MPC feedforward compensation adjusts for such disturbances as they occur to minimize their impact on the controlled variable. Controlled variable (or plant output). The signal to be held at the setpoint. This is the “true” value, uncorrupted by measurement noise. Measurement of the controlled variable. Used to estimate the true value, y . Measurement noise. Represents electrical noise, sampling errors, drifting calibration, and other effects that reduce the accuracy of the measurement.

r u v

y

y z

The measured disturbance also affects y . The MPC block includes models of the way in which v and u affect y (symbolically, v → y and u → y ). It uses this information to calculate u adjustments that keep y at its setpoint in spite of the (known) disturbance. This calculation considers the effect of any known constraints on the adjustments (e.g., an actuator at its upper or lower bound). If the models are accurate and the plant responds quickly to u, this “feedforward” compensation counteracts the effect of v perfectly.

1-6

MPC Fundamentals

NOTE: One may also specify bounds on y . These constraint-handling properties are a distinguishing feature of MPC and can be particularly valuable when one has multiple control objectives to be achieved via multiple adjustments.

In reality, however, model imperfections, plant limitations, and unmeasured disturbances cause the measurement, y, to deviate from its expected value. Thus, MPC uses the output measurement and a “disturbance model” ( d → y ) to predict future changes in y . It then uses its u → y model to calculate appropriate adjustments (a form of “feedback” compensation). This calculation also considers the known constraints. Various types of “noise” can corrupt the measurement. The signal z in Figure 1-1 represents such effects. They may vary randomly about a zero mean or exhibit a non-zero, drifting bias. MPC uses a z → y model in combination with its d → y model to remove the estimated noise component of the measurement (“filtering”). The above feedforward/feedback actions are MPC’s “regulator” mode. MPC also has a “servo” mode, i.e., it adjusts u such that y tracks a time-varying setpoint. The tracking accuracy depends on the plant characteristics (including constraints), the accuracy of the u → y model, and whether or not future setpoint variations can be anticipated, i.e., known in advance (11ref).

Details: SISO case
Sampling period and sampling instants
MPC operates at discrete intervals of ∆t time units, the “sampling period.” Suppose that MPC starts at time t = 0. The “sampling instants” are the times at which MPC adjusts the manipulated variable, u. They are integer multiples of the sampling period: 0,∆t, 2∆t, 3∆t, ..., k∆t, where the integer index, k, represents the current sampling instant.

1-7

1

Introduction

Past
y max
(a)

Future

r

Setpoint
Measured Estimated

y

min

Prediction Horizon, P

u max
(b)

Control Horizon

Past Moves Planned Moves

u

min
-4 -3 -2 -1 k +1 +2 +3 +4 +5 +6 +7 +8 +9

Sampling Instant
Figure 1-2 The MPC problem at the kth sampling instant.

An MPC sampling instant
Figure 1-2 shows the state of a hypothetical SISO MPC system which has been operating for some time; k is the current sampling instant. The current measured output, yk, and previous measurements, yk-1, yk-2, ..., are known and are the filled circles in Figure 1-2 (a). The current measured disturbance, dk, and its past values are also known (not shown).

1-8

MPC Fundamentals

Figure 1-2 (b) shows MPC’s previous “moves,” uk-41, ..., uk-1, as filled circles. As is usually the case, a “zero-order hold” receives each move from MPC and sends that value to the plant continuously until the next sampling instant – note the resulting step-wise variations of Figure 1-2 (b). MPC must now calculate the current move, uk. It does so in two phases:
1 Estimation. In order to make an intelligent move, MPC needs to know the

current state of the system. This includes the true value of the controlled variable, y k , and any internal plant variables that influence the future trend, y k + 1 , ..., y k + P . To accomplish this MPC uses all past and current measurements and the models u → y , d → y , w → y , and z → y . For details, please see Chapter 4, “Disturbance Detection and Estimation”.
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, where P (a finite integer ≥ 1) is the “prediction horizon” – see Figure 1-2 (a). MPC then computes the M moves uk, uk+1, ... uk+M-1, where M ( ≥ 1, ≤ P) is the “control horizon” – see Figure 1-2 (b). In our hypothetical example, P = 9 and M = 4. Suppose that the optimal sequence of moves is the series of four open circles in Figure 1-2 (b). MPC’s model predicts that this will result in the output sequence shown as the nine open circles in Figure 1-2 (a). These moves are optimal in the sense that no constraints are violated and the outputs track the setpoint “closely.” See 11ref for a detailed definition of optimality. MPC sends only the move uk to the plant. The plant operates with this input until MPC’s next sampling instant, ∆t time units later. MPC then obtains a new set of measurements and revises completely the plan it had formulated at the previous sampling instant, thus compensating for model error and unknown disturbances.

Prediction and control horizons
One might wonder why MPC bothers to optimize over P sampling periods into the future and calculate M moves when it discards all but the first move. Indeed, under certain conditions MPC gives identical results for P = M = 1 as

1-9

1

Introduction

it does for P = M = ∞. More often, however, the horizons have an important impact. Some examples are: • Constraints. MPC’s current move, uk, depends on future constraints, i.e., MPC plans ahead to avoid future constraint violations. • Delays in the plant. Suppose that the plant includes a pure time delay; MPC’s current move has no effect until D sampling periods into the future. Then we need P ≥ D and M ≤ P − D so that MPC can include the effect of each contemplated move in its optimization calculations. • Other nonminimum phase plants. Consider a SISO plant with an inverse-response, e.g., its unit-step response is a decrease below the initial condition followed by an increase to a final value above the initial condition. Experience suggests the following rules of thumb:
1 Choose the MPC sampling period 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 P to be the number of sampling periods used in step 1. 3 Use a relatively small M, e.g., 3-5.

The resulting MPC performance will usually be insensitive to minor adjustments in these M and P values, and further “tuning” should not be necessary. If performance is poor, it is probably due to other factors, such as modeling errors.

Blocking
In Figure 1-2 (b), M = 4 and P= 9, and MPC is optimizing the first M moves of the prediction horizon, after which the manipulated variable remains constant for P – M = 5 sampling instants. Figure 1-3 shows an alternative “blocked” strategy – again with M = 4 – in which the first planned move occurs at sampling instant k, the next at k+2, the next at k+4, and the final at k+6. A “block” is one or more successive sampling periods during which the manipulated variable is constant. The “block duration” is the number of sampling periods in a block. In Figure 1-3 the block durations are 2, 2, 2, and 3. (Their sum must equal P.)

1-10

MPC Fundamentals

u max

Past Moves Planned Moves

u

min
-4 -3 -2 -1 k +1 +2 +3 +4 +5 +6 +7 +8 +9

Sampling Instant
Figure 1-3 Example of blocking with M = [2, 2, 2, 3].

As for the default (unblocked) mode, only the current move, uk, actually goes to the plant, and MPC repeats the optimization of M moves at its next sampling instant. Thus, the signal going to the plant actually varies every ∆t time units. So why use blocking? When P >> M (as is generally recommended), and all M moves are at the beginning of the horizon, the moves tend to be larger (because all but the final move last just one sampling period). Blocking often leads to smoother adjustments, all other things being equal.

Optimization
For a SISO plant, MPC determines its moves by solving the following optimization problem (formulated for the kth sampling instant): Min u k, …, u k + P – 1 such that ˆ y k + i = f ( uk, …, u k + i – 1 )
(1-2)
P

∑ [w
i=1

y

u ˆ ( r k + i – y k + i ) + w ( ∆u k + i – 1 ) ]

2

2

(1-1)

1-11

1

Introduction

u y

min

≤ uk + i – 1 ≤ u

max

∀i = 1, P

(1-3) (1-4) (1-5)
y

min

max ˆ ≤ yk + i ≤ y ∀i = 1, P max

∆u k + i – 1 ≤ ∆u

∀i = 1, P

where ∆u j = u j – u j – 1 is the adjustment at sampling instant j, and w and u w are non-negative “weights.” Equation (1-2) is the model by which MPC predicts the controlled variable at ˆ instant k+i. In standard MPC, y k + i is a linear function of the adjustments u k, …, u k + i – 1 . ˆ Note: The prediction y k + i is also a function of known and estimated disturbances, but these effects are constant, i.e., independent of the adjustments. They are implicit in Equation (1-2).

Equations (1-3) – (1-5) are optional. They specify the bounds on the manipulated variable, the controlled variable, and the change in the manipulated variable. When P > M (the usual case), there are also P – M equality constraints of the form u k + j = u k + j – 1 , i.e., to hold the manipulated variables constant for a specified sequence of sampling instants. This depends on the specified block durations. For example, the situation of Figure 1-3 would have u k + 1 = u k , u k + 3 = u k + 2 , etc.

Choosing the optimization weights
The main difficulty in an MPC design (other than modeling) is the selection of y u the weights w and w in eq. (1-1). Trial-and-error tuning is often needed. The following guidelines may be helpful: • A positive value of w penalizes predicted deviations of the controlled variable from its setpoint. The larger this weight, the more closely MPC tries y to track the setpoint. If w = 0 , MPC ignores the setpoint. • A positive value of w penalizes planned changes in the manipulated variable. A moderate value makes the controller “cautious,” which usually
u y

1-12

MPC Fundamentals

increases its “robustness” (making it less sensitive to modeling errors – a positive effect). A large value makes it “sluggish,” however. In the extreme u as w goes to infinity, MPC ignores deviations of the controlled variable from its setpoint. • In a SISO problem, only the ratio of w to w matters. A good strategy is to fix one of them at unity and vary the other, testing the performance in simulations to obtain the desired trade-off between fast setpoint tracking (large ratio) and cautious adjustments of the manipulated variable (small y u ratio). (By default, the MPC GUI sets w = 1, w = 0.1 .) • MPC does whatever it must in order to satisfy any “hard” inequality y u constraints, eqs. (1-3)–(1-5). The values of w and w become less important when constraints are encountered.
y u

Solving the Optimization Problem
The objective function, eq. (1-1), is quadratic, and the standard MPC formulation uses linear constraints, eqs. (1-2)–(1-5). This is a “quadratic programming” problem. There are M “decision variables,” the moves. If none of the inequality constraints are binding, the QP has an analytical solution. In general, however, MPC uses an iterative procedure. If the QP is feasible, i.e., at least one set of moves satisfies all the constraints, the optimum will be obtained in a finite number of iterations. This can be time-consuming, especially for the MIMO case in the next section. If this is limiting in your application, consider reducing P and/or M.

Output Constraints
Output constraints, eq. (1-4), should be used only when it is essential to hold the output within its bounds
min

NOTE: to turn off an output constraint set y

= – ∞ and/or y

max

= ∞.

Such constraints can increase the computational effort significantly. More importantly, they may make the problem infeasible. Suppose, for example, that a large disturbance drives yk above its upper bound. If there are bounds on uk, it may be impossible to bring the output back within the allowed region quickly enough to satisfy eq. (1-4).

1-13

1

Introduction

An alternative is to replace eq. (1-4) with “soft” constraints. The mpc tools functions allow this, but for the moment the GUI uses “hard” constraints only.

Multiple Inputs and Outputs
We now consider the signals of Figure 1-1 to be vectors. Suppose that there are n y ≥ 1 controlled outputs, all measured, i.e., y k = [ y 1k, y 2k, …, y n k ]
y

(1-6)

Signals zk and y k also have ny elements. There are n u ≥ 1 manipulated variables u k = [ u 1k, u 2k, …, u n k ]
u

(1-7)

and disturbances dk and vk have n d ≥ 0 and n v ≥ 0 elements, respectively. (As discussed in “Theoretical Background” in Chapter 4, the MPC GUI assumes n d = n y .) Much of the previous discussion carries over to the multi-input, multi-output (MIMO) case. The same horizons (P, M) and block durations apply regardless of the number of controlled and manipulated variables. The main difference is in the optimization problem. At the kth sampling period, u k, …, u k + P – 1 ∑ ∑ such that ˆ y j, k + i = f ( u k, …, u k + i – 1 ) ∀j = 1, n y ul yj
min

Min

P

ny y w j ( r j, k + i

nu

ˆ – y j, k + i ) +

2

∑ wl ( ∆ul, k + i – 1 )
u l=1

2

(1-8)

i=1 j=1

(1-9) (1-10) (1-11) (1-12)

≤ u l, k + i – 1 ≤ u l

max

∀i = 1, P and l = 1, n u

min

max ˆ ≤ y j, k + i ≤ y j ∀i = 1, P and j = 1, n y max

∆u l, k + i – 1 ≤ u l

∀i = 1, P and l = 1, n u

where ∆u lj = u lj – u l, j – 1 is the adjustment of the lth manipulated variable at y u the jth sampling instant, and w j and w l are non-negative weights.

1-14

MPC Fundamentals

There are n y + n u weights to specify. The relative magnitudes of the weights are critical; we can again set one to unity and tune the rest. Unfortunately, a change in a single weight can affect the performance of all the controlled and manipulated variables, so tuning can be more delicate than in the SISO case. Some general guidelines are: • If ykj must be held close to its setpoint, the corresponding weight, w j , should be relatively large. If, setpoint tracking is unimportant for this output, its weight should be small, perhaps zero. • If you would prefer that ukj not change rapidly, make w j relatively large. • For “non-square” problems, if n u > n y , at least n u – n y of the input weights, u w j , must be non-zero so that the QP solution is unique. • For non-square problems with n u < n y , it is usually impossible to drive all ny outputs to setpoints, i.e., there will be steady-state offset unless n y – n u of the output weights are zero. • Keep the scaling of the variables in mind as for the SISO case.
u y

1-15

1

Introduction

1-16

2
MPC Worksheet Basics

The Worksheet . . . . . . . . . . . . . . . . . . . 2-2 Parts of the Worksheet . . . . . . . . . . . . . . . . 2-3 Loading a Model . . . . . . . . . . . . . . . . . . 2-4 Creating the Model . . . . . . . . . . . . . . . . . . 2-4 Paper machine headbox example . . . . . . . . . . . . 2-4 Manipulating Icons . . . . . . . . . . . . . . . . . 2-8 Organizing the Worksheet . . . . . . . . . . . . . . . 2-8 Viewing/modifying icon properties . . . . . . . . . . . . 2-8 Designing a Controller . . . . . . . . . . . . . . . 2-11 Simulation – Open Loop . . . . Simulation Dialog . . . . . . . Step Response – Headbox Example Viewing Results . . . . . . . . Viewing/Editing Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16 . 2-16 . 2-17 . 2-18 . 2-20

Simulation – Closed-Loop . . . . . . . . . . . . . . 2-22

2

MPC Worksheet Basics

The Worksheet
When you start the GUI you should see a fresh MPC Worksheet window (see Figure 2-1).

MPC Model

Overflow

Plant

Controller

Figure 2-1 A new MPC Worksheet window.

A typical GUI session requires you to
1 Load a plant model into the worksheet. The model can be in any of these

formats: step response, transfer function, state space, or Simulink (MDL) block diagram.
2 Test the model by running one or more open-loop simulations, i.e., with no

controller active. Plot responses to verify that the model behaves as you’d expect.

2-2

The Worksheet

3 Use the model in an MPC design to generate a controller. 4 Run simulations to test the closed-loop combination of plant and controller.

Each step creates one or more results. The Worksheet is like a pallet; it helps you organize your results so you can keep track of progress, try alternatives, etc.

Parts of the Worksheet
The worksheet has three main sections (groups of grey rectangles): • Models, the nine rectangles just below the word “Models.” When you load a model, a corresponding icon appears in one of the empty rectangles. • Controllers, the nine rectangles just below “Controllers.” When you design a controller, its icon appears here. • Results, the 14 rectangles at the bottom. When you run a simulation, a result icon appears here. There are also four special worksheet locations: • Plant Model. A white box. Drag a model icon here to designate it as “the plant” for a subsequent simulation. • MPC Model. A white box. The model icon you drag here forms the basis for MPC controller design. • Controller. A white box. Drag a controller icon here to designate it as “the controller” for a subsequent closed-loop simulation. • Overflow. A trashcan icon. Whenever your worksheet is getting full or an icon is no longer useful, drag it here. It can hold any number of icons, and you can move them back to the main Worksheet when needed.

2-3

2

MPC Worksheet Basics

Loading a Model
Creating the Model
MATLAB includes a variety of powerful model-building tools. The MPC GUI assumes that you have used one of them to create your model.

LTI Model
If your model is linear and time-invariant (LTI), the LTI Object in the Control Toolbox is a convenient representation. You can easily define linear transfer function (single or multiple input/output) and state-space models. They can be either continuous-time or discrete-time.

Simulink
Simulink provides a graphical environment with both linear and nonlinear building blocks. Models can be very complex. This is the most general approach.

System Identification Toolbox
Consider the System Identification Tools if you have data from plant tests and wish to determine an appropriate model. It handles linear models only, however.

MPC Tools Models
The GUI accepts models in the “Step” and “Mod” formats described in the MPC Tools manual.

Unsupported Model Formats
Other modeling tools (e.g., Neural Nets, Fuzzy Logic) cannot be used directly. It may be possible to convert them to one of the supported formats.

Paper machine headbox example
Consider the Simulink block diagram of a paper machine headbox shown in Figure 2-2. We’ll use this as an illustrative example. (See additional discussion and MPC design for this process in Section 3.4 of the MPC Tools manual).

2-4

Loading a Model

NOTE: Once you’ve started the GUI, you may notice several new variables in your main MATLAB workspace (PapMach, PapMachMod, and PapMachStep). These are the LTI, Mod, and Step representations of the paper machine headbox. The GUI creates them automatically for use in tutorial examples.

1 Gp 3 Np 1 2 Gw 4 Nw Mux Demux Mux papmach S−Function Demux H2 3 N2 2 N1

Figure 2-2 Paper machine headbox schematic.

The model includes four inputs and three outputs. The first two inputs (Gpand Gw) are “manipulated variables,” i.e., actuators that MPC can use to provide feedback/feedforward compensation. The third (Np) is an independent “measured disturbance” input. MPC can provide feedforward compensation for this type of input. The fourth input is an “unmeasured disturbance.” It represents an unknown, independent input for which feedforward compensation is impossible. The control objective is to hold outputs 1 and 3 (H2 and N2) at specified setpoints. Output 2 (N1) is used for disturbance detection only, and need not be held at a setpoint.

Loading the LTI model of the headbox
To load the LTI representation of the paper machine headbox, click the Load button in the Worksheet’s model area. MPC displays the dialog shown in Figure 2-3.

2-5

2

MPC Worksheet Basics

First indicate the type of model you wish to load by clicking the appropriate radio button on the left-hand side of the dialog (LTI in this case, which is the default). Then note the list of models on the right This will include any model of the selected type that is currently defined in your main MATLAB workspace. The GUI automatically creates the one called PapMach; if you have created other LTI models, they will appear here too. Select PapMach by clicking on it. Note that its name appears in the edit box labeled “Load on Worksheet As.” This is the name the model will have when loaded into the Worksheet. You could modify it at this point, but just click the Load button.

Figure 2-3 Model loading dialog.

The model loading dialog disappears, and an LTI model icon named “PapMach” appears in the MPC Worksheet (see Figure 2-4).

2-6

Loading a Model

LTI
PapMach

Figure 2-4 MPC Worksheet with new PapMach LTI model icon.

2-7

2

MPC Worksheet Basics

Manipulating Icons
Organizing the Worksheet
If you have several model icons, you may wish to change the order in which they appear on the Worksheet. Use the mouse to drag a model icon to any unused box in the model area. You can also drag model icons to the special “Plant,” “MPC Model,” and “Overflow” areas. None of the other areas (e.g., “Controllers” or “Results”) are valid locations for model icons, so the GUI keeps you from dragging them there.

Viewing/modifying icon properties
You may wish to view or modify the properties of an icon. You have two options: • Double-click on the icon. • Right-click on the icon to access its context menu (see “Icon Menus” in Chapter 7) then click on the “Properties” entry. For PapMach, MPC displays the dialog shown in Figure 2-5. The right-hand side summarizes the model’s input and output signals and their initial conditions. All four inputs are currently manipulated variables (MVs) by default. Only the first two should be MVs, however, (see page 2-5) so we need to change the definitions of inputs 3 and 4.
1 Click to select input 3 in the list on the upper left of the dialog (below

“Input”). The signal name in the edit box changes to Np.
2 Click the MD radio button. The “Input Summary” display changes. Input 3

is now “MD” and there are a total of 3 MVs and 1 MD.
3 Similarly, change input 4 to an unmeasured disturbance (UD).

The default assignment (CV) is correct for the outputs, so we have no further use of this dialog for now. In general, however, you could use it to • Change the name of one or more signals. • Change the model name. • Enter notes that record special features of the model.

2-8

Manipulating Icons

Input Summary

Output Summary

Figure 2-5 Model View/Modify dialog for PapMach icon.

• Define initial conditions. The zeros shown in Figure 2-5’s summary boxes are the default for linear models. If you are loading a Simulink model, you have to option to use non-zero initial conditions (see “Initial Conditions” in Chapter 3). • Set the sampling period. The PapMach model’s sampling period of zero indicates that it is a continuous-time system. Changing the sampling period would convert the model to a discrete-time system.

2-9

2

MPC Worksheet Basics

Instead, click the “Done” button. Since you’ve changed the model, MPC asks whether you wish to replace the existing model with the new version or create a new model. Click the “YES, Replace” button. MPC returns to the Worksheet view. It should still contain the PapMach model only, as shown in Figure 2-4.

2-10

Designing a Controller

Designing a Controller
Drag the PapMach icon to the “MPC Model” box. This activates the “MPC Design” button. Click it to obtain the dialog of Figure 2-6.

MV Weights Summary

Output Weights Summary

Figure 2-6 MPC design dialog – initial state for PapMach model.

As an example, let’s repeat the design described in Section 3.4 of the MPC Tools manual. • Prediction Horizon, P. This is the number of sampling periods over which MPC optimizes the MVs. Set P = 10 for this example. • Number of Moves, M. This is the number of times the MVs can change within the prediction horizon during each optimization. M must be less than or equal to P (or ≤ 10 if P > 10). Use M = 3 in this example.

2-11

2

MPC Worksheet Basics

NOTE: The restriction M ≤ 10 is a limitation of the GUI, not of MPC in general. Larger values are rarely needed, however, and you can block moves to spread their effect over a longer time period (see below).

• Sampling Period, ∆t. MPC is a discrete-time controller, so you must specify a sampling period. The choice depends on the process dynamic response characteristics. Use ∆t = 2 in this case. • Disturbance Estimator. This option adjusts the way MPC responds to unmeasured disturbances. See Chapter 4, “Disturbance Detection and Estimation” for details. Leave the box unchecked, i.e., use the default estimator. • Block Moves. Blocking spreads out the moves rather than making them all at the beginning of the prediction horizon. Clicking on the “Block Moves” checkbox brings up the dialog shown in Figure 2-7.

0

1

2

3

4

5

6

7

8

9

10

Figure 2-7 Blocking dialog – initial state for P = 10, M = 3.

The upper half of Figure 2-7 is a graphical representation of the current move locations. The numbers 0–10 represent each sampling instant in the prediction horizon, where 0 is the beginning and P = 10 is the end. MPC can change the MVs at any of these times. Recall that we are allowing a total of M = 3 moves in this example. The first move always occurs at the beginning of the horizon; you can’t relocate it. The

2-12

Designing a Controller

blue bars show when the remaining two moves will occur. The default is to make all M moves at the beginning of the horizon, as shown in Figure 2-7. The bottom half of the dialog is a numerical representation of the same information. It shows the duration of each move. The default sets the first M-1 moves to a duration of 1. The remaining move lasts until the end of the prediction horizon. To block the moves you either drag the blue bars to new locations or edit the move duration boxes. (You can’t edit the right-most, grayed-out box. MPC calculates it automatically.) For this example, drag the bars to locations 2 and 5. The dialog should then appear as in Figure 2-8. When you’ve finished, click the “Done” button.

0

1

2

3

4

5

6

7

8

9

10

Figure 2-8 Blocking dialog – final state for P = 10, M = 3.

• Anticipation. Use this checkbox to indicate whether MPC will “anticipate” changes in a setpoint or measured disturbance. For example, suppose you know that a setpoint change or disturbance will occur at a given time in the future. If the process response is sluggish and you want the process to track the setpoint accurately, you need to begin adjusting the MVs before the setpoint actually changes. See Chapter 5, “Signal Anticipation” for details. For now, leave this box in the default (unchecked) state. • Weighting. This allows you to prioritize your control objectives. You can specify weights for both inputs and outputs. A non-zero input weight

2-13

2

MPC Worksheet Basics

penalizes moves in that input, which usually smooths the MV variations. A non-zero output weight penalizes deviations of that output from its setpoint. By default, MPC assigns equal (unity) weights to all outputs, and weights of 0.1 to all MVs. The summary boxes in Figure 2-6 show the current values. The choice depends on your control objectives, the scaling of the variables, and robustness considerations. It often requires trial-and-error adjustment. In the present case, we have only two MVs, so it’s impossible to hold all three outputs at independent setpoints. If we were to leave the output weights as-is, MPC would try to do just that. The result would be a compromise in which none of the outputs would go exactly to its setpoint. Recall that our second output (N1) is measured for diagnostic purposes only. It doesn’t need to be controlled to a setpoint. We indicate this by setting its weight to zero. Use the popup menu (in the “Output” row under the “Description” heading) to select output signal N1. Then use the edit box (to the right of the popup) to change the weight to zero. The change should appear in the “Output Weights Summary” display. (You may have to push the “Enter” key or click the mouse to let MATLAB know that you’re done editing the weight.) • Constraints. You can specify bounds for each MV and output. You can also specify a maximum rate-of-change for each MV. The latter limits the absolute value of the change in an MV from one sampling period to the next. MPC optimizes the MVs such that you get the best performance (considering the MV and output weights and constraints. If one of the MVs is at a bound, MPC may use a very different strategy than it would if all MVs were free to vary. In this sense the control action can be nonlinear. To see a summary of all the MV constraints, right-click in the MV summary box. A context menu appears. You can use it to display any of the three MV constraint types, or switch back to the MV weight display. Similarly, if you right-click in the Output summary box, you can view the output constraints and weights. Use the default constraints for this example. • Controller Name. This edit box lets you specify the controller icon’s name. Use the default, which is the model name. • Notes. You will usually be testing several different controllers. To minimize confusion it’s good practice to note each controller’s key features here, i.e., how it differs from the others you are testing. But leave it blank for now.

2-14

Designing a Controller

When you’ve finished with all of the above specifications, the MPC Design dialog should appear as in Figure 2-9. Click the “Done” button. A new icon named “PapMach” should appear in the “Controllers” area of the Worksheet. The icon type is “LMPC,” signifying that it is a linear MPC design (the only possibility in the current version).

MV Weights Summary

Output Weights Summary

Figure 2-9 MPC Design dialog for PapMach – final state.

2-15

2

MPC Worksheet Basics

Simulation – Open Loop
Open-loop simulation allows you to test a model’s dynamic response when feedback control is absent.

Simulation Dialog
On the MPC Worksheet, drag the LTI PapMach icon (in the “Models” area) to the special “Plant” box. This activates the “Run Simulation” button. Click it to obtain the dialog of Figure 2-10. The “Open Loop” radio button is selected and the “Closed Loop” button is inactive. This will be the case whenever the Worksheet’s special “Controller” box is empty.

Input Summary

Noise Summary

Figure 2-10 Simulation dialog window for PapMach model – open-loop case.

In an open-loop simulation you may specify any input, regardless of type (MV, MD, or UD). The “Input Summary” area of Figure 2-10 displays the current status of each. Possibilities are:

2-16

Simulation – Open Loop

• Constant (Abbreviation: Cons). The input stays at a specified constant value for the entire simulation. Figure 2-10 shows that all four inputs default to a constant value of zero. • Step. At a specified “Start Time” the input changes instantly from a given “Initial Value” to a specified “Final Value.” • Ramp. The input begins at a specified “Initial Value.” At a given “Start Time” it begins to increase (or decrease) linearly at a constant “Rate.” • Sine. The input varies sinusoidally with a specified “Mean,” “Amplitude,” “Period,” and “Phase.” • File. MPC obtains the input signal from a specified data file. This allows you to define an arbitrary input.

Step Response – Headbox Example
Let’s test PapMach’s response to a unit-step increase in Gw. In the MPC Simulation dialog, use the “Plant Inputs” popup menu to select the Gw signal. Then click the “Specify” button. In the resulting dialog click the “Step” radio button. Then set the “Start Time” to 2. Use the defaults for the “Initial Value” and “Final Value.” The dialog should then show the specified signal, as in Figure 2-11 (depending on your computer’s operating system, you may need to push the “Enter” key or click the mouse to indicate that you’ve finished entering the Start Time).

2-17

2

MPC Worksheet Basics

Signal = Gw, 1

Type = MV

0.8

0.6

0.4

0.2

0

0

1

2

3

4

5 Time

6

7

8

9

10

Figure 2-11 Specifying a unit-step increase for PapMach input Gw.

When satisfied, click the “Done” button to go back to the MPC Simulation window. The “Input Summary” display should show the new definition of Gw. At this point you could use the same approach to specify other inputs or add noise to one or more outputs. Instead, click the “Run” button to start the simulation. A status message (“Simulation Running”) appears.

Viewing Results
After a brief wait you should see four plot windows. The one in front shows the output responses (see Figure 2-12). Note the inverse response of output N 2. The

2-18

Simulation – Open Loop

other windows are plots of the inputs, which are not very interesting in this case.

H2 1 0 −0.5 0.5 −1 0 0 5 Time N2 0.5 0 −0.5 −1 0 5 Time 10 10 −1.5 0

N1

5 Time

10

Figure 2-12 PapMach open-loop responses for unit step in Gw.

NOTE:

You can use the Worksheet’s MPC/Options menu to suppress plotting of selected signal types.

Examine each plot window, then close it. Observe that the Worksheet now contains a “result” icon (see Figure 2-13). The icon type is “OLSIM,” indicating that it was generated by an open-loop simulation. The name “PapMach” has been assigned by default. (You can change it by right-clicking on the icon. See “Rename” on page 7-3.)

2-19

2

MPC Worksheet Basics

LTI
PapMach

LMPC
PapMach

LTI
PapMach MPC Model

LTI
PapMach Plant

Overflow

Controller

OLSIM
PapMach

Figure 2-13 Worksheet after open-loop simulation of PapMach.

Once results are in the Worksheet, you can review them whenever you wish. Try double-clicking on the PapMach result icon now. The plots should re-appear. Close them, then try right-clicking on the icon. A context menu appears (see “Icon Menus” on page 7-2 for details on each menu item). If you were to select “Properties,” MPC would re-plot the results.

Viewing/Editing Notes
If you were to select “Notes,” you would see a window – similar to Figure 2-14 – summarizing the simulation conditions. If you had defined any notes for the

2-20

Simulation – Open Loop

LTI/PapMach model icon, those would appear here too. You can edit the note contents to make them more informative, then save the edited notes in the icon. If you were to select the “Export” menu entry, MPC would save all the results as a MATLAB structure variable in your main workspace. You could then use the information in another code, “Import” it into another Worksheet, etc.

Figure 2-14 Notes display window for OLSIM/PapMach icon.

NOTE: When the notes are too extensive to fit in the available display space (which is not the case in Figure 2-14) the notes appear in a “list box” with scroll bars, and the “Save” button in Figure 2-14 becomes an “Edit” button. If you wish to edit such notes you must first push this button.

2-21

2

MPC Worksheet Basics

Simulation – Closed-Loop
Now let’s see how well MPC works for this plant. On the Worksheet, drag the LMPC PapMach controller icon (in the “Controllers” area) to the special “Controller” box. Then click the “Run Simulation” button. When the MPC Simulation dialog appears, make sure the “Closed Loop” radio button is on (see Figure 2-15). You are no longer allowed to specify the first two inputs. These MVs will be determined by MPC. Another difference (relative to the open-loop case) is that you can specify a constant or time-varying setpoint for each output. Increase the “Run Duration” to 20. Then click the Setpoint “Specify” button and define a unit-step increase in the setpoint of H2 starting at time = 2 (follow the same procedure you used to specify Gw in the open-loop case). When you’ve finished, the MPC Simulation dialog should appear as in Figure 2-15. (All signals other than the H2 setpoint are at their defaults.) Click the “Run” button on the Simulation dialog. A progress window appears to show you how much longer the simulation will take. When it finishes, MPC attempts to store the results in the Worksheet.

Noise Summary

Setpoint Summary

Figure 2-15 MPC Simulation dialog – Closed-loop.

2-22

Simulation – Closed-Loop

Since you’ve already created a result icon named “PapMach,” MPC asks whether you wish to replace it or create a new icon. Respond by clicking the “Rename” button. A “Results Storage” dialog appears. It lists the results you’ve already created (PapMach, in this case). In the edit box at the bottom, enter a new name, such as PapMachCL. Then click the “Store” button. The closed-loop response plots should appear. Also note the new Worksheet icon.

H2 1.5 1 0.5 0 0 10 Time N2 0.5 Setpoint Output 20 1 0 −1 −2 0

N1

Setpoint Output 10 Time 20

0 Setpoint Output 10 Time 20

−0.5 0

Figure 2-16 Closed-loop responses for the PapMach outputs.

Figure 2-16 shows the output response plots. Note that

2-23

2

MPC Worksheet Basics

• MPC plots each setpoint and the corresponding output response. It adds a legend to indicate which curve is the setpoint. If the legend obscures something of interest, you can drag it to another location. • The controller sampling period is ∆t = 2. MPC calculates setpoints and outputs at the sampling instants only. It joins these points by straight lines in the plots. In general, this is only an approximation of the behavior of the signal between the sampling instants. For example, the H2 setpoint appears to ramp between t = 0 and t = 2, but it actually varies step-wise at t = 2. • MPC sacrifices control of the second output (N1) in order to bring the other two to their setpoints. Recall that this was one of our MPC design goals. • There is some interaction, i.e., the change in H2 causes a disturbance in N2. Whether the degree of interaction is acceptable is application-specific. The inverse-response behavior shown in Figure 2-12 limits setpoint-tracking accuracy you can achieve in this case. You could experiment with other controller settings, but performance is unlikely to improve significantly. • The MPC plotting function provides a lot of flexibility. For example, if you’d rather have each output appear by itself in a larger format, you could select the 1x1 “Layout” option (using the popup menu on the lower-right of the output plot). You could then use the “Next” and “Back” buttons to cycle through the plots, or use the “Plots” popup to jump to a particular one. See, e.g., Figure 2-17, which shows the second output in the 1x1 layout format. See “Plot Editing Options” on page 6-3 for more editing techniques.

2-24

Simulation – Closed-Loop

N1 0.2 0 −0.2 −0.4 −0.6 −0.8 −1 −1.2 0 Setpoint Output

5

10 Time

15

20

Figure 2-17 PapMachCL output #2 using the 1x1 Layout option.

2-25

2

MPC Worksheet Basics

2-26

3
Using Simulink Models in MPC
Loading a Simulink Model . Open the Model Window . . . . Check Input and Output Signals Load the Model . . . . . . . Specify Signal Types . . . . . Set Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 3-2 3-2 3-3 3-3 3-3

MPC Design . . . . . . . . . . . . . . . . . . . . 3-7 Simulations using Simulink Models . . . . . . . . . 3-8

Using Simulink to Define Inputs and Select Outputs . . 3-10 Initial Conditions . . . . . . . . . . . . . . . . . 3-12 Specifying . . . . . . . . . . . . . . . . . . . . . 3-12 Verifying . . . . . . . . . . . . . . . . . . . . . . 3-12

3

Using Simulink Models in MPC

Loading a Simulink Model
In the previous example, the plant and controller models were linear. The MPC GUI also allows a nonlinear Simulink plant. The procedure is nearly the same as in the linear case above. The following example illustrates the key differences.

Open the Model Window
Your Simulink diagram must be open in order for its name to appear in the Model Load dialog. The Simulink diagram of the paper machine headbox is named “paprmach.mdl” and should be in your mpc/gui directory. Type “paprmach” in the MATLAB command line to open it. The block diagram window should be as in Figure 3-1.

1 Gp 3 Np 1 2 Gw 4 Nw Mux Demux Mux papmach S−Function Demux H2 3 N2 2 N1

Figure 3-1 Simulink block diagram of paper machine headbox model.

Check Input and Output Signals
The MPC GUI searches for all the “Inports” and “Outports” in your Simulink diagram. The signals attached to these blocks become the model inputs and outputs, respectively. In Figure 3-1, the Inports are the four circles on the left side, and the Outports are the three on the right. (The GUI requires a model to have at least one Inport and one Outport.)

3-2

Loading a Simulink Model

The port names are the default MPC signal names. For example, the default name for the third input will be “Np” in this case. If you use a vector signal as an input or output, the GUI uses the port name as the base and appends an index to distinguish each signal. For example, suppose you had an inport named U defining a vector signal of width 3. Then the corresponding inputs would be named U_1, U_2, and U_3 (the underbar causes the index to appear as a subscript in plots, etc.)

Load the Model
For simplicity, the following discussion assumes that you are starting with a blank MPC Worksheet. If your Worksheet contains icons from a previous example, use the “MPC/Clear Worksheet” menu to clear it (use “MPC/Save Worksheet” first if you wish). Click the “Load” button on the Worksheet. MPC displays the “Load Model” dialog. Click the “Simulink (MDL)” radio button. Select “paprmach” in the model list and click on the “Load” button. (If “paprmach” doesn’t appear in the list, see “Open the Model Window” on page 3-2.) A new model icon named “paprmach” (type MDL) should appear in the Worksheet.

Specify Signal Types
Double-click (or use right-click/Properties) on the icon to open the Model View/ Edit dialog. It should resemble Figure 2-5. As before (i.e., page 2-8) specify that the first two inputs are MVs, the third is MD, and the fourth UD.

Set Initial Conditions
If you are working with a linear model (including a linear Simulink model), you probably don’t need to worry about initial conditions. By default, all variables in a linear model have a steady-state of zero, and this is usually the appropriate starting point for simulations.If your model is nonlinear, however, you need to set initial conditions properly. The paper machine headbox model is nonlinear, but its authors have normalized variables to be zero at the nominal steady-state. Thus, we could use

3-3

3

Using Simulink Models in MPC

the standard linear default. Instead, let’s work through the choice of a non-zero initial condition. The Model View/Edit dialog should still be open. In place of “Sampling Period” box of Figure 2-5 you should see a button marked “Initial Condition/Edit.” Click on it. The MPC Trim dialog shown in Figure 3-2 should appear.

Inputs (* if Held)

Figure 3-2 MPC Trim (steady-state calculation) – initial state for “paprmach” model.

NOTE: Simulink provides the trim function used by the MPC GUI to calculate

steady states. See the Simulink documentation for additional information on trim’s features.

The left-hand side of the dialog displays four types of variables. The “Inputs” and “Outputs” should be familiar. In Figure 3-2 the pop-up menus have been used to select input 4 (Nw) and output 1 (H2). Both are zero by default. The right-hand side of the dialog is a summary display. In Figure 3-2 it’s displaying all the inputs. To see a summary of any of the other classes,

3-4

Loading a Simulink Model

right-click in the display area to bring up a context menu, then select the desired class. The “States” are special Simulink dependent variables. All other dependent variables (e.g., the outputs) are functions of these. The number and physical significance of the states is model-dependent. In this case there are four states. The papmach s-function defines them and sets their default initial conditions. The “Derivatives” are the rate-of-change of the states with respect to time. These must be zero at steady state. Suppose we want our simulation to have the following initial conditions:
1 Steady state. 2 Output #1 (H2) at a setpoint of 1. 3 Output #3 (N2) at a setpoint of 0. 4 Input #3 (measured disturbance Np) at a value of 0.5. 5 Input #4 (unmeasured disturbance Nw) at a value of -1.0.

We must determine values of the two MVs and four states that satisfy these conditions. In the process, we will calculate the “floating” output #2 (N1). Use the Trim dialog as follows:
1 Use the “Inputs” pop-up to select input #3. Change its value to 0.5, and click

on the “Hold” radio button. This tells MPC that you want to hold this variable at the specified value.
2 Similarly, change input #4 to -1.0, and Hold it. 3 Verify that “Hold” is off for inputs #1 and #2. Then MPC can adjust them to

satisfy other specifications.
4 Change the value of output #1 to its setpoint of 1. It is already being held by

default, which is what we want.
5 Use the “Outputs” pop-up to select output #2. It is being held by default, but

we want it to float. Click on the radio button to turn off the hold.

3-5

3

Using Simulink Models in MPC

6 Verify that output #3 is to be held at zero (default settings). 7 Verify that all states are free to vary (hold off, the default). 8 Verify that all derivatives are to be held at zero (the default).

When you have made all the specifications, click the “Trim” button on the dialog. You should see a status message saying that steady-state calculations are in progress. If all goes well, it will finish quickly and you’ll see another status message saying “All specs have been satisfied to within 1e–10”. Use the display area to see what has changed. You should find that all specified (held) variables (inputs #3 and #4, outputs #1 and #3, and all derivatives) are still at the chosen values. The MVs should now be Gp = 0.54251, Gw = 1.0954. The unspecified output should be N1 = -0.24842. The first three states will also be changed from their default values. Click “Done” in the Trim dialog to return to the Model View/Edit dialog. Then click “Done” to store the modified model. As usual, you can either keep the same name or give it a new one. MPC stores the non-zero initial condition as part of the model definition (see “Model Icons” on page 7-4).

3-6

MPC Design

MPC Design
You can apply standard MPC design procedures to a nonlinear Simulink model. The MPC GUI linearizes the model at its initial condition. Thereafter, the procedure is the same as for a linear model. The following example assumes that you have loaded the paper machine headbox model and defined the initial conditions as described in the previous section. Drag the MDL model icon to the “MPC Model” location, then click on the “MPC Design” button. The GUI asks whether you wish to linearize the model at the current initial conditions. Respond “Yes.” You should then see the MPC linear design dialog window (Figure 2-9). Make the following selections: • Prediction horizon = 10. • Number of moves = 3. • Sampling period = 0.5 time units. • Blocking with move durations of 2, 3, 5. • Anticipation off. • Weight = 0 for output #2. • All other weights and constraints at their defaults. Then click “Done” to save the controller.

3-7

3

Using Simulink Models in MPC

Simulations using Simulink Models
The simulation procedure is essentially the same as for linear models. The main difference is the potential for problems with the initial conditions. Let’s use the nonlinear plant with the controller from the previous section in a closed-loop simulation. Drag the controller icon to the “Controller” box on the Worksheet. Also drag the model icon to the “Plant” box. Then click on the “Run Simulation” button. You should get the MPC Simulation dialog shown in Figure 3-3.

Noise Summary

Setpoint Summary

Figure 3-3 Simulation menu for the nonlinear paprmach model.

Notice that the GUI uses the non-zero initial conditions as the defaults for independent inputs (i.e., MDs and UDs) and setpoints. Make the following changes • Define the N2 setpoint as a unit-step increase with a Start Time of 2 time units. • Change the Run Duration to 20.

3-8

Simulations using Simulink Models

then click on “Run.” Figure 3-4 shows the output responses for this case. As for the linear plant there is some interaction (H2 deviates from its setpoint), but both H 2 and N2 return to their setpoints rapidly. The steady-state offset in the floating output, N1, is expected (zero weight in MPC design step).
H2 1.2 Setpoint Output 2 1 0 0.8 0 10 Time N2 2 Setpoint Output 20 −1 0 10 Time 20 N1 Setpoint Output

1

1

0 0

10 Time

20

Figure 3-4 Output responses for MPC of nonlinear paprmach model.

3-9

3

Using Simulink Models in MPC

Using Simulink to Define Inputs and Select Outputs
Figure 3-5 is a modification of Figure 3-1 in which the fourth input, Nw, has been defined within Simulink. You can do this for any independent input. An advantage is that you can use all the blocks and functions available in Simulink to construct the signal. It also reduces the number of input signals you must deal with in dialogs, etc. (In Figure 3-5, however, Nw is just a step, which could be done equally well within MPC.) Other considerations are: • All variables that are to be used as MVs must be connected to Inport blocks so MPC can recognize them. This is the case in Figure 3-5. • Similarly, all variables to be used as MDs must be connected to Inports. Otherwise MPC is unaware of them, and can’t provide feedforward compensation. • The MPC Trim dialog does its steady-state calculation at time = 0. Inputs defined in Simulink must have the correct values at this time. For example, to duplicate the results obtained previously for the paprmach model (see page 3-6) you would have to set the initial value of the step function, Nw, to -1.

1 Gp 3 Np Nw Mux 2 Gw Mux papmach S−Function Selector Demux Demux 1 H2 2 N2

Figure 3-5 paprmach model with Nw defined within Simulink.

If we truly have no use for output N1 in the MPC design, it’s better to eliminate it. Then it won’t appear in the MPC Design dialog and we won’t have to set its weight to zero. This would also reduce the number of plots and the memory requirements.

3-10

Using Simulink to Define Inputs and Select Outputs

Figure 3-5 illustrates the use of a selector block to eliminate output N1. The selector passes only the first and third outputs of the S-Function through to the Demux block. Another way would be to connect N1 to something other than an Outport (for example, one of the Simulink library’s Sink blocks).

3-11

3

Using Simulink Models in MPC

Initial Conditions
Specifying
If you wish to run a simulation with non-zero initial conditions, you must use a Simulink plant model. All other model types have an initial condition of zero. If you wish to use non-zero initial conditions for one of these types, consider converting to an equivalent (linear) Simulink model. See section Set Initial Conditions in this chapter for more details on how to define initial conditions for a Simulink model.

Verifying
When working with nonlinear models, if you observe unexpected behavior at the beginning of a simulation, the initial conditions are the first thing you should check. In particular, if your initial condition is supposed to be a steady state, it’s good practice to verify that it is! Run an open-loop simulation as a test. Turn off all known signal variations (e.g., make the initial and final values of Nw the same in Figure 3-5). Starting from your desired initial condition, run a simulation and plot the outputs. If any outputs vary, either an input signal is incorrect or your initial condition was unsteady. Check all inputs to make sure their initial values were as you planned. Then repeat the MPC Trim dialog, making sure that all calculated derivatives are zero.

3-12

4
Disturbance Detection and Estimation
Disturbance Estimation Goals . . . . . . . . . . . . 4-2 Paper Machine Headbox Example . MPC Design . . . . . . . . . . . . Noise Signal Definition . . . . . . . Disturbance Estimator for Noisy Signal Sustained Disturbances . . . . . . . Plant with Integration . . . . A Simple Example . . . . . . . MPC Design with Default Estimator Steady-state Offset in MPC . . . MPC Design to Eliminate Offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3 4-3 4-3 4-5 4-7

. 4-13 . 4-13 . 4-13 . 4-14 . 4-16

General Open-Loop Unstable Plants . . . . . . . . . 4-18 Theoretical Background . . . . . . . . . . . . . . 4-19 One measured output . . . . . . . . . . . . . . . . . 4-19 Multiple measured outputs . . . . . . . . . . . . . . 4-21

4

Disturbance Detection and Estimation

Disturbance Estimation Goals
Unknown disturbances, sensor errors, and model inaccuracies are inevitable in MPC applications. They show up as a difference between the measured plant outputs and the values predicted by MPC’s internal model. One usually assumes that each measurement is “unbiased,” i.e., if a variable were constant, we would expect the mean of repeated measurements to converge to the true value. (The scatter of the individual measurements about the mean would be considered “measurement noise,” often assumed to have a normal distribution.) When such outputs have setpoints, MPC should drive the measurements to the setpoints – the “zero offset” condition. To accomplish this, MPC uses measurement feedback to correct its predictions.

Note: If MPC’s internal model is open-loop unstable such corrections are

essential. Without them, prediction errors will eventually become very large. “Integrating” behavior is a common example of such a case.

By default, MPC assumes that there are random step-like (sustained) disturbances at the plant output. It estimates their magnitude by subtracting the predicted outputs from the measurements. This simple approach often provides sufficiently rapid disturbance rejection with zero offset. But there are at least two situations where an alternative might be warranted: • A measurement is very noisy. Its mean follows MPC predictions, but there are frequent, short-term positive and negative deviations. In this case MPC should rely on its predictions for the short-term, and use the mean of the measurements to correct its long-term predictions. • There is a consistent trend. A simple example is a ramp-like disturbance at the plant output. In this case MPC should take quick action to counteract the expected trend.

4-2

Paper Machine Headbox Example

Paper Machine Headbox Example
The MPC GUI includes a “Disturbance Estimator” that you can configure for each output. Let’s re-examine the paper machine headbox example, Figure 2-2.

MPC Design
Suppose that we are using the LTI “PapMach” model (see page 2-9) and have made the following MPC design selections: • Prediction horizon: 10. • Number of moves: 3. • Blocking durations: 2, 3, 5. • Sampling period: 0.25 (reduced from earlier example to improve disturbance rejection). • Output weights: zero for output N1. Defaults for others. • Default values for all other MPC design parameters. The MPC design window should resemble Figure 2-9, but with a sampling period of 0.25 (rather than 2). Save this controller as “PapMach.”

Noise Signal Definition
Suppose that the measurement of H2 is noisy. Let’s create a file containing a noise signal (for use in simulations). Make sure MATLAB’s default directory is one in which you can save a file (use the cd command to check the current directory). Then in the Command window enter
t=[0 : 0.25 : 30]’; NoiseData=[t randn(length(t),1)]; save H2noise.txt NoiseData -ascii

This creates an ascii file called H2noise.txt in the default directory. Drag the PapMach model icon to the “Plant” box on the Worksheet, and drag the PapMach controller icon to the “Controller” box. Click the “Run Simulation” button, then select

4-3

4

Disturbance Detection and Estimation

• Run duration: 20. • Closed loop. • Specify H2 noise. With H2 selected in the “Plant Outputs” pop-up menu, click on the “+ Noise” button. The Signal Specification dialog appears. Click the “File” radio button. A standard file selection dialog appears. Navigate to the directory (folder) containing H2noise.txt, select it, then click “Open.” The signal should plot in the Signal Specification window. Click “Done.” This returns you to the MPC Simulation dialog. Click “Run” to start the simulation. The outputs and MVs should resemble Figure 4-1 and Figure 4-2 (your results will not be exactly the same if MATLAB selects a different noise sequence). MPC responds to the H2 noise by making large adjustments to both MVs (Figure 4-2). This causes significant disturbances in output N2, which is actually noise-free (Figure 4-1).
H2 1 10 5 0 0 −1 0 10 Time N2 0.5 Setpoint Output 20 −5 0 10 Time 20 N1

0

−0.5 0

10 Time

20

Figure 4-1 MPC of PapMach with default estimator, noisy H2 signal.

4-4

Paper Machine Headbox Example

Gp 5 0 −5 −10 0 5 10 Time Gw 20 15 20

0

−20 0

5

10 Time

15

20

Figure 4-2 MVs corresponding to outputs shown in Figure 4-1.

NOTE: Use the MPC Plot context menu feature to hide all but one of the legends as in Figure 4-1 (see “Hide/Show Legend” on page 6-5). The remaining legend has been dragged to the position shown. Otherwise the legends would obscure the curves.

Disturbance Estimator for Noisy Signal
Let’s modify the MPC design to reduce the impact of the H2 noise. Double-click on the PapMach icon in the “Controllers” area (not the “Models” area). The MPC Design dialog should appear. Click the “Disturbance Estimator” check box. The Disturbance Estimator Design dialog of Figure 4-3 should appear.

4-5

4

Disturbance Detection and Estimation

Summary

Figure 4-3 Estimator design dialog for PapMach.

Verify that output H2 appears in the pop-up at the top. Then adjust the noise level specification until the Noise/Signal ratio (N/S) is approximately 100. You can either use the slider or type 100 in the edit box. If you use the slider, you’ll notice that its scale is nonlinear. An N/S value of zero specifies that there is no noise (the default). As N/S increases, MPC pays less attention to the measurement. A value of 100 is large and should have an obvious effect on MPC performance.

NOTE: See section Theoretical Background for more details.

Leave the remaining settings as-is. Click “Done” to return to the MPC Design dialog. Change the “Controller Name” field to “PapMach1” and (optionally) enter some notes to remind yourself how this controller differs from the base case. Then click “Done” to return to the Worksheet. There should now be two controller icons. Drag the “PapMach1” controller icon to the “Controller” box, then repeat the simulation (MPC should remember your simulation specifications, so just click “Run Simulation” to get the Simulation dialog, then click “Run.”). When asked, rename the results “PapMach1.”

4-6

Paper Machine Headbox Example

H2 0.1 0.2

N1

0

0

−0.1 0

10 Time N2

20

−0.2 0

10 Time Setpoint Output

20

0.01

0

−0.01 0

10 Time

20

Figure 4-4 MPC of PapMach, but with H2 Noise/Signal = 100.

Figure 4-4 shows that we have reduced the noise effect significantly (compare to Figure 4-1, and note the change in scale). The MVs are also much quieter (not shown, but see your MV plot).

Sustained Disturbances
If there is a sustained disturbance, however, the high Noise/Signal ratio used in the previous example might impair disturbance rejection. Let’s see… In the Worksheet with the Plant and Controller defined as in the previous case, click “Run Simulation” to get the Simulation dialog. Next • Turn off the H2 noise. You could retain the noise, but it obscures the effect of sustained disturbances. • Set Nw (the unmeasured disturbance input) to a constant value of 10. then run the simulation. Rename the results. (As you accumulate result icons, use the Notes feature to keep track of the differences between them. See “Notes” on page 7-2).

4-7

4

Disturbance Detection and Estimation

H2 0 4 2 −0.2 0 −0.4 0 10 Time N2 1 20 −2 0

N1

10 Time

20

Setpoint Output

0.5

0 0

10 Time

20

Figure 4-5 Effect of UD (Nw = 10) – MPC design as for Figure 4-4.

Figure 4-5 shows that there is now a significant disturbance in both controlled outputs (i.e., H2 and N2 – recall that N1 is not being controlled). Is this due to the large Noise/Signal we’re using for H2? To find out, let’s repeat the simulation using the original MPC design (controller PapMach). We find that there is no difference! (Not shown, but you can confirm this.) In general there would be a clear difference, but there are several unique, mitigating factors in this case: • The disturbance, Nw, has no effect on the first output, H2. You can see this by running an open-loop simulation (Figure 4-6). Thus, the closed-loop disturbance in H2 is due only to interactions as MPC attempts to regulate N2. Recall that unfavorable plant characteristics prevent us from eliminating these interactions (see Figure 2-16 and related discussion). • We are using the default estimator for N2 in both cases. • The same model is being used for the plant and within MPC (no plant/model mismatch). If there were model error, this would cause additional

4-8

Paper Machine Headbox Example

disturbances in H2, and the large H2 estimator Noise/Signal ratio would make a difference.

H2 1 10

N1

0

5

−1 0

10 Time N2

20

0 0

10 Time

20

10

5

0 0

10 Time

20

Figure 4-6 Open-loop response to unmeasured disturbance (Nw = 10).

Now let’s try to improve the disturbance rejection for output N2. Figure 4-6 shows that the disturbance in Nw causes N2 to respond with a time constant of about 5 time units (the settling time is 20 minutes, which should be equivalent to about 4 time constants). Create a new controller that’s identical to PapMach1 (with Noise/Signal = 100 for H2) except that the estimator accounts for the disturbance trend shown in Figure 4-6. To do so • Double-click on the PapMach1 controller and click on the Disturbance Estimator “Edit” button. This displays the Disturbance Estimator Design dialog. • Select N2 in the “Measured Output” pop-up menu (leave the H 2 settings as-is).

4-9

4

Disturbance Detection and Estimation

• Set the “Disturbance Type” time constant to 5. Either move the slider or type 5 in the edit box. • Leave the “Noise Level” at zero. The Disturbance Type slider has a nonlinear scale (as does the Noise Level slider). A Disturbance Type of zero implies rapid (step-like) changes at the output (the default). A value of infinity implies ramp-like disturbances. An intermediate value (such as the 5 used here) implies a first-order (exponential) character. The choice of the Disturbance Type time constant is rarely obvious. In this case we are guided by the known disturbance characteristics, but it usually requires some tuning. In general, MPC becomes more “aggressive” as the time constant increases. In the extreme (ramp-like disturbances), MPC “thinks” that a small disturbance will grow with time, so it makes a relatively large correction.

NOTE: You are only specifying the disturbance’s time-scale. MPC infers its

magnitude from the measurements.

Click “Done” on the Estimator dialog. In the MPC Design dialog, assign a new controller name and enter appropriate notes. Then click “Done.” Repeat the simulation. Figure 4-7 compares the results for the revised estimator to those obtained previously (from Figure 4-5). The revised MPC rejects the N2 disturbance much more rapidly and reduces the peak by over 50%. It even improves the control of H2.
NOTE: Performance is usually insensitive to rather large changes in the

Disturbance Type parameter. Figure 4-8 shows that a variation between 2.5 and 50 gives almost the same response seen in Figure 4-7. It also shows the trend of increasing aggressiveness as the time constant increases – notice the increasing overshoot in N2.

4-10

Paper Machine Headbox Example

H 0.5

2

N1 4 2

0 0 −0.5 0 10 N2 1 0.5 0 −0.5 0 10 Time 20 Setpoint H2 and N2 Estimators H Estimator Only 2 20 −2 0 10 Time 20

Figure 4-7 Effect of estimator design for closed-loop MPC, Nw = 10.

4-11

4

Disturbance Detection and Estimation

H2 0.2 2 1 0 0 −0.2 0 10 N2 0.5 20 −1 0

N1

10 Time

20

0

Setpoint Time Constant = 2.5 Time Constant = 50

−0.5 0

10 Time

20

Figure 4-8 Effect of Disturbance Type time constant.

4-12

Plant with Integration

Plant with Integration
A Simple Example
Figure 4-9 is a Simulink diagram of a simple “integrating” plant. This could approximate a physical situation in which the input, u, is the difference between liquid flow entering and leaving a storage tank, and the output, y, is the liquid level in the tank. There is a disturbance in the net flow (the step block). The desired steady-state output is y = 10, and the initial disturbance is 1. We need u = -1 to make this condition a steady state (otherwise a non-zero input to Gain is integrated, causing y to ramp).

Sum 1 u 2 Gain 1 s Integrator 1 y

Step
Figure 4-9 Simulink plant with integrating characteristics.

Suppose that at time = 0 the system is at the desired steady state. At time = 5 there is a unit-step increase in the disturbance (i.e., it changes from 1 to 2).

MPC Design with Default Estimator
Let’s test a standard MPC design for this system.
1 Create the Simulink model of Figure 4-9. The Integrator initial condition

should be 10, and Step should have an initial value of 1, a final value of 2, and a step time of 5.
2 Load the model into the Worksheet (if necessary, review “Loading a

Simulink Model” in Chapter 3).

4-13

4

Disturbance Detection and Estimation

3 Set the initial conditions. The GUI should set the state to 10 automatically

(if not, return to step 1, Integrator initial condition). You will need to set the initial values of the input to -1, and the output to 10. Save the model.
4 On the Worksheet, drag the model icon to the “Plant” and “MPC Model”

boxes. Click the “MPC Design” button. Linearize the model (trivial as it’s already linear). Then make the following choices on the MPC Design dialog: - Prediction horizon: 10. - Moves: 3. - Blocking: durations 2, 3, 5. - Sampling period: 0.25 - Other values at their defaults.
5 Save the controller, then drag its icon to the “Controller” box on the

Worksheet. Click the “Run Simulation” button. Verify the following settings on the Simulation dialog: - Run duration: 10 - Output setpoint: constant value of 10 - Closed loop operation Then click “Run.”

Steady-state Offset in MPC
Your results should resemble Figure 4-10 and Figure 4-11. MPC quickly moves the MV to -2 (to compensate for the disturbance of 2) but it doesn’t bring the output back to its setpoint. The reason is that the default estimator expects step-like disturbances at the output, but the integrating plant actually has ramp-like output disturbances.

4-14

Plant with Integration

y 11 10.8 10.6 10.4 10.2 10 9.8 0

Setpoint Output

2

4 Time

6

8

10

Figure 4-10 MPC of integrating plant output with default estimator
u −0.6 −0.8 −1 −1.2 −1.4 −1.6 −1.8 −2 −2.2 0 2 4 Time 6 8 10

Figure 4-11 MV moves corresponding to Figure 4-10.

4-15

4

Disturbance Detection and Estimation

MPC Design to Eliminate Offset
You need to modify the default estimator to eliminate the offset.
1 On the Worksheet, click on “MPC Design.” 2 In the MPC Design dialog, click the “Disturbance Estimator” checkbox. 3 In the Disturbance Estimator Design dialog, move the “Disturbance Type”

slider all the way to the right. This changes the disturbance assumption from step-like to ramp-like. Click “Done” to save the estimator.
4 In the MPC Design dialog, click “Done” then “Rename” to save the modified

controller under a different name.
5 Drag this controller to the “Controller” box and run the simulation (no

changes needed in the Simulation dialog). Your results should now resemble Figure 4-12 and Figure 4-13. The new controller quickly eliminates the offset. Since the MPC design model is accurate (identical to the plant), you could obtain even better performance here by eliminating blocking (i.e., number of moves equal to the prediction horizon) and setting the weight on u to zero in the MPC design. This controller eliminates offset in a single sampling period (not shown, but easily verified). It is very aggressive, however, and would probably work poorly in a real application with modeling error.

4-16

Plant with Integration

y 10.6 10.5 10.4 10.3 10.2 10.1 10 9.9 9.8 0 2 4 Time 6 8 10 Setpoint Output

Figure 4-12 MPC of integrating plant – modified estimator.

u −0.8 −1 −1.2 −1.4 −1.6 −1.8 −2 −2.2 −2.4 −2.6 0 2 4 Time 6 8 10

Figure 4-13 MV moves corresponding to Figure 4-12.

4-17

4

Disturbance Detection and Estimation

General Open-Loop Unstable Plants
The integrating plant considered in the previous section is a special case of an asymptotically unstable system (its pole is at the origin of the complex plane). If the plant has a pole whose real part is greater than zero, the simple ramp-like disturbance assumption used in the previous section is inappropriate. You then have two choices:
1 Abandon the GUI. The MPC Tools commands can handle this case, but we

have yet to include an equivalent facility in the GUI.
2 Stabilize the plant with a simple feedback control (proportional control is

appropriate for this). Use the stabilized plant model in the GUI.

4-18

Theoretical Background

Theoretical Background
Figure 4-14 shows the standard MPC configuration (discussed in “Overview: Single-Input, Single-Output (SISO) MPC” in Chapter 1). State estimation’s role here is to predict the impact of the unmeasured disturbances, d, on the true plant output, y . We assume that plant inputs u and v are known exactly, but the output measurement, y, includes measurement noise, z. One of the estimation challenges is to distinguish between the noise (which MPC should ignore) and a true disturbance (for which MPC should compensate by adjusting u).

Measured Disturbance Noise

v
Setpoint

v MPC
Actuator

z Plant y
Plant Output

r y

u d

+ +

y

Unmeasured Disturbance

Measured Output (Controlled Variable) Figure 4-14 Standard MPC configuration.

One measured output
For the moment, consider a plant with a single measured output. We model the plant as shown in Figure 4-15. Gv and Gu are transfer functions relating the known inputs to the true output. (Note: v and Gv are optional). Gw is a transfer function relating a random input, w, to the disturbance signal, d. These transfer functions are all discrete-time. Their sampling periods are ∆t (the MPC sampling period) and their outputs sum to form the true output. We assume that z is random and obeys a normal distribution N ( 0, σ z ) , i.e., 2 2 has a zero mean and a variance σ z . Similarly, w is N ( 0, σ w ) .
2

4-19

4

Disturbance Detection and Estimation

v

G v

y yu + + +

v

z

u

G u

y
+

+

y

w

G w

d

Figure 4-15 Block diagram of plant model for state estimation.

The Gv and Gu transfer functions can be measured experimentally or obtained from a mechanistic model of the process. We could do the same for Gw, but instead choose a convenient approximation: 1 q G w ( q ) = G w1 ⋅ G w2 = ----------- ⋅ ----------q–1 q–a
(4-1)

where q is the discrete-time shift operator. The transfer function G w1 converts (integrates) the zero-mean w signal; its output has a noisy step-like character. The transfer function G w2 imparts a trend, the nature of which depends on the value of the parameter, α. It may be helpful to think of α as a characteristic disturbance time constant, τ d , according to the mapping ∆t τ d = – --------ln α
(4-2)

where ∆t is the MPC sampling period. The τ d value is the “disturbance type” parameter discussed in section Sustained Disturbances (also the “Time Constant” of Figure 4-3). As α → 0 (or τ d → 0 ) G w2 goes to unity and has no effect, i.e., the disturbance d retains the step-like character produced by G w1 . As α → 1 (or τ d → ∞ ) G w2 acts as a second integrator and d exhibits a ramp-like character (whose slope changes randomly). For intermediate α, d

4-20

Theoretical Background

behaves as the output of a first-order system (with time constant τ d ) whose input is a series of random steps, i.e., it has a drifting character. We can convert Gw to discrete-time state-space form xk + 1 = Aw xk + Bw wk dk = Cw xk
w w w w

(4-3) (4-4)

where x k is a vector of “disturbance states.” If α > 0 there are two elements w w in x k . Otherwise, x k is a scalar. The states of the Gv and Gu are assumed to be known, as noted previously. At the kthsampling instant, given the noisy measurement yk, the goal is to estimate the disturbance states. Referring to Figure 4-15, we first subtract the known components from the measured output to obtain the combined disturbance and noise. Let this be the d noisy measurement of the disturbance, y k yk = dk + zk = yk – yk – yk Combining this with (4-4) yk = Cw xk + zk
2 d w d v u

(4-5)

(4-6)
2

The matrices Aw, Bw, and Cw with estimates of the variances σ w and σ z define a steady-state Kalman gain matrix, K. The estimate of the disturbance states is then
w d ˆw xˆk = x k – 1 + Ky k

(4-7)

In fact, only the relative noise σ z ⁄ σ w matters in the calculation of K. This is the noise-to-signal ratio discussed in section Disturbance Estimator for Noisy Signal (and specified as shown in Figure 4-3).

Multiple measured outputs
If there are multiple outputs, the GUI assumes that disturbances to each are independent of one another. It treats each output individually, estimating the associated disturbance state(s) as shown above for the single-output case.

4-21

4

Disturbance Detection and Estimation

4-22

5
Signal Anticipation

5

Signal Anticipation

It is occasionally possible to anticipate changes in a measured disturbance or a setpoint. In other words, the plant operator may know in advance that a change is coming. MPC tries to track setpoints over a prediction horizon of P future sampling periods (see “Designing a Controller” in Chapter 2). As soon as the change appears in the prediction horizon, MPC can begin planning for it. MPC’s setpoint tracking performance usually improves when it has advance notice of a setpoint change. To try this feature, load the LTI PapMach model (see “Loading the LTI model of the headbox” on page 2-5). Set the signal types of the last two inputs to MD and UD as before. Then drag the PapMach icon to the “Plant” and “MPC Model” boxes on the Worksheet. Click on the “MPC Design” button and make the following choices: • Prediction horizon: 10. • Number of moves: 3. • Sampling period: 0.25. • Blocking: durations of 2, 3, 5. • Turn anticipation on. When you click the “Anticipation” checkbox, the dialog of Figure 5-1 appears. Anticipation will be On for all signals by default. To toggle a signal from On to Off or vice versa, click the signal’s name in the list. In this case we will only anticipate changes in the N2 setpoint, so turn off all but that one (as shown in Figure 5-1). Then click “Done” to return to the MPC Design dialog. • Weight: 0 for output #2. • All other weights and constraints at their defaults. Then click “Done” on the MPC Design dialog to save the controller. If you wish (for comparison), create another controller that is identical except that anticipation is Off for all signals.

5-2

Figure 5-1 Signal anticipation dialog for PapMach example.

Drag the controller icon (the one with anticipation) to the “Controller” box on the Worksheet and click “Run Simulation.” The resulting “Setpoint Summary” display should indicate that anticipation is ON for N2. Make sure the “Closed Loop” radio button is on, and set the “Run Duration” to 30. Use the “Setpoints” pop-up to select N2 and click the “Specify” button. Define a unit-step increase that occurs at a “Start Time” of 10. Click “Done” to return to the “Simulation” dialog, then click “Run” to start the simulation. Figure 5-2 shows the response of N2 with anticipation on vs. the default (no anticipation). When anticipation is on, MPC begins to vary the MVs as soon as the setpoint change appears in the prediction horizon, i.e., (10)(0.25) = 2.5 time units in advance. The resulting servo response tracks the step change much better than the default case. In general, anticipation provides the greatest benefit when the process is sluggish or there is a large delay.

5-3

5

Signal Anticipation

PapMach Output N 1.2 1 0.8 0.6 0.4 0.2 0 −0.2 0

2

Setpoint Anticipation ON Anticipation OFF

5

10

15 Time

20

25

30

Figure 5-2 PapMach servo response with and without anticipation.

5-4

6
Working with Plots

Plot Editing in MPC – An Example . . . . . . . . . . 6-2 Plot Editing Options . Context Menus . . . . The Curve Context Menu The Plot Context Menu . Editing Text . . . . . . Zooming . . . . . . . The Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 6-3 6-3 6-4 6-6 6-7 6-10

6

Working with Plots

Plot Editing in MPC – An Example
Figure 4-7 and Figure 4-8 illustrate several MPC plot editing features (see “Plot Editing Options” on page 6-3). To reproduce such combined graphs,
1 Display the results for the two cases in separate windows (double-click on

the corresponding results icons).
2 Change the responses for one of the cases to a new color (red, for example)

by right-clicking on each curve, then selecting the desired color from the context menu.
3 Copy each of the red curves to the other window by right-clicking on a curve,

then selecting Copy Line. Then right-click in the corresponding axis of the other window and select Paste Line.
4 Edit the figure titles to add TEX formatting that converts the numbers to

subscripts. Click on the title you wish to edit. Suppose it’s “N2.” Then insert an underscore between the “N” and the “2” (i.e., N_2). Finally, hit the Esc key or click somewhere else in the figure. The “N_2” should change to “N2.”
5 Hide the legends in the upper two plots. Right-click inside each plot (but not

on a curve) and select Hide Legend in the context menu.
6 Edit the remaining legend. In the plot on the lower left, right-click on the

green curve, then select Edit/Add Legend. Edit the legend and hit the Enter key. Repeat for the red curve. Then drag the new legend to the location shown.

6-2

Plot Editing Options

Plot Editing Options
NOTE: Editing effects disappear when you close a figure window. If you wish to save the state after you’ve made some changes, use the “Save” command in the “File” menu. Then to retrieve it, use the “Open” command in the “File” menu.

Context Menus
You can use special “context menus” to modify the appearance of MPC plots. To see the context menu, right-click on the appropriate region of the plot (when using a one-button Macintosh mouse, click while holding down the Option key). MPC plots have two types of context menus: • Curve. Right-click on a curve. The context menu options apply to that curve. • Plot. Right-click within a plot axis, but not on a curve. The operations performed by this context menu apply to the plot as a whole.

The Curve Context Menu
The Curve context menu options are: • Color. Change the curve’s color (seven different colors allowed). • Style. Change the line style (solid, dash, dash-dot, etc.). • Width. Set the line width (choose a numerical value in points). • Marker. Add or remove a marker for each data point (14 different markers). • Zoom with Mouse. See “Zooming” on page 6-7. • Edit Axis Limits. See “Edit Axis Limits” on page 6-4. • Copy Line. Copy the curve to a special “clipboard.” You can then paste it into another MPC plot (see “Paste Line” on page 6-4). MPC copies the legend and formatting information (color, etc.) as well as the data. • Delete Line. This removes the curve and its legend (no Undo!). • Edit/Add Legend. Displays an edit box containing the existing legend (or a blank field if no legend exists). Change it as you wish. You may use TEX

6-3

6

Working with Plots

formatting for special effects (see “TeX Interpreter” on page 6-7). When finished editing, hit the Enter key. See Figure 4-8 and related discussion for an example application of some of these features.

The Plot Context Menu
In the discussion of the following items, a “plot” is one of the axes in which a plot appears. (An MPC plotting window may contain more than one axis.) The “current plot” is the axis in which you have just activated the context menu.

Paste Line
Once you have used Copy Line to copy a curve to the “clipboard” (see page 6-3) Paste Line pastes the curve into the current plot.

Zoom with Mouse
This allows you to focus on a particular region of a plot. It includes options to zoom either the x or y coordinates of all plots in a figure window. See “Zooming” on page 6-7 for more details.

Edit Axis Limits
This is an alternative to zooming with the mouse. It brings up a standard Matlab dialog box. You can then set the axis limits of the current plot. When you close the dialog, MPC gives you the option to apply changes to all axes in a figure window.

Change Title
The plot title (if any) highlights so you can edit it. (Clicking on an existing title does the same thing.) When finished, click outside the highlighted area or push the Esc key. You may include TEX formatting for special effects (see “TeX Interpreter” on page 6-7). If no title exists, a blank area highlights so you can enter one.

Change X-Axis Label
As for “Change Title,” but for the label below the horizontal axis.

6-4

Plot Editing Options

Change Y-Axis Label
As for “Change Title,” but for the label below the vertical axis.

Import Plot
Imports plot data from the main Matlab workspace, then adds all the curves defined therein to the current plot. The imported data must be a Matlab “structure” in the mpcplot format. Type help mpcplot in the command window for a summary of the fields. (An easy way to generate such data is to “Export” it from an MPC plot – see next section). The context menu displays a dialog box that lists all the structures in your main workspace. Select the one you wish to import, then click “Import.”

NOTE: If the imported data defines multiple plots, you will be asked to choose one of them. If the data you wish to import doesn’t appear in the list, Matlab doesn’t recognize that variable as a structure. Use the whos command to check the contents of your main Matlab workspace.

Export Plot
Saves the current plot’s data and formatting information as a “structure” in the main Matlab workspace. See the function mpcplot for details (or type help mpcplot in the Command window.

Export All
As for Export Plot (previous section), but all plots in the figure window are exported (not just the current plot).

Hide/Show Legend
MPC hides the legend associated with the current plot (if it’s showing) or reveals it (if it’s hidden). No legend will appear unless you’ve defined a legend string for at least one of the curves in the plot (see Add/Edit Legend on page 6-3).

6-5

6

Working with Plots

Add/Delete Axis
Add Axis adds a blank axis to the figure window. The new axis will appear after all the existing axes. You can then import plot data to the new axis. Delete Axis permanently removes the current axis from the figure window (no

Undo!).

Font
Font displays a font selection dialog where you can specify the font type and size used in all plot labels (including axes and legends). Your selection will apply to all axes in the current figure window.

Use this feature to increase the font size for presentations (slides and transparencies).

Editing Text
Text Objects in the MPC GUI
You can edit the following text objects: • Plot titles. • X-axis labels. • Y-axis labels. • Legend strings. • Icon names (on the Worksheet) To edit one of the first three, click on it. The text highlights and you can edit it. When finished, click outside the edit field or push the Esc key. Another way is to use the plot’s context menu. See page 6-4. To edit a legend string, use the curve context menu (Edit/Add Legend). See page 6-3. To edit the name of an icon on the Worksheet, right-click on the icon to get its context menu, then select “Rename.” This highlights the icon name so you can edit it. When finished, click outside the name field or hit the Esc key.

6-6

Plot Editing Options

TeX Interpreter
All MPC text objects have the ‘Interpreter’ property set to ‘TeX.’ This allows you to define plot labels and legends that contain Greek characters, subscripts and superscripts, mathematical symbols, combinations of bold, italics, and normal fonts, etc. Figure 4-8 and associated discussion give you one example of the possibilities. For additional information and examples see the on-line Matlab documentation: • Text Properties (Matlab Function Reference) • Text (Matlab Function Reference)

Zooming
MPC allows you to zoom in on a plot region. If your plot window contains multiple axes, you have the option to zoom all plots simultaneously. Consider the plot window shown in Figure 6-1. We have just turned the MPC zoom mode On using the context menu (right-click in any plot axis, then select Zoom with Mouse; see page 6-4). You can tell that zooming is on because the UI controls at the bottom differ from the standard MPC controls (e.g., compare to Figure 5-2) and the cursor changes to a crosshair. Most of the action is happening between time 8 and 15. We’d like to expand this region of each plot without changing the y-axis scales (which are all different). • Click the “X” radio button on the lower-left. • Click the “All X” radio button on the lower-right. • Click and drag in any of the plot axes such that you begin at about time = 8, and end at about time = 15. In this case it doesn’t matter how much you move in the y-axis dimension (because neither “XY” nor “Y” is selected in the lower-left).

6-7

6

Working with Plots

H2 0.1 4 2 0 0 −0.1 0 10 Time N2 2 1 0 −1 0 10 Time 20 30 20 30 −2 0 10

N1

20 Time

30

Setpoint Output

Figure 6-1 A plot for which the MPC zoom mode has just been turned on.

When you release the mouse button, all three x-axis scales should zoom, giving you a plot similar to Figure 6-2 (depending on exactly how you dragged). Now suppose you want to make it clear that H2 changes relatively little. You could set the radio buttons to “Y” and “All Y,” then zoom the y-axis range of the N1 signal (which varies the most). This would change all the y-axis limits to vary from -0.1 to 2.2 (again, depending on your mouse skills), and H2 would become a small wiggle on this scale (not shown, but try it).

6-8

Plot Editing Options

H2 0.1 4 2 0 0 −0.1 8 10 12 Time N2 2 1 0 −1 8 10 12 Time 14 14 −2 8 10

N1

12 Time

14

Setpoint Output

Figure 6-2 After zooming all axes of Figure 5-2 in the x-coordinate (note button states).

When you’re satisfied with the axis limits, click “Done” to return to the normal MPC plot mode.

NOTE: While the zoom mode is on, MPC won’t let you resize the window or

move the legends, and it disables all plot editing functions.

6-9

6

Working with Plots

If you wish to set the axis limits precisely, it’s better to use the “Edit Axis Limits” context menu (see page 6-4). The MPC zoom mode also provides the following options: • Left-click to zoom in on the point under the cross hairs (by a factor of 2). Each time you click you zoom further. • Right-click to zoom out by a factor of 2. • Double-click to revert to the original axis limits.

The Toolbar
The Matlab “Toolbar” – introduced in Version 5.3 (Release 11) – provides yet another way to modify your plots’ properties. MPC hides the Toolbar by default. To use it, select “Show Toolbar” in the “Tools” menu (usually found on the Figure window, but this is operating-system dependent). Excellent on-line help is available. To see it, select “Help Plot Editor” in the “Help” menu. The Help menu usually appears near the top of a plot window; this is also system-dependent. The Toolbar and the MPC editing features overlap to some extent. Each has its strengths. Experiment to see which is more convenient for you.

NOTE: When the Toolbar is in use, it disables other plot editing functions (e.g., the MPC GUI context menus). It also replaces MPC context menus with its own. If the expected MPC menu no longer appears, you may need to hide the Toolbar. You may also experience “strange behavior” if you switch back and forth between the two editing methods.

6-10

7
Worksheet Icons

Icon Menus Properties . Notes . . . Export . . . Import . . . Delete . . . Rename . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

7-2 7-2 7-2 7-2 7-3 7-3 7-3 7-4 7-4 7-7 7-9

Icon Data Structures Model Icons . . . . . Controller Icons . . . Result Icons . . . . .

7

Worksheet Icons

Icon Menus
MPC Worksheet icons have context menus that allow you to • view/modify icon properties • import/export the icon data. • delete the icon and its data from the Worksheet • rename the icon. To see the context menu, right-click on the icon (option-click the one-button Macintosh mouse). The following sections describe the effect of each menu item.

Properties
If the icon is a “Model” or a “Controller,” Properties displays the appropriate View/Edit dialog (see Figure 2-5 and Figure 2-6). If the icon is a “Result,” Properties plots the response curves.

Notes
This displays the current icon notes, if any (see Figure 2-14). You can edit the information therein if you wish. Notes help you keep track of the special features of each icon. When you run a simulation (creating a Result icon), MPC automatically copies any notes from the “Plant” and “Controller” icons into the Result icon. It also adds a summary of the simulation conditions.

Export
This exports the icon’s data to the main MATLAB workspace. Then you can either import it into another MPC Worksheet (see next section), or use the data for some other purpose (e.g., custom plotting). See “Icon Data Structures” for details.

7-2

Icon Menus

Import
This imports icon data from the main MATLAB workspace into a blank icon slot on the Workspace. (MPC disables the Import option when you right-click on a full slot.) The data must be stored in a MATLAB “structure” variable. Each type of icon (Model, Controller, Result) has different data requirements. If the data you’re importing is incompatible with the type of slot you’ve chosen, an error message appears. One way to create a compatible structure is to export it from the Worksheet (see previous section).

Delete
Clears the icon from the Worksheet. If it’s in the special “Plant,” “MPC Model,” or “Controller” location, it’s actually deleted (because it’s just a copy of another icon). Otherwise MPC moves it to the Overflow (and you can retrieve it if necessary).

Rename
Highlights the icon name on the Worksheet and allows you to edit it. When you’re finished editing, click outside the icon or push the Esc key.

7-3

7

Worksheet Icons

Icon Data Structures
This section details the icon data structures used in the MPC GUI. You may need this information if you’ve exported data from the MPC Worksheet and wish to use it for custom plots, etc. All data are MATLAB structure variables. See the MATLAB documentation for details on working with structures.

Model Icons
The fields common to all Model icons appear in Table 7-1.

NOTE: Structure field names are case-sensitive. When you refer to a field in a command, you must type it exactly as shown in the table. This applies to all MATLAB structures.

Table 7-1 Fields common to all MPC Model icons. Field Name Type Contents

String defining the icon name.
A string that can be either:

• LTI – a linear time-invariant model in the standard Control Toolbox format. • STEP – a linear time-invariant step-response model in the MPC Tools format. • MDL – a Simulink model, usually nonlinear.
Value

Structure containing the model data. Its form depends on the model type. See “LTI Model” on page 7-5, “STEP Model” on page 7-6, or “MDL Model” on page 7-6 String containing the date and time the icon was created. Character array containing the icon notes.

Rev Notes

7-4

Icon Data Structures

The following sections detail the contents of the Model.Value field for each model type.

LTI Model
The Value field of Table 7-1 is a standard LTI object (see the Control Toolbox for details). MPC stores another structure in this LTI object’s UserData field. Table 7-2 defines its contents. Its primary use is to hold initial conditions and the class of each signal.

Table 7-2 Contents of the UserData field of an MPC LTI object. Field InputClass Contents 1 by nin cell array, where nin is the number of plant inputs. Each element is a 2-character string designating the type of signal (’MV’, ’MD’, or 'UD’). 1 by nout cell array, where nout is the number of plant outputs. Each element is a 2-character string designating the type of signal ('CV' or 'UO’). nx by 1 vector of initial values for the model states, where nx is the system order (number of states). nu by 1 vector of initial values for the model inputs, where nu is the number of inputs. ny by 1 vector of initial values for the model outputs, where ny is the number of outputs. nx by 1 vector of initial time-derivatives of the model states.

OutputClass

x0

u0

y0

f0

7-5

7

Worksheet Icons

STEP Model
In this case the Value field of Table 7-1 is a structure. Table 7-3 details its contents.
Table 7-3 Contents of a STEP model’s Value field. Field StepData Contents Matrix of step-response model data. See “step format” in the MPC Tools documentation for details. 1 by nin cell array, where nin is the number of plant inputs. Each element is the name of an input signal (a string). 1 by nout cell array, where nout is the number of plant outputs. Each element is the name of an output signal (a string). Sampling period of the step-response model (a scalar). A structure with two fields, which are the same as the first two fields of Table 7-2.

InputName

OutputName

Ts

UserData

MDL Model
The Value field is a structure. See Table 7-4 for details.
Table 7-4 Contents of a MDL model icon’s Value field. Field MDLname InputName Contents The name of the Simulink.MDL file defining the model. 1 by nin cell array, where nin is the number of plant inputs. Each element is the name of an input signal (a string).

7-6

Icon Data Structures

Table 7-4 Contents of a MDL model icon’s Value field. Field OutputName Contents 1 by nout cell array, where nout is the number of plant

outputs. Each element is the name of an output signal (a string).
Ts Sampling period (a scalar). Usually zero, i.e., a

continuous-time model.
UserData A structure with ten fields. The first six are the same as in Table 7-2. The remaining four indicate the

variables held constant in the steady-state calculation (MPC Trim, see page 3-4). The field names are iu, iy, ix, and idx, corresponding to the inputs, outputs, states, and derivatives, respectively. Each field is a vector. Vector elements are 1 or 0, depending on whether the corresponding variable was held or not.

Controller Icons
Each controller icon contains the information shown in Table 7-5.
Table 7-5 Fields common to all MPC controller icons. Field Name Type Contents

String defining the icon name.
LMPC – Linear MPC (currently the only valid controller type. A string.).

Value

The contents depend on whether MPC’s internal model is LTI or STEP. See “LTI Internal Model” on page 7-8, and “STEP Internal Model” on page 7-9. String containing date and time icon was created. Character array containing the icon notes. Name of the Model icon used to design the controller.

Rev Notes ModelName

7-7

7

Worksheet Icons

LTI Internal Model
In this case, the Value field is the MPC internal model in a standard LTI, discrete state-space format (i.e., an LTI object). The object’s UserData field contains a structure defining additional controller parameters. See Table 7-6 for its contents.
Table 7-6 Structure of LMPC Value.UserData. Field InputClass Contents 1 by nin cell array, where nin is the number of plant inputs. Each element is a 2-character string designating the type of signal (’MV’, ’MD’, or 'UD’). 1 by nout cell array, where nout is the number of plant outputs. Each element is a 2-character string designating the type of signal ('CV' or 'UO’). nx by 1 vector of initial values for the model states, where nx is the system order (number of states). nu by 1 vector of initial values for the model inputs, where nu is the number of inputs. ny by 1 vector of initial values for the model outputs, where ny is the number of outputs. nx by 1 vector of initial time-derivatives of the model states.

OutputClass

x0

u0

y0

f0

P M

Prediction horizon (a scalar). Number of moves (if a scalar) or block durations (if a row vector). Row vector of output weights, length ny. 1 by 2 cell array, {ymin, ymax}. where ymin is a row vector of lower bounds, and ymax is a row vector of upper bounds. Vectors are length ny. Row vector of input weights, length nu.

ywt ylim

uwt

7-8

Icon Data Structures

Table 7-6 Structure of LMPC Value.UserData. Field ulim Contents

1 by 3 cell array, {umin, umax, dumax}. where umin is a row vector of lower bounds, and umax is a row vector of upper bounds, and dumax is the rate-of-change bound. Vectors are length nu. Disturbance estimator gain matrix. See MPC Tools documentation for details. A structure MPC uses to determine which signals are to be anticipated.

Kest

Anti

STEP Internal Model
In this case, the Value field is the STEP model structure shown in Table 7-3. Its UserData field is a structure that defines the controller parameters. Its fields are the same as Table 7-6, except that two of the initial condition fields(x0 and f0) are omitted.

Result Icons
Each Result structure contains the fields defined in Table 7-7. Table 7-7 Fields common to all MPC result icons. Field Name Type Contents

String defining the icon name.
A string that can be either:

• LSIM – result of a closed-loop simulation with a LMPC controller icon. • OLSIM – result of an open-loop simulation.
Plant

Name of the model icon that was the “Plant” in the simulation (a string).

7-9

7

Worksheet Icons

Table 7-7 Fields common to all MPC result icons. Field MPC Contents

Name of the controller icon that was the “Controller” in the simulation (a string). Null if the simulation was open-loop. Column vector of times at which results were obtained. Length N.
N by nu matrix of manipulated variables (MVs) at each time, where nu is the number of MVs. N by nv matrix of measured disturbances (MDs) at each time, where nv is the number of MDs. May be empty (nv=0). N by nw matrix of unmeasured disturbances (UDs) at each time, where nw is the number of UDs. May be empty (nw=0). N by ny matrix of outputs at each time, where ny is the

t

u

v

w

y

number of outputs.
r SimCond N by ny matrix of output setpoints at each time.

Structure containing a record of the simulation conditions. See Table 7-8. Cell array, nin by 1, where nin is the number of inputs (nin=nu+nv+nw). Each element is a signal name (string). They are arranged in the order [u v w], i.e., the first nu correspond to the columns of u, the next nv to the columns of v, and the final nw to the columns of w. Cell array, ny by 1. Each element is a signal name for the corresponding column in y. String containing date and time icon was created. Character array containing the icon notes.

InputName

OutputName

Rev Notes

7-10

Icon Data Structures

Table 7-8 Simulation Condition Structure. Field Time Type Contents

Simulation elapsed time (i.e., duration specified by user).
A string that can be either:

• CL – result of a closed-loop simulation. • OL – result of an open-loop simulation.
R

If the simulation was open-loop, this is empty. Otherwise it is a nout by 1 cell array defining the setpoint trajectory for each output (where nout is the number of outputs). The format is that required by the MPC GUI function SIG2MAT. (This also applies to U and N below.) An nin by 1 cell array defining the input trajectories for the nin inputs. If the simulation was closed loop, all MV trajectories in U are ignored, i.e., they are instead calculated by MPC. An nout by 1 cell array defining the measurement noise trajectories.

U

N

7-11

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->