Documentation Center

  • Trial Software
  • Product Updates

mpc

Create MPC controller

Syntax

MPCobj=mpc(plant)
MPCobj=mpc(plant,ts)
MPCobj=mpc(plant,ts,p)
MPCobj=mpc(plant,ts,p,m)
MPCobj=mpc(plant,ts,p,m,W)
MPCobj=mpc(plant,ts,p,m,W,MV,OV,DV)
MPCobj=mpc(models,ts,p,m,W,MV,OV,DV)

Description

MPCobj=mpc(plant) creates an MPC controller based on the discrete-time model plant. The model can be specified either as an LTI object, or as an object in System Identification Toolbox™ format. See Identify Plant from Data.

MPCobj=mpc(plant,ts) specifies the sampling time ts for the MPC controller. A continuous-time plant is discretized with sampling time ts. A discrete-time plant is resampled if its sampling time is different than the controller's sampling time ts. If plant is a discrete-time model with unspecified sampling time, namely plant.ts=-1, then Model Predictive Control Toolbox™ software assumes that the plant is sampled with the controller's sampling time ts. ts has the same unit as the internal predictive plant model, i.e., plant.TimeUnit.

MPCobj=mpc(plant,ts,p) specifies the prediction horizon p.

MPCobj=mpc(plant,ts,p,m) specifies the control horizon m.

MPCobj=mpc(plant,ts,p,m,W) also specifies the structure W of input, input increments, and output weights (see Weights).

MPCobj=mpc(plant,ts,p,m,W,MV,OV,DV) also specifies limits on manipulated variables (MV) and output variables (OV), as well as equal concern relaxation values, units, etc. Names and units of input disturbances can be also specified in the optional input DV. The fields of structures MV, OV, and DV are described in ManipulatedVariables, in OutputVariables, and in DisturbanceVariables, respectively).

MPCobj=mpc(models,ts,p,m,W,MV,OV,DV) where model is a structure containing models for plant, unmeasured disturbances, measured disturbances, and nominal linearization values, as described in Model.

    Note   Other MPC properties are specified by using set(MPCobj,Property1, Value1,Property2,Value2,...) or MPCobj.Property=Value.

Construction and Initialization

An MPC controller is built in two steps. The first step happens at construction when the object constructor mpc is invoked, or properties are changed by a set command. At this first stage, only basic consistency checks are performed, such as dimensions of signals, weights, constraints, etc. The second step happens at initialization, namely when the object is used for the first time by methods such as mpcmove and sim, that require the full computation of the QP matrices and the estimator gain. At this second stage, further checks are performed, such as a test of observability of the overall extended model.

Informative messages are displayed in the command window in both phases, you can turn them on or off using the mpcverbosity command.

Properties

All the parameters defining the MPC control law (prediction horizon, weights, constraints, etc.) are stored in an MPC object, whose properties are listed in the following table (MPC Controller Object ).

MPC Controller Object

Property

Description

ManipulatedVariables (or MV or Manipulated or Input )

Input and input-rate upper and lower bounds, ECR values, names, units, and input target

OutputVariables (or OV or Controlled or Output )

Output upper and lower bounds, ECR values, names, units

DisturbanceVariables (or DV or Disturbance )

Disturbance names and units

Weights

Weights defining the performance function

Model

Plant, input disturbance, and output noise models, and nominal conditions.

Ts

Controller's sampling time

Optimizer

Parameters for the QP solver

PredictionHorizon

Prediction horizon

ControlHorizon

Number of free control moves or vector of blocking moves

History

Creation time

Notes

Text or comments about the MPC controller object

UserData

Any additional data

MPCData (private)

Matrices for the QP problem and other accessorial data

Version (private)

Model Predictive Control Toolbox version number

ManipulatedVariables

ManipulatedVariables (or MV or Manipulated or Input) is an nu-dimensional array of structures (nu = number of manipulated variables), one per manipulated variable. Each structure has the fields described in the following table (Structure ManipulatedVariables), where p denotes the prediction horizon.

