Model Predictive Control Toolbox

Key Features

  • Design and simulation of model predictive controllers in MATLAB® and Simulink
  • Customization of constraints and weights with advisory tools for improved performance and robustness
  • Adaptive MPC control through run-time changes to internal plant model
  • Explicit MPC control  for applications with fast sample times using precomputed solutions
  • Control of plants over a wide range of operating conditions by switching between multiple model predictive controllers
  • Specialized model predictive control quadratic programming (QP) solver optimized for speed, efficiency, and robustness
  • Support for C-code generation with Simulink Coder™ and IEC 61131-3 Structured Text generation with Simulink PLC Coder™
MPC Controller block for designing and simulating model predictive controllers directly in Simulink.
MPC Controller block (red) for designing and simulating model predictive controllers directly in Simulink.

Designing and Simulating Model Predictive Controllers

Model predictive controllers can be used to optimize closed-loop system performance of MIMO plants subject to input and output constraints. Because they base their actions on an internal plant model, model predictive controllers can forecast future process behavior and compute the optimal control actions accordingly. The ability to model process interactions often enables model predictive controllers to outperform multiple PID control loops, which require individual tuning and other techniques to reduce loop coupling.

Model Predictive Control Toolbox provides functions, an app, and Simulink blocks for designing and simulating model predictive controllers in MATLAB and Simulink.

You can iteratively improve your controller design by defining an internal plant model, adjusting controller parameters such as weights and constraints, and simulating closed-loop system response to evaluate controller performance.

Getting Started with Model Predictive Control Toolbox 2:49
Use Model Predictive Control Toolbox™ to design and simulate model predictive controllers.

Defining Internal Plant Models

When designing a model predictive controller in Simulink, you can use Simulink Control Design™ to extract a linearized form of the Simulink model and automatically import it into the controller as the internal plant model.

Alternatively, you can use linear time-invariant (LTI) systems from Control System Toolbox™, such as a transfer function or a state-space model, to specify the internal plant model. Model Predictive Control Toolbox also lets you directly import models created from measured input-output data using System Identification Toolbox™.

Designing Controllers

Once you have defined the internal plant model, you can complete the design of your model predictive controller by specifying the following controller parameters:

  • Control interval (sample time)
  • Prediction and control horizons
  • Scale factors for plant inputs and outputs
  • Hard and soft constraints on manipulated variables, manipulated variable rates, and output variables
  • Weights on manipulated variables, manipulated variable rates, and output variables
  • Models that characterize measurement noise and unmeasured input and output disturbances
Dialog box for selecting a plant model and specifying the control interval (sample time), prediction horizon, and control horizon in Model Predictive Control Toolbox.
Dialog box for selecting a plant model and specifying the control interval (sample time), prediction horizon, and control horizon in Model Predictive Control Toolbox.
Dialog box for setting constraints on manipulated variables, manipulated variable rates, and output variables in Model Predictive Control Toolbox.
Dialog box for setting constraints on manipulated variables, manipulated variable rates, and output variables in Model Predictive Control Toolbox.

The toolbox supports time-varying constraints and weights, constraints on linear combinations of manipulated variables and output variables, terminal constraints and weights, and constraints in the form of linear off-diagonal weights. The toolbox also supports constraint softening.

Running Closed-Loop Simulations

You can use functions or the MPC Designer app to run closed-loop simulations of your model predictive controller against linear plant models. The app lets you set up multiple simulation scenarios. For each scenario, you can specify controller set points and disturbances by choosing from several common signal profiles. Examples are step, ramp, sine wave, and random signal.

Configuring and running a simulation to test a controller against a linear plant model in the MPC Designer app.
Configuring and running a simulation to test a controller against a linear plant model in the MPC Designer app.

To assess robustness under model mismatch, you can simulate a controller against a linear plant model that is different from the internal plant model used by the controller. You can also simulate multiple controller designs against the same plant model to see how different weight and constraint settings affect controller performance. With this toolbox, you also have the ability to disable constraints to evaluate characteristics of the closed-loop dynamics, such as stability and damping.

