mpc matlab userguide

Upload: anncar1987

Post on 03-Jun-2018

220 views

Category:

Documents


1 download

TRANSCRIPT

  • 8/12/2019 MPC Matlab UserGuide

    1/276

    Model Predictive Control Toolbox

    Users Guide

    R2013b

    Alberto BemporadManfred MorariN. Lawrence Ricker

  • 8/12/2019 MPC Matlab UserGuide

    2/276

    How to Contact MathWorks

    www.mathworks.com Web

    comp.soft-sys.matlab Newsgroup

    www.mathworks.com/contact_TS.html Technical Support

    [email protected] Product enhancement suggestions

    [email protected] Bug reports

    [email protected] Documentation error reports

    [email protected] Order status, license renewals, passcodes

    [email protected] Sales, pricing, and general information

    508-647-7000 (Phone)

    508-647-7001 (Fax)

    The MathWorks, Inc.

    3 Apple Hill Drive

    Natick, MA 01760-2098

    For contact information about worldwide offices, see the MathWorks Web site.

    Model Predictive Control Toolbox Users Guide

    COPYRIGHT 20052013 by The MathWorks, Inc.

    The software described in this document is furnished under a license agreement. The software may be usedor copied only under the terms of the license agreement. No part of this manual may be photocopied orreproduced in any form without prior written consent from The MathWorks, Inc.

    FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentationby, for, or through the federal government of the United States. By accepting delivery of the Programor Documentation, the government hereby agrees that this software or documentation qualifies ascommercial computer software or commercial computer software documentation as such terms are usedor defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms andconditions of this Agreement and only those rights specified in this Agreement, shall pertain to and governthe use, modification, reproduction, release, performance, display, and disclosure of the Program andDocumentation by the federal government (or other entity acquiring for or through the federal government)and shall supersede any conflicting contractual terms or conditions. If this License fails to meet thegovernments needs or is inconsistent in any respect with federal procurement law, the government agreesto return the Program and Documentation, unused, to The MathWorks, Inc.

    Trademarks

    MATLAB and Simulink are registered trademarks of The MathWorks, Inc. Seewww.mathworks.com/trademarks for a list of additional trademarks. Other product or brandnames may be trademarks or registered trademarks of their respective holders.

    Patents

    MathWorks products are protected by one or more U.S. patents. Please see

    www.mathworks.com/patentsfor more information.

    http://www.mathworks.com/trademarkshttp://www.mathworks.com/patentshttp://www.mathworks.com/patentshttp://www.mathworks.com/trademarks
  • 8/12/2019 MPC Matlab UserGuide

    3/276

    Revision History

    October 2004 First printing New for Version 2.1 (Release 14SP1)

    March 2005 Online only Revised for Version 2.2 (Release 14SP2)September 2005 Online only Revised for Version 2.2.1 (Release 14SP3)March 2006 Online only Revised for Version 2.2.2 (Release 2006a)September 2006 Online only Revised for Version 2.2.3 (Release 2006b)March 2007 Online only Revised for Version 2.2.4 (Release 2007a)September 2007 Online only Revised for Version 2.3 (Release 2007b)March 2008 Online only Revised for Version 2.3.1 (Release 2008a)October 2008 Online only Revised for Version 3.0 (Release 2008b)March 2009 Online only Revised for Version 3.1 (Release 2009a)September 2009 Online only Revised for Version 3.1.1 (Release 2009b)March 2010 Online only Revised for Version 3.2 (Release 2010a)

    September 2010 Online only Revised for Version 3.2.1 (Release 2010b)April 2011 Online only Revised for Version 3.3 (Release 2011a)September 2011 Online only Revised for Version 4.0 (Release 2011b)March 2012 Online only Revised for Version 4.1 (Release 2012a)September 2012 Online only Revised for Version 4.1.1 (Release 2012b)March 2013 Online only Revised for Version 4.1.2 (Release R2013a)September 2013 Online only Revised for Version 4.1.3 (Release R2013b)

  • 8/12/2019 MPC Matlab UserGuide

    4/276

  • 8/12/2019 MPC Matlab UserGuide

    5/276

    Contents

    IntroductionHow Plants Are Used In Model Predictive Control . . . . 1-2

    Single-Input Single-Output (SISO) Plants . . . . . . . . . . . . . 1-2Multi-Input Multi-Output (MIMO) Plants . . . . . . . . . . . . . 1-5

    Blocking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12

    Typical Sampling Instant . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14

    Prediction and Control Horizons . . . . . . . . . . . . . . . . . . . . 1-18

    Model Predictive Control Problem Setup

    Prediction Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2

    Offsets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3

    Optimization Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5Standard Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5Alternative Cost Function . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7Terminal Weights and Constraints . . . . . . . . . . . . . . . . . . . 2-8Custom Constraints on Inputs and Outputs . . . . . . . . . . . . 2-11

    Terminal Weights and Constraints . . . . . . . . . . . . . . . . . . 2-12

    Custom Constraints on Inputs and Outputs . . . . . . . . . . 2-15

    Constraint Softening . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16

    v

  • 8/12/2019 MPC Matlab UserGuide

    6/276

    State Estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17Unmeasured (Input) Disturbance Model . . . . . . . . . . . . . . . 2-17Measurement Noise Model . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19Output Disturbance Model . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19State Observer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20

    QP Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23Prediction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23Optimization Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24Cost Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27

    Model Predictive Control Computation . . . . . . . . . . . . . . 2-29Unconstrained Model Predictive Control . . . . . . . . . . . . . . . 2-29Constrained Model Predictive Control . . . . . . . . . . . . . . . . . 2-29MPC QP Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-31

    Model Predictive Control Simulink Library

    3MPC Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2

    MPC Controller Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3

    MPC Controller Block Mask . . . . . . . . . . . . . . . . . . . . . . . . . 3-3MPC Controller Parameters . . . . . . . . . . . . . . . . . . . . . . . . . 3-4Connect Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5Optional Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6Input Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10Output Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11Look Ahead and Signals from the Workspace . . . . . . . . . . . 3-12Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13

    Generate Code and Deploy Controller to Real-Time

    Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14

    Multiple MPC Controllers Block . . . . . . . . . . . . . . . . . . . . 3-15Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15

    vi Contents

  • 8/12/2019 MPC Matlab UserGuide

    7/276

    Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15

    Relationship of Multiple MPC Controllers to MPC

    Controller Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16

    Listing the controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16Designing the controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16Defining controller switching . . . . . . . . . . . . . . . . . . . . . . . . 3-16Improving prediction accuracy . . . . . . . . . . . . . . . . . . . . . . . 3-17

    Case-Study Examples

    4Servomechanism Controller . . . . . . . . . . . . . . . . . . . . . . . . 4-2

    System Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2Control Objectives and Constraints . . . . . . . . . . . . . . . . . . . 4-4Defining the Plant Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4Controller Design Using MPCTOOL . . . . . . . . . . . . . . . . . . 4-5

    Using Model Predictive Control Toolbox Commands . . . . . 4-19Using MPC Tools in Simulink . . . . . . . . . . . . . . . . . . . . . . . 4-23

    Paper Machine Process Control . . . . . . . . . . . . . . . . . . . . . 4-27System Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27Linearizing the Nonlinear Model . . . . . . . . . . . . . . . . . . . . . 4-28MPC Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-30Controlling the Nonlinear Plant in Simulink . . . . . . . . . . . 4-37References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-40

    Transfer Bumplessly Between Manual and Automatic

    Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-41

    Coordinate Multiple Controllers at Different Operating

    Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-49

    Using Custom Constraints in Blending Process . . . . . . . 4-57About the Blending Process . . . . . . . . . . . . . . . . . . . . . . . . . 4-57MPC Controller with Custom Input/Output Constraints . . 4-58

    vii

  • 8/12/2019 MPC Matlab UserGuide

    8/276

    Refine Controller Tuning Weights Using the Tuning

    Advisor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-65

    Providing LQR Performance Using Terminal

    Penalty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-70References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-75

    Real-Time Control with OPC Toolbox . . . . . . . . . . . . . . . 4-76

    Simulation and Code Generation Using MPC Controller

    Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-81

    Setting Targets for Manipulated Variables . . . . . . . . . . . 4-86

    Specifying Alternative Cost Function with Off-Diagonal

    Weight Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-90

    Review Model Predictive Controller Design for

    Potential Stability and Robustness Issues . . . . . . . . . 4-96

    Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-116

    Reference for the Design Tool GUI

    5Working with the Design Tool . . . . . . . . . . . . . . . . . . . . . . 5-2

    Opening the MPC Design Tool . . . . . . . . . . . . . . . . . . . . . . . 5-2Creating a New MPC Design Task . . . . . . . . . . . . . . . . . . . 5-3Menu Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6

    Tree View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7Importing a Plant Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8Importing a Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14Exporting a Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16Signal Definition View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18Plant Models View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-23Controllers View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-25

    viii Contents

  • 8/12/2019 MPC Matlab UserGuide

    9/276

    Simulation Scenarios List . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-29Controller Specifications View . . . . . . . . . . . . . . . . . . . . . . . 5-32Simulation Scenario View . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-54

    Analyze Sensitivity Using the Tuning Advisor . . . . . . . . 5-63Defining the Performance Metric . . . . . . . . . . . . . . . . . . . . . 5-65Baseline Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-67Sensitivities and Tuning Advice . . . . . . . . . . . . . . . . . . . . . . 5-67Updating the Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-70Restoring Baseline Tuning . . . . . . . . . . . . . . . . . . . . . . . . . . 5-70Modal Dialog Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-70Scenarios for Performance Measurement . . . . . . . . . . . . . . 5-70

    Customize Response Plots . . . . . . . . . . . . . . . . . . . . . . . . . . 5-71Data Markers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-72Displaying Multiple Scenarios . . . . . . . . . . . . . . . . . . . . . . . 5-73Viewing Selected Variables . . . . . . . . . . . . . . . . . . . . . . . . . 5-74Grouping Variables in a Single Plot . . . . . . . . . . . . . . . . . . . 5-75Normalizing Response Amplitudes . . . . . . . . . . . . . . . . . . . 5-75

    Index

    ix

  • 8/12/2019 MPC Matlab UserGuide

    10/276

    x Contents

    1

  • 8/12/2019 MPC Matlab UserGuide

    11/276

    1

    Introduction

    How Plants Are Used In Model Predictive Control on page 1-2

    Blocking on page 1-12

    Typical Sampling Instant on page 1-14

    Prediction and Control Horizons on page 1-18

  • 8/12/2019 MPC Matlab UserGuide

    12/276

    1 Introduction

    How Plants Are Used In Model Predictive ControlIn this section...

    Single-Input Single-Output (SISO) Plants on page 1-2

    Multi-Input Multi-Output (MIMO) Plants on page 1-5

    Single-Input Single-Output (SISO) PlantsThe typical Model Predictive Control Toolbox application involves a plant

    having multiple inputs and multiple outputs (MIMO).

    Consider the simpler single-input single-output (SISO) application shown in

    the following figure.

    Block Diagram of a SISO Model Predictive Control Toolbox Application

    The plant can be a manufacturing process, such as a unit operation in an oilrefinery, or a device, such as an electric motor. The main objective is to hold

    a singleoutput, y , at a reference value (or setpoint),r, by adjusting a single

    manipulated variable(or actuator)u. This is what is generally termed aSISO

    (single-input single-output) plant. The block labeled MPC represents a Model

    Predictive Controller designed to achieve the control objective.

    1-2

  • 8/12/2019 MPC Matlab UserGuide

    13/276

    How Plants Are Used In Model Predictive Control

    The following table summarizes the nomenclature used in the previous figure.

    Model Predictive Control Toolbox Signals

    Symbol Description

    d Unmeasured disturbance. This signal is unknown except for

    its effect on the plant output. The controller provides feedback

    compensation for such disturbances.

    r Setpoint (or reference). The target value for the output.

    u Manipulated variable (or actuator). The signal the controller

    adjusts in order to achieve its objectives.

    v Measured disturbance (optional). The controller provides

    feedforward compensation for such disturbances as they occur

    to minimize their impact on the output.

    y Output (or controlled variable). The signal to be held at thesetpoint. This is the true value, uncorrupted by measurement

    noise.

    y Measured output. The signal used to estimate the true value,

    y .

    z Measurement noise. The signal represents electrical noise,

    sampling errors, drifting calibration, and other effects that

    impair measurement precision and accuracy.

    The SISO plant actually has multiple inputs. In addition to the manipulated

    variable input, u, there may be:

    An unmeasured disturbance, d. The unmeasured disturbance is alwayspresent. It is an independentinputnot affected by the controller or the

    plant. It represents all the unknown, unpredictable events that upset plant

    operation. In the context of Model Predictive Control, it can also representunmodeled dynamics. When such an event occurs, the only indication is

    its effect on the measured output, y, which is fed backto the controller,

    as shown in the previous figure. Some applications have unmeasured

    disturbances only.

    1-3

  • 8/12/2019 MPC Matlab UserGuide

    14/276

    1 Introduction

    Ameasured disturbance, v. It is an independent input that affects y . Incontrast tod, the controller receives the measured v directly, as shown in

    the previous figure. Receiving the signal directly allows the controller to

    compensate forvs impact on y immediately rather than waiting until the

    effect appears in the y measurement. This approach is called feedforward

    control.

    Model Predictive Control Toolbox design always provides feedback

    compensation for unmeasured disturbances andfeedforwardcompensationfor any measured disturbance.

    The design requires a model of the impact that v and u have on y

    (symbolically, v y and u y ). It uses this plant modelto calculate the

    u adjustments needed to keep y at its setpoint.

    This calculation considers the effect of any known constraints on theadjustments (typically an actuator upper or lower bound or a constraint on

    how rapidly u can vary). You can also specify bounds on y . The ability

    to create such constraint specifications is a distinguishing feature of Model

    Predictive Control Toolbox design and can be particularly valuable when you

    have multiple control objectives to be achieved via multiple adjustments (a

    MIMO plant). In the context of a SISO system, such constraint handling is

    often termed as anti-windup.

    If the plant model is accurate, the plant responds quickly to adjustments

    in u, and no constraints are encountered, feedforward compensation can

    counteract the impact ofv perfectly. In reality, model imperfections, physical

    limitations, and unmeasured disturbances cause the y to deviate from its

    setpoint. Therefore, Model Predictive Control Toolbox design includes a

    disturbance model( d y ) toestimate dand predictits impact on y . It then

    uses its u y model to calculate appropriate adjustments (feedback). Thiscalculation also considers the known constraints.

    Variousnoiseeffects can corrupt the measurement. The signalz in theBlock

    Diagram of a SISO Model Predictive Control Toolbox Application on page

    1-2figure represents such effects. Theses effects can vary randomly with a

    zero mean, or can exhibit a nonzero, drifting bias. Model Predictive Control

    1-4

  • 8/12/2019 MPC Matlab UserGuide

    15/276

    How Plants Are Used In Model Predictive Control

    Toolbox design uses a z y model in combination with its d y model toremove the estimated noise component (filtering).

    The preceding feedforward/feedback actions comprise the controllers

    regulator mode. The design also provides a servomode, i.e., it adjustsu 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 futuresetpoint variations can beanticipated,i.e., known in advance. If so, it provides

    feedforward compensation for these.

    Multi-Input Multi-Output (MIMO) PlantsOne advantage of Model Predictive Control Toolbox design (relative to

    classical multi-loop control) is that it generalizes directly to plants having

    multiple inputs and outputs. Moreover, the plant can benon-square, i.e.,

    having an unequal number of actuators and outputs. Industrial applications

    involving hundreds of actuators and controller outputs have been reported.

    The main challenge is to tune the controller to achieve multiple objectives. For

    example, if there are several outputs to be controlled, it might be necessary

    to prioritize so that the controller provides accurate setpoint tracking for

    the most important output, sacrificing others when necessary, e.g., when it

    encounters constraints. Model Predictive Control Toolbox features supportsuch prioritization.

    Optimization and ConstraintsAs discussed in more detail in Optimization Problem on page 2-5, the Model

    Predictive Control Toolbox controller solves an optimization problem much

    like the LQG optimal control described in the Control System Toolbox

    product. The main difference is that the Model Predictive Control Toolboxoptimization problem includes explicitconstraintson u and y, and it optimizes

    over a finite horizon.

    Setpoint Tracking. Consider first a case with no constraints. A primarycontrol objective is to force the plant outputs to track their setpoints.

    1-5

  • 8/12/2019 MPC Matlab UserGuide

    16/276

    1 Introduction

    Specifically, the controller predicts how much each output will deviate fromits setpoint within the prediction horizon. It multiplies each deviation by

    the outputs weight, and computes the weighted sum of squared deviations,

    Sy

    (k), as follows:

    S k w r k i y k iy jy

    j j

    j

    n

    i

    P y

    ( ) [ ( ) ( )]= + +{ }==

    11

    2

    wherek is the current sampling interval, k+iis a future sampling interval

    (within the prediction horizon), Pis the prediction horizon, ny

    is the number

    of plant outputs, wjy

    is theweightfor outputj, and[ ( ) ( )]r k i y k ij j+ + is thepredicted deviation at future instant k+i.

    If w wj

    y

    i j

    y

    , the controller does its best to trackrj, sacrificing ri tracking

    if necessary. If wjy =0 , on the other hand, the controller completely ignores

    deviationsrj yj .

    Choosing the weights is a critical step. You will usually need to tune your

    controller, varying the weights to achieve the desired behavior.

    As an example, consider the following figure, which depicts a type of chemical

    reactor (a CSTR). Feed enters continuously with reactant concentrationCAi.

    A reaction takes place inside the vessel at temperatureT. Product exits

    continuously, and contains residual reactant at concentration CA

    (

  • 8/12/2019 MPC Matlab UserGuide

    17/276

    How Plants Are Used In Model Predictive Control

    CSTR Schematic

    From the Model Predictive Control Toolbox point of view,Tand CA

    would be

    plant outputs, andCAi

    and Tcwould be inputs. More specifically, C

    Aiwould be

    an independent disturbance input, and Tcwould be a manipulated variable

    (actuator).

    There is one manipulated variable (the coolant temperature), so its impossible

    to hold both Tand CA at setpoints. ControllingTwould usually be a highpriority. Thus, you might set the output weight forTmuch larger than that

    forCA. In fact, you might set theCAweight to zero, allowing CAto move freely

    within an acceptable operating region(to be defined by constraints).

    Move Suppression. If the controller focuses exclusively on setpointtracking, it might choose to make large manipulated-variable adjustments.

    These could be impossible to achieve. They could also accelerate equipment

    wear or lead to control system instability.

    Thus, the Model Predictive Controller also monitors a weighted sum of

    controller adjustments, calculated according to the following equation:

    S k w u k iu ju

    jj

    n

    i

    M mv

    === + { }( ) ( )1

    11

    2

    whereMis the control horizon, nmv is the number of manipulated variables,

    uj(k+i 1) is the predicted adjustment (i.e., move) in manipulated variable

    j at future (or current) sampling intervalk+i 1, and wj

    u is a weight,

    which must be zero or positive. Increasing wj

    u forces the controller to make

    1-7

    1

  • 8/12/2019 MPC Matlab UserGuide

    18/276

    1 Introduction

    smaller, more cautious uj moves. In many cases (but not all) this will havethe following effects:

    The controllers setpoint tracking will degrade.

    The controller will be less sensitive to prediction inaccuracies (i.e., morerobust).

    Setpoints on Manipulated Variables. In most applications, the controllersmanipulated variables (MVs) should move freely (within a constrained region)

    to compensate for disturbances and stepoint changes. An attempt to hold an

    MV at a point within the region would degrade output setpoint tracking.

    On the other hand, some plants have more MVs than output setpoints. In

    such a plant, if all manipulated variables were allowed to move freely, the

    MV values needed to achieve a particular setpoint or to reject a particular

    disturbance would be non-unique. Thus, the MVs would drift within the

    operating space.

    A common approach is to define setpoints for extra MVs. These setpoints

    usually represent operating conditions that improve safety, economic return,

    etc. Model Predictive Control Toolbox design includes an additional term to

    accommodate such cases, as follows:

    S k w u u k iu ju j jj

    n

    i

    M mv

    ( ) [ ( )]= + { }== 1

    11

    2

    where uj is the manipulated variable setpoint (nominal value) for thejth MV,

    and wju is the corresponding weight.

    Constraints. Constraints may be eitherhardor soft. A hard constraint mustnot be violated. Unfortunately, under some conditions a constraint violationmight be unavoidable (e.g., an unexpected, large disturbance), and a realistic

    controller must allow for this.

    Model Predictive Control Toolbox software does so by softeningeach

    constraint, making a violation mathematically acceptable, though

    1-8

  • 8/12/2019 MPC Matlab UserGuide

    19/276

    1 I d

  • 8/12/2019 MPC Matlab UserGuide

    20/276

    1 Introduction

    Ksampling periods withKpoles at z = 0. This delay absorption increases

    the plant model order.

    If the plant contains significant delays, you must specify an appropriate

    controller sample time. If the controller sample time is too large, you may not

    achieve the desired controller performance. However, if you sample the plant

    too fast, delay absorption leads to a high-order controller. Such a controller

    can have a large memory footprint, which can cause difficulty if you generate

    code for a real-time target. Also, high-order controllers can have numerical

    precision issues.

    BlockingIn figureController State at the kth Sampling Instant on page 1-15(b),

    M= 4 and P= 9, and the controller is optimizing the first Mmoves of the

    prediction horizon, after which the manipulated variable remains constant for

    the remaining PM= 5 sampling instants.

    The following figure shows an alternative blocked strategyagain with 4

    planned movesin which the first occurs at sampling instant k, the next at

    k+2, the next atk+4, and the final atk+6. Ablockis one or more successive

    sampling periods during which the manipulated variable is constant. The

    block durationsare the number of sampling periods in each block. In figure

    Blocking Example with Four Moves on page 1-12the block durations are 2, 2,

    2, and 3. (Their sum must equalP.)

    1-10

    H Pl t A U d I M d l P di ti C t l

  • 8/12/2019 MPC Matlab UserGuide

    21/276

    How Plants Are Used In Model Predictive Control

    Blocking Example with Four Moves

    As for the default (unblocked) mode, only the current move, uk

    , actually goes

    to the plant. Thus, as shown in the figure above, the controller has made a

    plant adjustment at each sampling instant.

    So why use blocking? WhenP>> M(as is generally recommended), and all

    Mmoves 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 oftenleads to smoother adjustments, all other things being equal.

    See the subsequent case study examples and the literature for more discussion

    and MIMO design guidelines.

    1-11

    1 Introduction

  • 8/12/2019 MPC Matlab UserGuide

    22/276

    1 Introduction

    BlockingIn figureController State at the kth Sampling Instant on page 1-15(b),

    M= 4 and P= 9, and the controller is optimizing the first Mmoves of the

    prediction horizon, after which the manipulated variable remains constant for

    the remaining PM= 5 sampling instants.

    The following figure shows an alternative blocked strategyagain with 4

    planned movesin which the first occurs at sampling instant k, the next at

    k+2, the next atk+4, and the final atk+6. Ablockis one or more successive

    sampling periods during which the manipulated variable is constant. The

    block durationsare the number of sampling periods in each block. In figure

    Blocking Example with Four Moves on page 1-12the block durations are 2, 2,

    2, and 3. (Their sum must equalP.)

    Blocking Example with Four Moves

    As for the default (unblocked) mode, only the current move, uk, actually goes

    to the plant. Thus, as shown in the figure above, the controller has made a

    plant adjustment at each sampling instant.

    So why use blocking? WhenP>> M(as is generally recommended), and all

    Mmoves are at the beginning of the horizon, the moves tend to be larger

    1-12

    Blocking

  • 8/12/2019 MPC Matlab UserGuide

    23/276

    Blocking

    (because all but the final move last just one sampling period). Blocking often

    leads to smoother adjustments, all other things being equal.

    See the subsequent case study examples and the literature for more discussion

    and MIMO design guidelines.

    1-13

    1 Introduction

  • 8/12/2019 MPC Matlab UserGuide

    24/276

    1 Introduction

    Typical Sampling InstantModel Predictive Control Toolbox design generates a discrete-time

    controllerone that takes action at regularly spaced, discrete time instants.

    Thesampling instantsare the times at which the controller acts. The interval

    separating successive sampling instants is thesampling period, t (also

    called thecontrol interval). This section provides more details on the events

    occuring at each sampling instant.

    1-14

    Typical Sampling Instant

  • 8/12/2019 MPC Matlab UserGuide

    25/276

    yp p g

    Controller State at the kth Sampling Instant

    Thefigure,Controller State at thekth Sampling Instant on page 1-15, shows

    thestate of a hypothetical SISO model preditive control system. This system

    hasbeen operating for many sampling instants. Integerk represents the

    current instant. The latest measured output, yk, and previous measurements,

    yk1

    , yk2, ..., are known and are the filled circles in the figure Controller

    1-15

    1 Introduction

  • 8/12/2019 MPC Matlab UserGuide

    26/276

    State at thekth Sampling Instant on page 1-15(a). If there is a measured

    disturbance, its current and past values would be known (not shown).

    FigureController State at thekth Sampling Instant on page 1-15(b) shows

    the controllers previous moves, uk4

    , ..., uk1

    , as filled circles. As is usually

    the case, azero-order hold receives each move from the controller and holds it

    until the next sampling instant, causing the step-wise variations shown in

    figureController State at thekth Sampling Instant on page 1-15(b).

    To calculate its nextmove, ukthe controller operates in two phases:

    1 Estimation. In order to make an intelligent move, the controller needs

    to know the current state. This includes the true value of the controlled

    variable, yk , andany internal variables that influence the future trend,

    y yk k P+ +1 ,..., . To accomplish this, the controller uses all past and current

    measurements and the models u y , d y , v y , and z y . Fordetails, seePrediction on page 2-23andState Estimation on page 2-17.

    2 Optimization. Values of setpoints, measured disturbances, and constraints

    are specified over a finitehorizon of future sampling instants, k+1, k+2,

    ..., k+P, where P(a finite integer 1) is the prediction horizon see

    figureController State at the kth Sampling Instant on page 1-15(a). The

    controller computes Mmovesuk, u

    k+1, ... u

    k+M1, whereM( 1, P) is the

    control horizonsee figureController State at the kth Sampling Instant on

    page 1-15(b). In the hypothetical example shown in the figure,P= 9 andM= 4. The moves are the solution of a constrainedoptimization problem. For

    details of the formulation, seeOptimization Problem on page 2-5.

    In the example, the optimal moves are the four open circles in figure

    Controller State at the kth Sampling Instant on page 1-15(b). The controller

    predicts that the resulting output values will be the nine open circles in figure

    Controller State at the kth Sampling Instant on page 1-15 (a). Notice that

    both are within their constraints,uminuk+jumaxand yminyk+iymax.

    When its finished calculating, the controller sends move uk

    to the plant. The

    plant operates with this constant input until the next sampling instant, t

    time units later. The controller then obtains new measurements and totally

    revises its plan. This cycle repeats indefinitely.

    1-16

    Typical Sampling Instant

  • 8/12/2019 MPC Matlab UserGuide

    27/276

    Reformulation at each sampling instant is essential for good control. The

    predictions made during the optimization stage are imperfect. Periodic

    measurement feedback allows the controller to correct for this error and for

    unexpected disturbances.

    1-17

    1 Introduction

  • 8/12/2019 MPC Matlab UserGuide

    28/276

    Prediction and Control HorizonsYou might wonder why the controller bothers to optimize overPfuture

    sampling periods and calculateMfuture moves when it discards all but the

    first move in each cycle. Indeed, under certain conditions a controller using P

    =M= 1 would be identical to one using P= M= . More often, however, the

    horizon values have an important impact. Some examples follow:

    Constraints. Given sufficiently long horizons, the controller can see apotential constraint and avoid itor at least minimize its adverse effects.

    For example, consider the situation depicted below in which one controller

    objective is to keep plant output y below an upper boundymax

    . The current

    sampling instant isk, and the model predicts the upward trend yk+i

    . If the

    controller were looking P1

    steps ahead, it wouldnt be concerned by the

    constraint until more time had elapsed. If the prediction horizon were P2

    ,

    it would begin to take corrective action immediately.

    Plant delays. Suppose that the plant includes a pure time delay equivalenttoD sampling instants. In other words, the controllers current move, uk,

    has no effect until yk+D+1. In this situation it is essential that P>> D and M

  • 8/12/2019 MPC Matlab UserGuide

    29/276

    but a longer term response in the opposite direction. The optimization

    should focus primarily on the longer-term behavior. Otherwise, the

    controller would move in the wrong direction.

    Most designers choosePandMsuch that controller performance is insensitive

    to small adjustments in these horizons. Here are typical rules of thumb for a

    lag-dominant, stable process:

    1 Choose the control interval such that the plants open-loop settling time

    is approximately 2030 sampling periods (i.e., the sampling period isapproximately one fifth of the dominant time constant).

    2 Choose prediction horizon Pto be the number of sampling periods used

    in step 1.

    3 Use a relatively small control horizon M, e.g., 35.

    If performance is poor, you should examine other aspects of the optimizationproblem and/or check for inaccurate controller predictions.

    1-19

    1 Introduction

  • 8/12/2019 MPC Matlab UserGuide

    30/276

    1-20

  • 8/12/2019 MPC Matlab UserGuide

    31/276

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    32/276

    Prediction ModelThe linear model used in Model Predictive Control Toolbox software for

    prediction and optimization is depicted in the following figure.

    Model Used for Optimization

    The model consists of:

    A model of theplant to be controlled, whose inputs are the manipulatedvariables, the measured disturbances, and the unmeasured disturbances

    A model generating the unmeasureddisturbances

    Note When defining a model predictive controller, you must specify a plantmodel. You do not need to specify a model generating the disturbances, asthe controller setup assumes by default that unmeasured disturbances are

    generated by integrators driven by white noise (seeOutput Disturbance

    Model on page 2-19and setindist).

    The model of the plant is a linear time-invariant system described by the

    equations

    x(k+1) = Ax(k) + B u(k) + B v(k) + B d(k)

    y (k) = C x(k) +

    u v d

    m m DD v(k) + D d(k)

    y (k) = C x(k) + D v(k) + D d(k)

    vm dm

    u u vu du

    2-2

  • 8/12/2019 MPC Matlab UserGuide

    33/276

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    34/276

    at some nominal valuex=x0, u=u

    0, v=v

    0,d=d

    0. In these equations x denotes

    either the time derivative (continuous time model) or the successorx(k+1)(discrete time model). As an example, x

    0, u

    0, v

    0, d

    0may be obtained by using

    findopon a Simulink model describing the nonlinear dynamical equations,

    andA,B, C, D by usinglinearize. The linearized model has the form:

    + + x f x u v d f x u v d x x f x u v dx x( , , , ) ( , , , )( ) ( , , , )(0 0 0 0 0 0 0 0 0 0 0 0 0 uu uf x u v d v v f x u v d d d

    y

    v d

    + +

    0

    0 0 0 0 0 0 0 0 0 0

    )

    ( , , , )( ) ( , , , )( )

    + + h x u v d h x u v d x x h x u v d ux u( , , , ) ( , , , )( ) ( , , , )(0 0 0 0 0 0 0 0 0 0 0 0 0 + +

    u

    h x u v d v v h x u v d d dv d

    0

    0 0 0 0 0 0 0 0 0 0

    )

    ( , , , )( ) ( , , , )( )

    The model matrices A, B, C, D are readily obtained from the Jacobian

    matrices appearing in the equations above.

    The linearized dynamics are affected by the constant termsF=f(x0, u0, v0,d0)

    andH=h(x0,u0, v0,d0). For this reason the model predictive control algorithm

    internally adds a measured disturbancev=1, so thatFandHcan be embeddedintoBvand Dv, respectively, as additional columns.

    Nonzero offset values d0 for unmeasured disturbances, while relevant for

    obtaining the linearized model matrices, are not relevant for the model

    predictive control problem setup. In fact, onlydd0can be estimated from

    output measurements.

    2-4

    Optimization Problem

  • 8/12/2019 MPC Matlab UserGuide

    35/276

    Optimization ProblemIn this section...

    Standard Form on page 2-5

    Alternative Cost Function on page 2-7

    Terminal Weights and Constraints on page 2-8

    Custom Constraints on Inputs and Outputs on page 2-11

    Standard FormAssume that estimates ofx(k), xd(k) are available at time k (for state

    estimation, seeState Estimation on page 2-17). The model predictive control

    action at timek is obtained by solving the optimization problem:

    min ( ( ) ( ))( ),..., ( ),

    ,

    ++

    =+ + + +

    u k k u m k k

    i jy j jj

    w y k i k r k i

    1

    11

    1 1

    nn

    i ju jj

    n

    i ju j j

    y u

    w u k i k w u k i k u k i + + + + += ( )2

    2

    1, , ( ( ) ( ))target

    22

    1

    20

    1

    j

    n

    i

    p

    u

    ==

    + (2-3)

    In this equation, the subscript ( )jdenotes the j component of a vector,

    (k+i|k) denotes the value predicted for timek+i. This predictive value is

    based on the information available at time k. r(k) is the current sample of the

    output reference, subject to

    u i V i u k i k u i V i

    u i

    j ju

    j j ju

    j

    min min max max

    min

    ( ) ( ) ( ) ( )

    ( )

    +( ) +

    V i u k i k u i V i

    y i V

    ju

    j j ju

    j j

    min max max

    min mi

    +( ) +

    ( ) ( ) ( )

    ( ) nn max maxy

    j j jyi y k i k y i V i

    u k h k

    ( ) ( ) ( ) + +( ) +

    +( )=

    1

    0

    0

    where

    i = 0, ..., p1

    h = m, ..., p1

    2-5

  • 8/12/2019 MPC Matlab UserGuide

    36/276

    Optimization Problem

  • 8/12/2019 MPC Matlab UserGuide

    37/276

    input constraints are hard ( V V V V u u u umin max min max= = = = 0 ) and all output

    constraints are soft ( V Vy ymin max= = 1 ). Also, by default:

    e i ju

    i ju

    i jyw w w= { }105 max , , ., , , (2-4)

    The model predictive controller penalizes the worst case soft constraint

    violationthe one for which the inclusion of the non-zero slack variable

    (and the associated ECR value) allows the constraint to be satisfied atequality. As the model predictive controller attempts to minimize the cost

    function, it might increase violations of other soft constraints. You can use

    the ECR values to adjust the priority. Doing so allows you to determine which

    constraint is selected as the worst-case violation.

    Vectorutarget(k+i) is a setpoint for the input vector. You typically uses utargetwhen the number of inputs is greater than the number of outputs. Doing so

    specifies a preferred value for the inputs when all other objectives have beenachieved.

    As mentioned earlier, onlyu(k|k) is actually used to compute u(k). The

    remaining samples u(k+i|k) are discarded, and a new optimization problem

    based on ym

    (k+1) is solved at the next sampling stepk+1.

    The algorithm implemented in the Model Predictive Control Toolbox software

    uses different procedures depending on the presence of constraints. Ifthere are no constraints, the controller uses a fast analytical solution to

    obtain its optimal moves at each sampling instant. Otherwise, a Quadratic

    Programming (QP) solver is used. The matrices associated with the quadratic

    optimization problem are described inQP Matrices on page 2-23.

    If, for numerical reasons, the QP problem becomes infeasible, the

    second sample from the previous optimal sequence is applied, i.e.

    u(k)=u(k1)+*

    u(k|k1).

    Alternative Cost FunctionYou have the option to use the following quadratic objective instead of the

    standard one (Equation 2-3):

    2-7

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    38/276

    J u y k i k r k i Q y k i k r k i

    T

    i

    p

    ( , ) = + +( ) + +( )

    + +( ) + +( )

    =

    1 1 1 101

    + +( ) +( )

    + +( ) +( )

    u k i k R k i k

    u k i k u k i

    T

    u

    target +( ) +( ) +T

    u target eR u k i k u k i 2

    (2-5)

    In this equation,Qis anny

    by ny

    matrix, andRuand Ruare nuby numatrices,

    all positive semidefinite. Equation 2-5allows nonzero, off-diagonal weights

    but uses the same weights at each step in the prediction horizon.

    Equation 2-3andEquation 2-5are equivalent when:

    Weights wi jy, , wi j

    u, , and w

    i ju, are constant for alli = 1, ...,p.

    Matrices Q,Ruand Ruare diagonal with the squares of the weights wi jy, ,

    wi j

    u, , and w

    i ju, respectively as their diagonal elements.

    Note When using the alternative cost function, you must define the controllerusing MATLAB commands. The Model Predictive Control Toolbox design

    tool does not provide this option.

    Terminal Weights and Constraints

    Terminal weightsare the quadratic weightsWyon y(t+p) andWu on u(t+ p 1). The variablep is the prediction horizon. You apply the quadratic weights

    at timek +p only, such as the prediction horizons final step. Using terminal

    weights, you can achieve infinite horizon control that guarantees closed-loop

    stability. However, before using terminal weights, you must distinguish

    between problems with and without constraints.

    Terminal constraintsare the constraints ony(t+ p) andu(t+ p 1), wherep is

    the prediction horizon. You can use terminal constraints as an alternativeway to achieve closed-loop stability by defining a terminal region.

    Note You can use terminal weights and constraints only at thecommand-line. See setterminal.

    2-8

    Optimization Problem

  • 8/12/2019 MPC Matlab UserGuide

    39/276

    For the relatively simple unconstrained case, a terminal weight can make the

    finite-horizon Model Predictive Controller behave as if its prediction horizonwere infinite. For example, the MPC controller behavior is identical to a

    linear-quadratic regulator (LQR). The standard LQR derives from the cost

    function:

    J u x k i Qx k i u k i Ru k iT T

    i

    ( ) ( ) ( ) ( ) ( )

    1 11 (2-6)

    wherexis the vector of plant states in the standard state-space form:

    x(k + 1) = Ax+ Bu(k) (2-7)

    The LQR provides nominal stability provided matrices Q and R meet certain

    conditions. You can convert the LQR to a finite-horizon form as follows:

    J u x k i Qx k i u k i Ru k i x k p Q xT T

    i

    pT

    p( ) [ ( ) ( ) ( ) ( )] ( )

    1 11

    1

    (( )k p(2-8)

    whereQp

    , the terminal penalty matrix, is the solution of the Riccati equation:

    Q A Q A A Q B B Q B R B Q A QpT

    pT

    pT

    pT

    p ( ) 1 (2-9)

    You can obtain this solution using thelqr command in Control System

    Toolbox software.

    In general, Qp

    is a full (symmetric) matrix. You cannot use thestandard

    Model Predictive Control Toolbox cost functionto implement the LQR cost

    function. The only exception is for the first p 1 steps ifQand R are diagonal

    matrices. Also, you cannot use thealternative cost functionbecause it employs

    identical weights at each step in the horizon. Thus, by definition, the terminal

    weight differs from those in steps 1 to p 1. Instead, use the following steps:

    1 Augment the model (Equation 2-11) to include the weighted terminal

    states as auxiliary outputs:

    yaug(k) = Qcx(k)

    whereQcis the Cholesky factorization ofQpsuch thatQp= QcTQ

    c.

    2-9

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    40/276

    2 Define the auxiliary outputs yaug

    as unmeasured, and specify zero weight

    to them.

    3 Specify unity weight onyaug

    at the last step in the prediction horizon using

    setterminal.

    To make the Model Predictive Controller entirely equivalent to the LQR,

    use a control horizon equal to the prediction horizon. In an unconstrained

    application, you can use a short horizon and still achieve nominal stability.

    Thus, the horizon is no longer a parameter to be tuned.

    When the application includes constraints, the horizon selection becomes

    important. The constraints, which are usually softened, represent factors

    not considered in the LQR cost function. If a constraint becomes active,

    the control action deviates from the LQR (state feedback) behavior. If this

    behavior is not handled correctly in the controller design, the controller may

    destabilize the plant.

    For an in-depth discussion of design issues for constrained systems see[2].

    Depending on the situation, you might need to include terminal constraints

    to force the plant states into a defined region at the end of the horizon, after

    which the LQR can drive the plant signals to their targets. Usesetterminal

    to add such constraints to the controller definition.

    The standard (finite-horizon) Model Predictive Controller provides comparable

    performance, if the prediction horizon is long. You must tune the other

    controller parameters (weights, constraint softening, and control horizon)

    to achieve this performance.

    Tip Robustness to inaccurate model predictions is usually a more importantfactor than nominal performance in applications.

    Related Examples

    Implementing Infinite-Horizon LQR by Setting Terminal Weights in aFinite-Horizon MPC Formulation

    Providing LQR Performance Using Terminal Penalty on page 4-70

    2-10

    Optimization Problem

  • 8/12/2019 MPC Matlab UserGuide

    41/276

    Custom Constraints on Inputs and OutputsAs discussed previously, Model Predictive Control Toolbox software allows

    you to add upper and lower bounds on manipulated variables and plant

    outputs. You can also use the toolbox to constrain linear combinations of these

    signals. For example, you might want a particular manipulated variable to

    be greater than the weighted sum of two other manipulated variables. You

    provide such constraints in the form:

    Eu(k + j|k) +Fy(k + j|k) + Sv(k + j|k) g+ h

    In this equation,j = 0,...,p, E, F, S, g, andh are constants. The variablep is

    the prediction horizon, is the slack variable used for constraint softening

    (as inEquation 2-3). Thus, each row ofE, F, S, g, andh represents a linear

    constraintto be imposed at each prediction horizon step.

    Note Custom constraints can be specified only at the command line. See

    setconstraint.

    Related Examples

    MPC Control with Constraints on a Combination of Input and OutputSignals

    MPC Control of a Nonlinear Blending Process

    2-11

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    42/276

    Terminal Weights and Constraints

    Terminal weightsare the quadratic weightsWyon y(t+p) andWu on u(t+ p

    1). The variablep is the prediction horizon. You apply the quadratic weights

    at timek +p only, such as the prediction horizons final step. Using terminal

    weights, you can achieve infinite horizon control that guarantees closed-loop

    stability. However, before using terminal weights, you must distinguish

    between problems with and without constraints.

    Terminal constraintsare the constraints ony(t+ p) andu(t+ p 1), wherep isthe prediction horizon. You can use terminal constraints as an alternative

    way to achieve closed-loop stability by defining a terminal region.

    Note You can use terminal weights and constraints only at thecommand-line. See setterminal.

    For the relatively simple unconstrained case, a terminal weight can make the

    finite-horizon Model Predictive Controller behave as if its prediction horizon

    were infinite. For example, the MPC controller behavior is identical to a

    linear-quadratic regulator (LQR). The standard LQR derives from the cost

    function:

    J u x k i Qx k i u k i Ru k iT T

    i

    ( ) ( ) ( ) ( ) ( )

    1 1

    1 (2-10)

    wherexis the vector of plant states in the standard state-space form:

    x(k + 1) = Ax+ Bu(k) (2-11)

    The LQR provides nominal stability provided matrices Q and R meet certain

    conditions. You can convert the LQR to a finite-horizon form as follows:

    J u x k i Qx k i u k i Ru k i x k p Q xT T

    i

    pT

    p( ) [ ( ) ( ) ( ) ( )] ( )

    1 11

    1

    (( )k p(2-12)

    whereQp, the terminal penalty matrix, is the solution of the Riccati equation:

    2-12

    Terminal Weights and Constraints

  • 8/12/2019 MPC Matlab UserGuide

    43/276

    Q A Q A A Q B B Q B R B Q A QpT

    pT

    pT

    pT

    p ( ) 1 (2-13)

    You can obtain this solution using thelqr command in Control System

    Toolbox software.

    In general, Qpis a full (symmetric) matrix. You cannot use thestandard

    Model Predictive Control Toolbox cost functionto implement the LQR cost

    function. The only exception is for the first p 1 steps ifQand R are diagonal

    matrices. Also, you cannot use thealternative cost functionbecause it employs

    identical weights at each step in the horizon. Thus, by definition, the terminal

    weight differs from those in steps 1 to p 1. Instead, use the following steps:

    1 Augment the model (Equation 2-11) to include the weighted terminal

    states as auxiliary outputs:

    yaug(k) = Qcx(k)

    whereQcis the Cholesky factorization ofQpsuch thatQp= QcT

    Qc.

    2 Define the auxiliary outputs yaug

    as unmeasured, and specify zero weight

    to them.

    3 Specify unity weight onyaug

    at the last step in the prediction horizon using

    setterminal.

    To make the Model Predictive Controller entirely equivalent to the LQR,

    use a control horizon equal to the prediction horizon. In an unconstrained

    application, you can use a short horizon and still achieve nominal stability.

    Thus, the horizon is no longer a parameter to be tuned.

    When the application includes constraints, the horizon selection becomes

    important. The constraints, which are usually softened, represent factors

    not considered in the LQR cost function. If a constraint becomes active,

    the control action deviates from the LQR (state feedback) behavior. If this

    behavior is not handled correctly in the controller design, the controller maydestabilize the plant.

    For an in-depth discussion of design issues for constrained systems see[2].

    Depending on the situation, you might need to include terminal constraints

    to force the plant states into a defined region at the end of the horizon, after

    2-13

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    44/276

    which the LQR can drive the plant signals to their targets. Usesetterminal

    to add such constraints to the controller definition.

    The standard (finite-horizon) Model Predictive Controller provides comparable

    performance, if the prediction horizon is long. You must tune the other

    controller parameters (weights, constraint softening, and control horizon)

    to achieve this performance.

    Tip Robustness to inaccurate model predictions is usually a more importantfactor than nominal performance in applications.

    Related Examples

    Implementing Infinite-Horizon LQR by Setting Terminal Weights in aFinite-Horizon MPC Formulation

    Providing LQR Performance Using Terminal Penalty on page 4-70

    2-14

    Custom Constraints on Inputs and Outputs

  • 8/12/2019 MPC Matlab UserGuide

    45/276

    Custom Constraints on Inputs and Outputs

    As discussed previously, Model Predictive Control Toolbox software allows

    you to add upper and lower bounds on manipulated variables and plant

    outputs. You can also use the toolbox to constrain linear combinations of these

    signals. For example, you might want a particular manipulated variable to

    be greater than the weighted sum of two other manipulated variables. You

    provide such constraints in the form:

    Eu(k + j|k) +Fy(k + j|k) + Sv(k + j|k) g+ h

    In this equation, j = 0,...,p, E, F, S, g, andh are constants. The variablep is

    the prediction horizon, is the slack variable used for constraint softening

    (as inEquation 2-3). Thus, each row ofE, F, S, g, andh represents a linear

    constraint to be imposed at each prediction horizon step.

    Note Custom constraints can be specified only at the command line. Seesetconstraint.

    Related Examples

    MPC Control with Constraints on a Combination of Input and OutputSignals

    MPC Control of a Nonlinear Blending Process

    2-15

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    46/276

    Constraint Softening

    Ahardconstraint cannot be violated. Hard constraints are risky, especially

    for outputs, because the controller will ignore its other objectives in order to

    satisfy them. Also, the constraints might be impossible to satisfy in certain

    situations, in which case the calculations are mathematically infeasible.

    Model Predictive Control Toolbox software allows you to specify soft

    constraints. These can be violated, but you specify a violation tolerance for

    each (therelaxation band). SeeEquation 2-3, where is the slack variableused for constraint softening.

    Soft input and output constraints are scalars or vectors. The latter defines a

    time-varying relaxation band. The relaxation band is a relative tolerance, not

    a strict bound. In other words, the actual constraint violation can exceed the

    relaxation band. Specifying zero indicates a hard constraint.

    See Also

    getconstraint

    setconstraint

    Define Soft Output Constraints

    2-16

    State Estimation

  • 8/12/2019 MPC Matlab UserGuide

    47/276

    State Estimation

    In this section...

    Unmeasured (Input) Disturbance Model on page 2-17

    Measurement Noise Model on page 2-19

    Output Disturbance Model on page 2-19

    State Observer on page 2-20

    As the statesx(k),xd

    (k) are not directly measurable, predictions are obtained

    from a state estimator. In order to provide more flexibility, the estimator is

    based on the model depicted in the following figure.

    Model Used for State Estimation

    Unmeasured (Input) Disturbance ModelThe unmeasured disturbance model is also called the input disturbance

    model. It allows you to model random disturbances that enter the plant as

    unmeasured inputs,d(k), which affects the plant states and/or outputs. There

    is no limit on the number of disturbances contained within d(k), but the

    combination of plant and disturbance models must be observable. For more

    information, seeState Observer on page 2-20.

    2-17

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    48/276

    Thed(k) signal is the output of a time-invariant linear system

    x k A x k B n k

    d k C x k D n k

    d d d d d

    d d d d

    ( ) ( ) ( )

    ( ) ( ) ( )

    1

    wherend(k) is a zero-mean, unit variance, random Gaussian input andxd(k)

    are the input disturbance model states. You may supply the model in any

    convenient LTI form (e.g. transfer function). The Model Predictive Control

    Toolbox will convert it to the state-space model internally.

    The software discretizes xdto the controller sample time. Ifxdcontains any

    delays, the software replaces each delay ofKsampling periods with Kpoles

    at z = 0. This delay absorption increases the order ofxd, which increases

    the controller order.

    Ifxdcontains significant delays, you must specify an appropriate controller

    sample time. If the controller sample time is too large, you may not achieve

    the desired controller performance. However, if you samplexdtoo fast, delay

    absorption leads to a high-order controller. Such a controller can have a

    large memory footprint, which can cause difficulty if you generate code for a

    real-time target. Also, high-order controllers can have numerical precision

    issues.

    There are three ways to specify the input disturbance model. SupposeObj is

    an mpc object for a plant with two inputs and two outputs. One input is the

    manipulated variable and the other is an unmeasured disturbance. Let theinput disturbance model be an LTI system parameterized by matrices A

    d, B

    d,

    Cd, D

    d. If x

    dis length 2, then C

    dmust contain 1 row and 2 columns. Use one of

    the following methods to specify this input disturbance model:

    Set the Model.Disturbanceproperty ofObj.

    Obj.Model.Disturbance = ss(Ad,Bd,Cd,Dd);

    Call setindist

    DistMod = ss(Ad,Bd,Cd,Dd);

    setindist(Obj,'model',DistMod);

    2-18

    State Estimation

  • 8/12/2019 MPC Matlab UserGuide

    49/276

    Use the graphical design tool to import the disturbance model for the mpc

    object. For more information, seeInput Disturbances on page 5-49.

    A default disturbance model is created if the plant model includes a d(k) signal

    but no input disturbance model is specified. This guarantees asymptotic

    rejection of plant output disturbances.

    Use getindistto review the controllers input disturbance model.

    Measurement Noise ModelWe assume that the measured output vector y

    m(k) is corrupted by a

    measurement noisem(k), which is the output of the linear time-invariant

    system

    x k Ax k Bn k

    m k Cx k Dn k

    m m m

    m m

    ( ) ( ) ( )

    ( ) ( ) ( )

    + = +

    = +

    1

    The system described by these equations is driven by the random Gaussian

    noisenm(k), having zero mean and unit covariance matrix.

    Note The objective of the model predictive controller is to bring yu

    (k) and

    [ym

    (k)m(k)] as close as possible to the reference vector r(k). For this reason,

    the measurement noise model producingm(k) is not needed in the prediction

    model used for optimization described inPrediction Model on page 2-2.

    Output Disturbance ModelIn order to guarantee asymptotic rejection of output disturbances, the overall

    model is augmented by an output disturbance model. By default, the output

    disturbance model is a collection of integrators driven by white noise. Output

    integrators are added according to the following rule:

    1 Measured outputs are ordered by decreasing output weight (in case

    of time-varying weights, the sum of the absolute values over time is

    considered for each output channel, and in case of equal output weight the

    order within the output vector is followed).

    2-19

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    50/276

    2 By following such order, an output integrator is added per measured

    outputs, unless there is a violation of observability or you force (through theOutputVariables.Integratorsproperty described in OutputVariables

    in the Model Predictive Control Toolbox Reference).

    The software discretizes xd

    to the controller sample time. Ifxd

    contains any

    delays, the software replaces each delay ofKsampling periods with Kpoles

    at z = 0. This delay absorption increases the order ofxd

    , which increases

    the controller order.

    Ifxd

    contains significant delays, you must specify an appropriate controller

    sample time. If the controller sample time is too large, you may not achieve

    the desired controller performance. However, if you samplexd

    too fast, delay

    absorption leads to a high-order controller. Such a controller can have a

    large memory footprint, which can cause difficulty if you generate code for a

    real-time target. Also, high-order controllers can have numerical precision

    issues.

    An arbitrary output disturbance model can be specified through the function

    setoutdist. See also setoutdist for ways to remove the default output

    integrators.

    Use getoutdist to obtain the output disturbance model in the form used

    internally.

    State ObserverThe state observer is designed to provide estimates ofx(k),x

    d(k), x

    m(k), where

    x(k) is the state of the plant model, xd

    (k) is the overall state of the input

    and output disturbance model, xm

    (k) is the state of the measurement noise

    model. The estimates are computed from the measured outputym

    (k) by the

    linear state observer

    2-20

    State Estimation

  • 8/12/2019 MPC Matlab UserGuide

    51/276

    ( )

    ( )

    ( )

    ( )

    ( )

    ( )

    x k k

    x k k

    x k k

    x k k

    x k k

    x k k

    d

    m

    d

    m

    =

    1

    1

    1

    +

    +

    +

    +

    M y k y k

    x k k

    x k k

    x k k

    m m

    d

    m

    ( ( ) ( ))

    ( )

    ( )

    ( )

    1

    1

    1

    =

    + + +

    Ax k k B u k B v k B Cx k k

    Ax k k

    Ax k k

    u v d d

    d

    m

    ( ) ( ) ( ) ( )

    ( )

    ( )

    = + + + ( ) ( ) ( ) ( ) (y k C x k k D v k D Cx k k Cx k k

    m m vm dm d m1 1

    1)

    wherem denotes the rows ofC,D corresponding to measured outputs.

    To prevent numerical difficulties in the absence of unmeasured disturbances,

    the gainMis designed using Kalman filtering techniques (seekalmanin the

    Control System Toolbox documentation) on the extended model

    x k

    x k

    x k

    A B C

    A

    A

    x k

    xd

    m

    d( )

    ( )

    ( )

    ( )

    1

    1

    1

    0

    0 0

    0

    0

    dd

    m

    u v

    k

    x k

    B

    u k

    B

    v k( )

    ( )

    ( ) ( )

    0

    0

    0

    0

    B D

    B

    B

    B Bn k

    n k

    n k

    n k

    d u vd

    m

    u

    v

    0

    0

    0 0

    0

    0

    0

    ( )

    ( )

    ( )

    ( )

    y k C D C C

    x k

    x k

    x k

    D v k Dm m dm d

    m

    vm( )

    ( )

    ( )

    ( )

    ( ) ddm vm

    d

    m

    u

    v

    mD D D

    n k

    n k

    n k

    n k

    0

    ( )

    ( )

    ( )

    ( ) (2-14)

    wherenu(k) andnv(k) are additional unmeasured white noise disturbances

    having unit covariance matrix and zero mean, that are added on the vector of

    manipulated variables and the vector of measured disturbances, respectively,

    to ease the solvability of the Kalman filter design.

    2-21

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    52/276

    Note The overall state-space realization of the combined plant anddisturbance models must be observable for the state estimation design

    to succeed. Model Predictive Control Toolbox software first checks for

    observability of the plant, provided that this is given in state-space form.

    After all models have been converted to discrete-time, delay-free, state-space

    form and combined, observability of the overall extended model is checked

    (seesetestimand Construction and Initialization in the Model Predictive

    Control Toolbox Reference).

    Note also that observability is only checked numerically. Hence, for large

    models of badly conditioned system matrices, unobservability may be reported

    by the toolbox even if the system is observable.

    See also getestimand setestimfor details on the methods you can use to

    access and modify properties of the state estimator.

    2-22

    QP Matrices

  • 8/12/2019 MPC Matlab UserGuide

    53/276

    QP Matrices

    This section describes the matrices associated with the model predictive

    control optimization problem described inOptimization Problem on page 2-5.

    Prediction on page 2-23

    Optimization Variables on page 2-24

    Cost Function on page 2-26

    Constraints on page 2-27

    PredictionAssume that the disturbance model inEquation 2-1and Equation 2-2is a

    unit gain for example,d(k)=nd(k) is a white Gaussian noise). You can denote

    this problem as

    x xx

    A A B CA

    B B B Bv Bd

    du

    uv d

    , , , ,

    0 0 0BB D

    BC C D Cd d

    Then, the prediction model is:

    x(k+1) = Ax(k) +Buu(k) +Bvv(k)+Bdnd(k)

    y(k) = Cx(k) +Dvv(k) +Ddnd(k)

    Next, consider the problem of predicting the future trajectories of the model

    performed at timek=0. Setnd(i)=0 for all prediction instants i, and obtain

    y i C A x A B u u j B v hi i uj

    h

    v( | ) ( ) ( ) ( ) ( )0 0 11

    0

    = + +

    +

    =

    +

    =

    h

    i

    vD v i

    0

    1

    ( )

    This equation gives the solution

    2-23

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    54/276

    y

    y p

    S x S u S

    u

    u p

    x u u

    ( )

    ( )

    ( ) ( )

    ( )

    ( )

    1

    0 1

    0

    11

    = + +

    +

    H

    v

    v p

    v

    ( )

    ( )

    0

    where

    S

    CA

    CA

    CA

    S

    CB

    CB CAB

    CA B

    x

    p

    u

    u

    u u

    hu

    h

    pn ny x=

    =

    +

    =

    2

    1

    ,

    00

    1

    0 0

    0

    p

    u

    u

    u u u

    pn ny u

    S

    CB

    CB CAB CB

    =

    +

    CCA B CA B CB

    pn pn

    H

    hu

    h

    p hu

    h

    pu

    v

    y u

    =

    =

    0

    1

    0

    2

    ==

    CB D

    CAB CB D

    CA B CA B CA B D

    v v

    v v v

    pv

    pv

    pv v

    0 0

    0

    1 2 3

    +pn p ny v( ) .1

    Optimization VariablesLetm be the number of free control moves, and letz= [z

    0; ...;z

    m1]. Then,

    u

    u p

    J

    z

    z

    M

    m

    ( )

    ( )

    0

    1

    0

    1

    =

    (2-15)

    whereJMdepends on the choice of blocking moves. Together with the slack

    variable, vectorsz0, ..., zm1 constitute the free optimization variables ofthe optimization problem. In the case of systems with a single manipulated

    variables,z0, ..., zm1 are scalars.

    2-24

    QP Matrices

  • 8/12/2019 MPC Matlab UserGuide

    55/276

    BlockingMoves: Inputs and Input Iincrements for moves=[2 3 2]

    Consider the blocking moves depicted inBlocking Moves: Inputs and Input

    Iincrements for moves=[2 3 2] on page 2-25. This graph corresponds to the

    choicemoves=[2 3 2], or, equivalently,u(0)=u(1), u(2)=u(3)=u(4), u(5)=u(6),

    u(0)=z0, u(2)=z1, u(5)=z2, u(1)=u(3)=u(4)=u(6)=0.

    Then, the corresponding matrixJMis

    J

    I

    I

    I

    M=

    0 0

    0 0 0

    0 0

    0 0 00 0 0

    0 0

    0 0 0

    2-25

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    56/276

    Cost Function

    Standard Form on page 2-26

    Alternative Cost Function on page 2-27

    Standard FormThe function to be optimized is

    J zu

    u p

    u

    u p

    target

    target

    ( , )( )

    ( )

    ( )

    ( )

    =

    0

    1

    0

    1

    T

    u

    target

    targe

    Wu

    u p

    u

    u

    20

    1

    0( )

    ( )

    ( )

    tt

    T

    u

    p

    u

    u p

    Wu

    ( )

    ( )

    ( )

    +

    1

    0

    1

    2

    (( )

    ( )

    ( )

    ( )

    ( )

    0

    1

    1 1

    u p

    y

    y p

    r

    +

    r p

    W

    y

    y p

    r

    r p

    T

    y

    ( )

    ( )

    ( )

    ( )

    (

    21 1

    ))

    + 2

    where

    Wu w w w w w wu u

    nu

    pu

    pu

    pu= diag 0 1 0 2 0 1 1 1 2 1, , , , ,, ,..., ,..., , ,..., ,,

    , , , ,, ,..., ,..., ,

    nu

    u unu

    pu

    p

    u

    W u w w w w wu

    ( )=

    diag 0 1 0 2 0 1 1 1,, ,

    , , , ,

    ,...,

    , ,..., ,...,

    2 1

    1 1 1 2 1

    up n

    u

    y yn

    yp

    w

    w w w w

    u

    Wyy

    ( )=diag 11 2

    ypy

    p nyw w

    y, ,...,, ,( ) (2-16)

    Finally, after substitutingu(k),u(k),y(k), J(z) can be rewritten as

    J z z K z

    r

    r p

    K

    v

    v p

    Tu

    T

    r( , )

    ( )

    ( )

    ( )

    ( )

    = + +

    +

    2 2

    1 0

    + +

    +

    T

    vT

    u

    target

    target

    T

    utK u K

    u

    u p

    K x( )

    ( )

    ( )

    (1

    0

    1

    00)T xK z

    + constant (2-17)

    Note You may want the QP problem to remain strictly convex. If thecondition number of the Hessian matrix KU is larger than 10

    12, add the

    quantity10*sqrt(eps)on each diagonal term. You can use this solution only

    when all input rates are unpenalized (Wu=0) (see Weights in the Model

    Predictive Control Toolbox reference documentation).

    2-26

    QP Matrices

  • 8/12/2019 MPC Matlab UserGuide

    57/276

    Alternative Cost Function

    If you are using the alternative cost function shown inEquation 2-5,Equation2-16is replaced by the following:

    W R R

    W R R

    W Q

    u u u

    u u u

    y

    = ( )

    = ( )

    =

    blkdiag

    blkdiag

    blkdiag

    ,...,

    ,...,

    ,.

    ..., Q( ) (2-18)

    In this case, the block-diagonal matrices repeatp times, for example, once foreach step in the prediction horizon.

    You also have the option to use a combination of the standard and alternative

    forms. See Weights in the Model Predictive Control Toolbox reference

    documentation for more details.

    ConstraintsNext, consider the limits on inputs, input increments, and outputs along

    with the constraint0.

    y V

    y p V p

    u V

    u

    y

    y

    u

    min min

    min min

    min min

    min

    ( ) ( )

    ( ) ( )

    ( ) ( )

    (

    1 1

    0 0

    pp V p

    u V

    u p V p

    u

    u

    u

    1 1

    0 0

    1

    ) ( )

    ( ) ( )

    ( ) (

    min

    min min

    min min

    11

    1

    0

    1

    )

    ( )

    ( )

    ( )

    ( )

    y

    y p

    u

    u p

    u

    u p

    y V

    ( )

    ( )

    ( )max max

    0

    1

    1

    + yy

    y

    u

    u

    y p V p

    u V

    u p V

    ( )

    ( ) ( )

    ( ) ( )

    ( ) (

    max max

    max max

    max max

    1

    0 0

    1

    +

    +

    +

    pp

    u V

    u p V p

    u

    u

    +

    +

    1

    0 0

    1 1

    )

    ( ) ( )

    ( ) ( )

    max max

    max max

    Note To reduce computational effort, the controller automatically eliminatesextraneous constraints, such as infinite bounds. Thus, the constraint set used

    in real time may be much smaller than that suggested in this section.

    2-27

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    58/276

    Similar to what you did for the cost function, you can substituteu(k), u(k),

    y(k), and obtain

    M z M M M

    v

    v p

    M u M xz v u x+ +

    + + lim

    ( )

    ( )

    ( ) ( )

    0

    1 0

    (2-19)

    In this case, matrices Mz,M,Mlim,Mv,Mu,Mxare obtained from the upper and

    lower bounds and ECR values.

    2-28

    Model Predictive Control Computation

    M d l P di ti C t l C t ti

  • 8/12/2019 MPC Matlab UserGuide

    59/276

    Model Predictive Control Computation

    This section describes how the model predictive control optimization

    problem is solved at each time step k (in mpcmove, mpc_sfun.mex, and

    mpcloop_engine.mex). This solution uses the matrices built at initialization

    described inQP Matrices on page 2-23.

    Unconstrained Model Predictive Control on page 2-29

    Constrained Model Predictive Control on page 2-29

    MPC QP Solver on page 2-29

    Unconstrained Model Predictive ControlThe optimal solution is computed analytically

    z K

    r

    r pK

    v

    v pK uu

    T

    r v*

    ( )

    ( )

    ( )

    ( )(=

    +

    + 1

    1 0

    1 ))

    ( )

    ( )( )T u

    target

    target

    T

    ut T xK

    u

    u pK x K+

    +

    0

    10

    T

    and the model predictive controller setsu(k)=z*0, u(k)=u(k1)+u(k).

    Constrained Model Predictive Control

    The controller computes the optimal solution z* and* by solving thequadratic program (QP) described inEquation 2-17andEquation 2-19.

    MPC QP SolverThe model predictive controller QP solver converts an MPC optimization

    problem to the general QP form

    x

    TTMin f x x Hz( )12

    such that

    2-29

    2 Model Predictive Control Problem Setup

    A b

  • 8/12/2019 MPC Matlab UserGuide

    60/276

    Ax b

    wherexT=[zT ] are the decisions, His the Hessian matrix, A is a matrix

    of linear constraint coefficients, and b and f are vectors. TheHandA

    matrices are constants. The controller computes these during initialization

    and retrieves them from computer memory when needed. It computes the

    time-varyingb and fvectors at the beginning of each control instant.

    The toolbox uses the KWIK algorithm[1] to solve the QP problem, which

    requires the Hessian to be positive definite. In the very first control step,KWIK uses a cold start, in which the initial guess is the unconstrained

    solution described inModel Predictive Control Computation on page 2-29.

    If this xsatisfies the constraints, it is the optimal QP solution, x*, and

    the algorithm terminates. Otherwise this means that at least one of the

    linear inequality constraints must be satisfied as an equality. In this case,

    KWIK uses an efficient, numerically robust strategy to determine the active

    constraint set satisfying the standard optimality conditions. In the following

    control steps, KWIK uses a warm start. In this case, the active constraint setdetermined at the previous control step becomes the initial guess for the next.

    Although KWIK is robust, you should consider the following:

    One or more linear constraints might be violated slightly due to numericalround-off errors. The toolbox employs a nonadjustable relative tolerance.

    This tolerance allows a constraint to be violated by 10-6 times the

    magnitude of each term. Such violations are considered normal and do not

    generate warning messages.

    The toolbox also uses a nonadjustable tolerance when it tests a solution foroptimality.

    The search for the active constraint set is an iterative process. If theiterations reach a problem-dependent maximum, the algorithm terminates.

    If your problem includes hard constraints, these constraints might be

    infeasible (impossible to satisfy). If the algorithm detects infeasibility,it terminates immediately.

    In the last two situations, with an abnormal outcome to the search, the

    controller will retain the last successful control output. For more information,

    2-30

    Model Predictive Control Computation

    see the mpcmove command You can detect an abnormal outcome and override

  • 8/12/2019 MPC Matlab UserGuide

    61/276

    see, thempcmovecommand. You can detect an abnormal outcome and override

    the default behavior as you see fit.

    References[1] Schmid, C. and L.T. Biegler. Quadratic programming methods for

    reduced hessian SQP.Computers & Chemical Engineering. Vol. 18, Number

    9, 1994, pp. 817832.

    2-31

    2 Model Predictive Control Problem Setup

  • 8/12/2019 MPC Matlab UserGuide

    62/276

    2-32

    3

  • 8/12/2019 MPC Matlab UserGuide

    63/276

    Model Predictive ControlSimulink Library

    MPC Library on page 3-2

    MPC Controller Block on page 3-3

    Generate Code and Deploy Controller to Real-Time Targets on page 3-14

    Multiple MPC Controllers Block on page 3-15

    Relationship of Multiple MPC Controllers to MPC Controller Block onpage 3-16

    3 Model Predictive Control Simulink Library

    MPC Library

  • 8/12/2019 MPC Matlab UserGuide

    64/276

    MPC Library

    The MPC Simulink Library provides two blocks you can use to implement

    MPC control in Simulink, MPC Controller, and Multiple MPC Controllers.

    Access the library using the Simulink Library Browser or by typingmpclibat

    the command prompt. The following figure shows the library contents.

    MPC Simulink Library

    Once you have access to the library, you can add one of its blocks to your

    Simulink model by clicking-and-dragging or copying-and-pasting.

    3-2

    MPC Controller Block

    MPC Controller Block

  • 8/12/2019 MPC Matlab UserGuide

    65/276

    In this section...

    MPC Controller Block Mask on page 3-3

    MPC Controller Parameters on page 3-4

    Connect Signals on page 3-5

    Optional Ports on page 3-6

    Input Signals on page 3-10

    Output Signals on page 3-11

    Look Ahead and Signals from the Workspace on page 3-12

    Initialization on page 3-13

    The MPC Controller block represents a single MPC controller. You can adjust

    plant inputs to control plant outputs, accounting for constraints, includingactuator limits.

    MPC Controller Block MaskInsert an MPC Controller block in your Simulink model and then specify its

    properties. Double-click on the block to open its mask. The following figure

    shows the masks default settings. This section shows you how to configure

    the controller by:

    Specifying required parameters.

    Enabling optional inports and outputs.

    Connecting appropriate signals.

    3-3

    3 Model Predictive Control Simulink Library

  • 8/12/2019 MPC Matlab UserGuide

    66/276

    MPC Controller Block Mask

    MPC Controller Parameters

    Specify the MPC ControllerSpecify a valid MPC object in the MPC Controller field in one of two ways:

    Typethe name of an MPC object saved in your workspace. To review itssettings before running a simulation, click Design to load the named object

    into the MPC design tool.

    If your installation includes Simulink Control Design software, connecttheMPC Controller block to the plant it controls. Leaving the MPC

    3-4

    MPC Controller Block

    controller field empty, click Design. The block constructs a default MPC

    bj t b li i i th l t t th d f lt ti i t d t

  • 8/12/2019 MPC Matlab UserGuide

    67/276

    object by linearizing the plant at the default operating point and exports

    this defaults controller to the base workspace. If the default operating

    point is not the one you want, seeImporting a Plant Model on page 5-8

    for help with importing a new plant model.

    Note You can run closed-loop simulations with a linear plant in the designtool, allowing you to tune the controller parameters. To test the controller

    in Simulink, export it from the design tool to the workspace and run the

    simulation in Simulink.

    Indicate Initial Controller StateIf you do not specify an initial controller state, the controller uses a default

    initial condition in simulations. To change the initial state, specify an

    mpcstate object. See MPC Simulation Options Object in the Model Predictive

    Control Toolbox Reference.

    Connect SignalsThe MPC Controller requires at least two inputs and generates at least one

    output. There are also optional inputs and outputs. In most cases, the signals

    are vectors comprised of plant variables. Verify that the signal dimensions

    and the sequence of elements within each vector signal are consistent with

    your controller definition.

    Required inputsConnect the following to the indicated controller inports:

    Measured output variables (mo). Connect the measured plant outputvariables to the MPC Controllers mo inport as a vector signal, length

    nym

    1 . This provides the controllers feedback. References (ref). Your controllers prediction model contains n ny ym output

    variables. Each must have a reference target or setpoint value. Connect

    this 1-by-nyvector signal to the controllers ref inport. This inport defines

    3-5

    3 Model Predictive Control Simulink Library

    the reference values at the first step in the controllers prediction horizon.

    By default the controller assumes these values hold for the entire horizon

  • 8/12/2019 MPC Matlab UserGuide

    68/276

    By default, the controller assumes these values hold for the entire horizon.

    You can also preview reference signals at run-time. To activate reference

    previewing, supply the reference input as anNxnysignal, where1 N p ,and p is the prediction horizon length. The rows 1 to N define the reference

    values for time instantstk+1to tk+N in the prediction horizon. IfN< p, the

    last row is used for stepstk+n+1to tk+p. See the mpcpreviewexample.

    Required outportDuring operation, the controller updates the manipulated variable (mv)

    outport at each control interval. The mv outport defines adjustments to plant

    input variables. Connect this vector signal to the plant.

    Sample Time

    Every t( )

    0 time units, the MPC Controller samples its input signals and

    updates its output signals. This control interval is defined in theTs property

    of the MPC object.

    Optional Ports

    Feedforward compensation for measured disturbances

    If your prediction model includes measured disturbances, ensure thatMeasured disturbance is selected, and click Apply. Selecting this

    parameter adds an inport labeled md. Connect anN x nmdsignal, where:

    nmd 1 is the number of measured disturbances coming from the plant

    N 1 is the number of sampling instants for which you are supplyingmeasured disturbance values.

    IfN=1, the previewing is disabled and the signal must contain the vector of

    measured disturbances at the current controller sampli