Structure ManipulatedVariables

Field Name

Content

Default

Min

1 to p dimensional vector of lower constraints on a manipulated variable u

-Inf

Max

1 to p dimensional vector of upper constraints on a manipulated variable u

Inf

MinECR

1 to p dimensional vector describing the equal concern for the relaxation of the lower constraints on u

0

MaxECR

1 to p dimensional vector describing the equal concern for the relaxation of the upper constraints on u

0

Target

1 to p dimensional vector of target values for the input variable u

'nominal'

RateMin

1 to p dimensional vector of lower constraints on the rate of a manipulated variable u

-Inf if problem is unconstrained, otherwise -10

RateMax

1 to p dimensional vector of upper constraints on the rate of a manipulated variable u

Inf

RateMinECR

1 to p dimensional vector describing the equal concern for the relaxation of the lower constraints on the rate of u

0

RateMaxECR

1 to p dimensional vector describing the equal concern for the relaxation of the upper constraints on the rate of u

0

Name

Name of input signal. This is inherited from InputName of the LTI plant model.

InputName of LTI plant model

Units

String specifying the measurement units for the manipulated variable

''

    Note   Rates refer to the difference Δu(k)=u(k)-u(k-1). Constraints and weights based on derivatives du/dt of continuous-time input signals must be properly reformulated for the discrete-time difference Δu(k), using the approximation du/dt ≅ Δu(k)/Ts.

OutputVariables

OutputVariables (or OV or Controlled or Output) is an ny-dimensional array of structures (ny = number of outputs), one per output signal. Each structure has the fields described in the following table (Structure OutputVariables), where p denotes the prediction horizon.

Structure OutputVariables

Field Name

Content

Default

Min

1 to p dimensional vector of lower constraints on an output y

-Inf

Max

1 to p dimensional vector of upper constraints on an output y

Inf

MinECR

1 to p dimensional vector describing the equal concern for the relaxation of the lower constraints on an output y

1

MaxECR

1 to p dimensional vector describing the equal concern for the relaxation of the upper constraints on an output y

1

Name

Name of output signal. This is inherited from OutputName of the LTI plant model.

OutputName of LTI plant model

Units

String specifying the measurement units for the measured output

''

Integrator

Magnitude of integrated white noise on the output channel (0=no integrator)

[]

In order to reject constant disturbances due for instance to gain nonlinearities, the default output disturbance model used in Model Predictive Control Toolbox software is a collection of integrators driven by white noise on measured outputs (see Output Disturbance Model). 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. By following such order, an output integrator is added per measured outputs, unless there is a violation of observability, or you force it by zeroing the corresponding value in OutputVariables.Integrators).

By default, OutputVariables.Integrators is empty on all outputs. This enforces the default action of Model Predictive Control Toolbox software, namely add integrators on measured outputs, do not add integrators on unmeasured outputs. By setting the entry of OutputVariables(i).Integrators to zero, no attempt will be made to add integrated white noise on the i-th output . On the contrary, by setting the entry of OutputVariables(i).Integrators to one, an attempt will be made to add integrated white noise on the i-th output (see getoutdist).

DisturbanceVariables

DisturbanceVariables (or DV or Disturbance) is an (nv+nd)-dimensional array of structures (nv = number of measured input disturbances, nd = number of unmeasured input disturbances), one per input disturbance. Each structure has the fields described in the following table (Structure DisturbanceVariables).

Structure DisturbanceVariables

Field Name

Content

Default

Name

Name of input signal. This is inherited from InputName of the LTI plant model.

InputName of LTI plant model

Units

String specifying the measurement units for the manipulated variable

''

The order of the disturbance signals within the array DisturbanceVariables is the following: the first nv entries relate to measured input disturbances, the last nd entries relate to unmeasured input disturbances.

    Note   The Name properties of ManipulatedVariables, OutputVariables, and DisturbanceVariables are read only. You can set signal names in the Model.Plant.InputName and Model.Plant.OutputNameproperties of the MPC object, for instance by using the method setname.