Using Simulink blocks provided with Model Predictive Control Toolbox, you can run closed-loop simulations of your model predictive controller against a nonlinear Simulink model. You can configure the blocks to accept run-time constraint and weight signals that are generated by other Simulink blocks.

Simulink model for running closed-loop simulations of a model predictive controller and a nonlinear plant model.
Simulink model for running closed-loop simulations of a model predictive controller and a nonlinear plant model, with controller constraints calculated by other Simulink blocks.

Adjusting Constraints, Weights, and State Estimation

Model Predictive Control Toolbox provides several tools to help you optimize controller performance by adjusting controller constraints and weights, as well as the models and gains used in state estimation.

Adjusting Weights with the Tuning Advisor

The toolbox includes the Tuning Advisor, which guides you through setting weights to improve controller performance. You can use the Tuning Advisor to:

  • Select a cost function that measures the difference between a reference signal and measured plant output, and then compute the cost function value for the baseline design
  • Compute sensitivities of the cost function to individual weights
  • Determine whether individual weights should be increased or decreased to improve controller performance
  • Adjust the weights and recompute the cost function value

By repeating this interactive process, you can systematically adjust controller weights to optimize controller performance.

Weight Tuning for Model Predictive Controllers 7:24
Use Tuning Adviser to adjust model predictive controller weights to improve controller performance.

Analyzing Constraints and Weights for Potential Run-Time Failures

The toolbox provides a diagnostic function for detecting potential stability and robustness issues with your model predictive controller, such as:

  • Model predictive controller or closed-loop system is unstable
  • QP optimization problem is ill-defined with an invalid Hessian matrix
  • Zero steady-state offset cannot be achieved
  • Hard and soft constraint settings may lead to infeasible optimization problems at run time

You can use this diagnostic tool to adjust controller weights and constraints during controller design to avoid run-time failures.

Results of diagnostic tests for potential model predictive controller run-time failures.
Results of diagnostic tests for potential model predictive controller run-time failures.

Using Custom State Estimation

The toolbox provides built-in state estimators for estimating controller states from measured outputs. If you have state measurements or prefer to use values estimated with a custom algorithm, the toolbox provides you with an option to do so.

Adjusting Run-Time Controller Performance

Model Predictive Control Toolbox supports monitoring run-time controller performance and adjusting run-time tuning parameters.

Monitoring Run-Time Controller Performance

Model predictive controllers formulate and solve a QP optimization problem at each computation step. The QP solver supplied with the toolbox is optimized for performance and robustness. It achieves convergence even when the optimization problem is ill-conditioned.

On rare occasions when the optimization may fail to converge due to process abnormalities, the MPC Controller block freezes the controller output at the previous value and lets you monitor optimization status at run time. You can access the optimization status signal to detect when an optimization fails to converge and then decide if a backup control strategy should be used.

The MPC Controller block also lets you access the optimal cost and control sequence at each computation step. You can use these signals to analyze controller performance and develop custom control strategies. For example, you can use optimal cost information for switching between two model predictive controllers whose outputs are restricted to discrete values.

Simulink model that uses the optimal cost signal to switch between two model predictive controllers whose outputs are restricted to discrete values.
Simulink model that uses the optimal cost signal to switch between two model predictive controllers whose outputs are restricted to discrete values. You can compare the reference signal (top right, red) and plant output (top right, blue) to evaluate controller performance. You can plot the manipulated variable—the controller output (bottom right, green)—to see when the control strategy switches between controllers.

Adjusting Weights at Run Time

The toolbox lets you adjust the run-time weights of your model predictive controller to optimize its performance at run time without redesigning or reimplementing it. To perform run-time controller tuning in Simulink, you would configure the MPC Controller block to accept the appropriate weights. You can also perform run-time controller tuning in MATLAB.

Model Predictive Control Toolbox provides access to the following run-time tuning parameters:

  • Weights on plant outputs
  • Weights on manipulated variables
  • Weights on manipulated variable rates
  • Weight on overall constraint softening
