Documentation Center |
Create MPC controller
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)
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.
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.
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 (or MV or Manipulated or Input) is an n_{u}-dimensional array of structures (n_{u} = 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)/T_{s}. |
OutputVariables (or OV or Controlled or Output) is an n_{y}-dimensional array of structures (n_{y} = 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:
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).
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 (or DV or Disturbance) is an (n_{v}+n_{d})-dimensional array of structures (n_{v} = number of measured input disturbances, n_{d} = 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 n_{v} entries relate to measured input disturbances, the last n_{d} 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 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).
The table below, Weights for the Standard Cost Function (MATLAB Structure), lists the content of the four fields where p denotes the prediction horizon, n_{u} the number of manipulated variables, n_{y} the number of output variables.
The fields ManipulatedVariables, ManipulatedVariablesRate, and OutputVariables are arrays with n_{u}, n_{u}, and n_{y} 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-n_{u} dimensional array of input weights | zeros(1,nu) |
ManipulatedVariablesRate (or MVRate or ManipulatedRate or InputRate) | (1 to p)-by-n_{u} dimensional array of input-rate weights | 0.1*ones(1,nu) |
OutputVariables (or OV or Controlled or Output) | (1 to p)-by-n_{y} dimensional array of output weights | 1 (The default for output weights is the following: if n_{u}≥n_{y}, all outputs are weighted with unit weight; if n_{u}<n_{y}, n_{u} 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 10^{5} 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 10^{12}, 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). |
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 n_{y}-by-n_{y} Q matrix, ManipulatedVariables must be a cell array containing the n_{u}-by-n_{u} R_{u} matrix, and ManipulatedVariablesRate must be a cell array containing the n_{u}-by-n_{u} 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=R_{u}, and Rdu = R_{Δ}_{u} are positive semidefinite matrices.
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 |
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 |
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.
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 is an integer value expressing the number p of sampling steps of prediction.
ControlHorizon is either a number of free control moves, or a vector of blocking moves (see Optimization Variables).
History stores the time the MPC controller was created.
Notes stores text or comments as a cell array of strings.
Any additional data stored within the MPC controller object.
MPCData is a private property of the MPC object used for storing intermediate operations, QP matrices, internal flags, etc.
Version is a private property indicating the Model Predictive Control Toolbox version number.
Define an MPC controller based on the transfer function model s+1/(s^{2}+2s), with sampling time T_{s}=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);