Weights

Weights is the structure defining the QP weighting matrices. Unlike the InputSpecs and OutputSpecs, which are arrays of structures, W is a single structure containing four fields. The values of these fields depend on whether you are using the standard quadratic cost function (see Standard Form) or the alternative cost function (see Alternative Cost Function).

Standard Cost Function

The table below, Weights for the Standard Cost Function (MATLAB Structure), lists the content of the four fields where p denotes the prediction horizon, nu the number of manipulated variables, ny the number of output variables.

The fields ManipulatedVariables, ManipulatedVariablesRate, and OutputVariables are arrays with nu, nu, and ny columns, respectively. If weights are time invariant, then ManipulatedVariables, ManipulatedVariablesRate, and OutputVariables are row vectors. However, for time-varying weights, each field is a matrix with up to p rows. If the number of rows is less than the prediction horizon, p, the object constructor duplicates the last row to create a matrix with p rows.

Weights for the Standard Cost Function (MATLAB Structure)

Field Name

Content

Default

ManipulatedVariables (or MV or Manipulated or Input)

(1 to p)-by-nu dimensional array of input weights

zeros(1,nu)

ManipulatedVariablesRate (or MVRate or ManipulatedRate or InputRate)

(1 to p)-by-nu dimensional array of input-rate weights

0.1*ones(1,nu)

OutputVariables (or OV or Controlled or Output)

(1 to p)-by-ny dimensional array of output weights

1 (The default for output weights is the following: if nuny, all outputs are weighted with unit weight; if nu<ny, nu outputs are weighted with unit weight (with preference given to measured outputs), while the remaining outputs receive zero weight.)

ECR

Weight on the slack variable ɛ used for softening the constraints

1e5*(max weight)

The default ECR weight is 105 times the largest weight specified in ManipulatedVariables, ManipulatedVariablesRate, and OutputVariables.

    Note   All weights must be greater than or equal to zero. If all weights on manipulated variable increments are strictly positive, the resulting QP problem is always strictly convex. If some of those weights are zero, the Hessian matrix of the QP problem may become only positive semidefinite. In order to keep the QP problem always strictly convex, if the condition number of the Hessian matrix KΔU is larger than 1012, the quantity 10*sqrt(eps) is added on each diagonal term. This may only occur when all input rates are not weighted (WΔu=0) (see Cost Function).

Alternative Cost Function

You can specify off-diagonal Q and R weight matrices in the cost function. To accomplish this, you must define the fields ManipulatedVariables, ManipulatedVariablesRate, and OutputVariables as cell arrays, each containing a single positive-semi-definite matrix of the appropriate size. Specifically, OutputVariables must be a cell array containing the ny-by-ny Q matrix, ManipulatedVariables must be a cell array containing the nu-by-nu Ru matrix, and ManipulatedVariablesRate must be a cell array containing the nu-by-nu RΔu matrix (see Alternative Cost Function) and the mpcweightsdemo example). You can abbreviate the field names as shown in Weights for the Standard Cost Function (MATLAB Structure). You can also use diagonal weights (as defined in Weights for the Standard Cost Function (MATLAB Structure)) for one or more of these fields. If you omit a field, the object constructor uses the defaults shown in Weights for the Standard Cost Function (MATLAB Structure).

For example, you can specify off-diagonal weights, as follows

MPCobj.Weights.OutputVariables={Q};
MPCobj.Weights.ManipulatedVariables={Ru};
MPCobj.Weights.ManipulatedVariablesRate={Rdu};

where Q=Q. Ru=Ru, and Rdu = RΔu are positive semidefinite matrices.

    Note   You cannot specify off-diagonal time-varying weights.

Model

The property Model specifies plant, input disturbance, and output noise models, and nominal conditions, according to the model setup described in State Estimation. It is specified through a structure containing the fields reported in Structure Model Describing the Models Used by MPC.

