Model predictive controller

A model predictive controller uses linear plant, disturbance, and noise models to estimate the controller state and predict future plant outputs. Using the predicted plant outputs, the controller solves a quadratic programming optimization problem to determine control moves.

For more information on the structure of model predictive controllers, see MPC Modeling.

creates a model predictive controller object based on the discrete-time prediction model
`mpcobj`

= mpc(`plant`

)`plant`

. The controller, `mpcobj`

, inherits its
control interval from `plant.Ts`

, and its time unit from
`plant.TimeUnit`

. All other controller properties are default values.
After you create the MPC controller, you can set its properties using dot
notation.

If `plant.Ts = -1`

, you must set the `Ts`

property of the controller to a positive value before designing and simulating your
controller.

creates a model predictive controller based on the specified plant model and sets the
controller sample time to `mpcobj`

= mpc(`plant`

,`ts`

)`ts`

, which corresponds to the
`Ts`

property of the controller. If `plant`

is
a:

Continuous-time model, then the controller discretizes the model for prediction using sample time

`ts`

A discrete-time model with a specified sample time, the controller resamples the plant for prediction using sample time

`ts`

A discrete-time model with an unspecified sample time (

`plant.Ts`

=`–1`

), it inherits sample time`ts`

when used for predictions

specifies the following controller properties. If any of these values are omitted or
empty, the default values apply.`mpcobj`

= mpc(`plant`

,`ts`

,`P`

,`M`

,`W`

,`MV`

,`OV`

,`DV`

)

`P`

sets the`PredictionHorizon`

property.`M`

sets the`ControlHorizon`

property.`W`

sets the`Weights`

property.`MV`

sets the`ManipulatedVariables`

property.`OV`

sets the`OutputVariables`

property.`DV`

sets the`DisturbanceVariables`

property.

creates a model predictive controller object based on the specified prediction model
set, which includes the plant, input disturbance, and measurement noise models along
with the nominal conditions at which the models were obtained. When you do not specify a
sample time, the plant model, `mpcobj`

= mpc(`model`

)`model.Plant`

, must be a discrete-time
model. This syntax sets the `Model`

property of the
controller.

creates a model predictive controller based on the specified plant model and sets the
controller sample time to `mpcobj`

= mpc(`model`

,`ts`

)`ts`

. If `model.Plant`

is a discrete-time LTI model with an unspecified sample time
(`model.Plant.Ts`

= `–1`

), it inherits sample time
`ts`

when used for predictions.

specifies additional controller properties. If any of these values are omitted or empty,
the default values apply.`mpcobj`

= mpc(`model`

,`Ts`

,`P`

,`M`

,`W`

,`MV`

,`OV`

,`DV`

)

`review` | Examine MPC controller for design errors and stability problems at run time |

`mpcmove` | Compute optimal control action |

`sim` | Simulate closed-loop/open-loop response to arbitrary reference and disturbance signals for implicit or explicit MPC |

`mpcstate` | MPC controller state |

`getCodeGenerationData` | Create data structures for mpcmoveCodeGeneration |

`generateExplicitMPC` | Convert implicit MPC controller to explicit MPC controller |

To minimize computational overhead, model predictive controller creation occurs in two
phases. The first happens at *creation* when you use the
`mpc`

function, or when you change a controller property. Creation
includes basic validity and consistency checks, such as signal dimensions and nonnegativity of
weights.

The second phase is *initialization*, which occurs when you use the
object for the first time in a simulation or analytical procedure. Initialization computes all
constant properties required for efficient numerical performance, such as matrices defining
the optimal control problem and state estimator gains. Additional, diagnostic checks occur
during initialization, such as verification that the controller states are observable.

By default, both phases display informative messages in the command window. You can turn
these messages on or off using the `mpcverbosity`

function.

You can also create model predictive controllers using the **MPC
Designer** app.

`get`

| `mpcprops`

| `mpcverbosity`

| `set`

| `setmpcsignals`