Simulink model for run-time tuning of model predictive controller parameters.
Simulink model for run-time tuning of model predictive controller parameters. Model Predictive Control Toolbox enables run-time tuning by changing weights on plant outputs, weights on manipulated variables, manipulated variable rates, and the weight on overall constraint softening.

Designing Adaptive Model Predictive Controllers

With Model Predictive Control Toolbox, you are able to design, simulate, and deploy adaptive MPC controllers for your plant. You can use an adaptive MPC controller to control a nonlinear plant across a wide operating range through run-time changes to an internal linear plant model. The toolbox provides a function and a Simulink block for simulating and implementing adaptive MPC controllers in MATLAB and Simulink, respectively. The toolbox also provides a built-in linear-time-varying Kalman filter with asymptotic stability guarantee for state estimation in adaptive model predictive controllers.

You can continuously estimate a linear plant model at run time with online parameter estimation capabilities of System Identification Toolbox. You can then use the estimated model for run-time updates to an internal plant model in an adaptive MPC controller. This approach lets you design controllers that can adapt to changes in plant dynamics as these changes happen.

Adaptive MPC Controller block for controlling nonlinear models over a wide operating range through run-time changes to an internal plant model.
Adaptive MPC Controller block (red) for controlling nonlinear models over a wide operating range through run-time changes to an internal plant model. Use System Identification Toolbox blocks to estimate a linear plant model at run time.

Generating Explicit Model Predictive Controllers

Model Predictive Toolbox enables you to design, simulate and deploy explicit MPC controllers for your plant. By using optimal solutions precomputed offline, explicit MPC controllers require fewer computations than traditional (implicit) model predictive controllers and are, therefore, useful for applications with fast sample times. You are able to generate an explicit MPC controller from a traditional model predictive controller, as well as simplify a generated explicit MPC controller for a reduced memory footprint. The toolbox also provides a function and a Simulink block for simulating and implementing a generated explicit model predictive controller in MATLAB and Simulink, respectively.

MATLAB code for creating an explicit MPC controller.
MATLAB code (top left) for creating an explicit MPC controller. The created controller can be used with an Explicit MPC Controller block (top right, red).

Controlling Plants Over a Range of Operating Conditions

You can use the Multiple MPC Controllers block for controlling a nonlinear Simulink plant model over a wide range of operating conditions. With this block you can design a model predictive controller for each operating point and switch between model predictive controllers at run time. The Multiple MPC Controllers block ensures bumpless control transfer from one model predictive controller to another. You can create linear plant models for controller design at each operating point either by linearizing a Simulink model with Simulink Control Design or by specifying the plant model directly. The toolbox also provides a function for switching multiple model predictive controllers in MATLAB.

Multiple MPC Controllers block for controlling nonlinear models over a wide operating range using multiple model predictive controllers with bumpless control transfer.
Multiple MPC Controllers block (red) for controlling nonlinear models over a wide operating range using multiple model predictive controllers with bumpless control transfer. With this block you can design a model predictive controller for each operating point and switch between model predictive controllers at run time.

Deploying Model Predictive Controllers

Model Predictive Control Toolbox provides two ways to deploy a controller in an application. One way is to use Simulink Coder or Simulink PLC Coder to generate C code or IEC61131-3 Structured Text, respectively, from Simulink blocks provided with the toolbox, and deploy the code to a supported target system for implementation or rapid prototyping. The toolbox provides a diagnostic function for estimating data memory size used by deployed controller at run time.

Hardware setup for rapid prototyping of a model predictive controller on PC-compatible hardware using Simulink Coder and Simulink Real-Time.
Hardware setup for rapid prototyping of a model predictive controller on PC-compatible hardware using Simulink Coder and Simulink Real-Time™.

Another way to deploy a controller in an application is to use OPC Toolbox™ to connect a controller operating in MATLAB directly to an OPC-compliant system.

System Identification and Control Using OPC Data 17:58
Improve process performance by designing and implementing a model predictive controller. Use OPC Toolbox™ and System Identification Toolbox™ to collect the input-output data and create a plant model.

Try Model Predictive Control Toolbox

Get trial software

Online Parameter Estimation and Adaptive Control

View webinar