Structure Model Describing the Models Used by MPC

Field Name

Content

Default

Plant

LTI model or identified linear model of the plant

No default

Disturbance

LTI model describing color of input disturbances

An integrator on each Unmeasured input channel

Noise

LTI model describing color of plant output measurement noise

Unit white noise on each measured output = identity static gain

Nominal

Structure containing the state, input, and output values where Model.Plant is linearized

See Nominal Values at Operating Point.

    Note   Direct feedthrough from manipulated variables to any output in Model.Plant is not allowed. See Prediction Model.

The type of input and output signals is assigned either through the InputGroup and OutputGroup properties of Model.Plant, or, more conveniently, through function setmpcsignals, according to the nomenclature described in Input Groups in Plant Model and Output Groups in Plant Model.

Input Groups in Plant Model

Name

Value

ManipulatedVariables (or MV or Manipulated or Input)

Indices of manipulated variables

MeasuredDisturbances (or MD or Measured)

Indices of measured disturbances

UnmeasuredDisturbances (or UD or Unmeasured)

Indices of unmeasured disturbances

Output Groups in Plant Model

Name

Value

MeasuredOutputs (or MO or Measured)

Indices of measured outputs

UnmeasuredOutputs (or UO or Unmeasured)

Indices of unmeasured outputs

By default, all inputs are manipulated variables, and all outputs are measured.

    Note   With this current release, the InputGroup and OutputGroup properties of LTI objects are defined as structures, rather than cell arrays (see the Control System Toolbox™ documentation for more details).

The structure Nominal contains the nominal values for states, inputs, outputs and state derivatives/differences at the operating point where Model.Plant was linearized. The fields are reported in Nominal Values at Operating Point (see Offsets).

Nominal Values at Operating Point

Field

Description

Default

X

Plant state at operating point

0

U

Plant input at operating point, including manipulated variables, measured and unmeasured disturbances

0

Y

Plant output at operating point

0

DX

For continuous-time models, DX is the state derivative at operating point: DX=f(X,U). For discrete-time models, DX=x(k+1)-x(k)=f(X,U)-X.

0

Ts

Sampling time of the MPC controller. By default, if Model.Plant is a discrete-time model, Ts=Model.Plant.ts. For continuous-time plant models, you must specify a sampling time for the MPC controller.

Optimizer

Parameters for the QP optimization. Optimizer is a structure with the fields reported in the following table (Optimizer Properties).

Optimizer Properties

Field

Description

Default

MaxIter

Maximum number of iterations allowed in the QP solver

200

Trace

On/off

'off'

Solver

QP solver used (only 'ActiveSet')

'ActiveSet'

MinOutputECR

Minimum positive value allowed for OutputMinECR and OutputMaxECR

1e-10

MinOutputECR is a positive scalar used to specify the minimum allowed ECR for output constraints. If values smaller than MinOutputECR are provided in the OutputVariables property of the MPC objects a warning message is issued and the value is raised to MinOutputECR.

PredictionHorizon

PredictionHorizon is an integer value expressing the number p of sampling steps of prediction.

ControlHorizon

ControlHorizon is either a number of free control moves, or a vector of blocking moves (see Optimization Variables).

History

History stores the time the MPC controller was created.

Notes

Notes stores text or comments as a cell array of strings.

UserData

Any additional data stored within the MPC controller object.

MPCData

MPCData is a private property of the MPC object used for storing intermediate operations, QP matrices, internal flags, etc.

Version

Version is a private property indicating the Model Predictive Control Toolbox version number.

Examples

Define an MPC controller based on the transfer function model s+1/(s2+2s), with sampling time Ts=0.1 s, and satisfying the input constraint -1≤ u ≤1:

Ts=.1;    %Sampling time
MV=struct('Min',-1,'Max',1);
p=20;
m=3;

mpc1=mpc(tf([1 1],[1 2 0]),Ts,p,m,[],MV);

See Also

|

Was this topic helpful?