Main Content

Code Generation

Generate code and deploy controllers on real-time targets

Once you have validated a model predictive controller in Simulink® or MATLAB®, you can generate code and deploy it for real-time control applications. For more information, see Generate Code and Deploy Controller to Real-Time Targets.


expand all

Linear MPC

getCodeGenerationDataCreate data structures for mpcmoveCodeGeneration
mpcmoveCodeGenerationCompute optimal control moves with code generation support

Nonlinear MPC

getCodeGenerationDataCreate data structures for nlmpcmoveCodeGeneration
nlmpcmoveCodeGenerationCompute nonlinear MPC control moves with code generation support
buildMEXBuild MEX file that solves a (generic or multistage) nonlinear MPC control problem
mpcActiveSetSolverSolve quadratic programming problem using active-set algorithm
mpcActiveSetOptionsCreate default option set for mpcActiveSetSolver
mpcInteriorPointSolverSolve a quadratic programming problem using an interior-point algorithm
mpcInteriorPointOptionsCreate default option set for mpcInteriorPointSolver


expand all

MPC ControllerSimulate model predictive controller
Adaptive MPC ControllerSimulate adaptive and time-varying model predictive controllers
Explicit MPC ControllerExplicit model predictive controller
Multiple MPC ControllersSimulate switching between multiple implicit MPC controllers
Multiple Explicit MPC ControllersMultiple explicit MPC controllers
Nonlinear MPC ControllerSimulate nonlinear model predictive controllers
Adaptive Cruise Control SystemSimulate adaptive cruise control using model predictive controller
Lane Keeping Assist SystemSimulate lane-keeping assistance using adaptive model predictive controller
Path Following Control SystemSimulate path-following control using adaptive model predictive controller


Code Generation Basics

Generate Code and Deploy Controller to Real-Time Targets

Model Predictive Control Toolbox™ software provides code generation functionality for controllers designed in Simulink and MATLAB.

QP Solvers

The model predictive controller QP solvers convert an MPC optimization problem to a general form quadratic programming problem.

Simulink Code Generation

Simulation and Code Generation Using Simulink Coder

Simulate your MPC controller in Simulink and generate real-time code that uses either double or single precision signals.

Simulation and Structured Text Generation Using Simulink PLC Coder

Simulate your MPC controller in Simulink and generate structured text for programmable logic controllers.

Using MPC Controller Block Inside Function-Call and Triggered Subsystems

To ensure that an MPC controller works properly inside a Function-Call or triggered subsystem, configure the MPC Controller block to use inherited sample time and invoke the subsystem periodically with the same sample time defined in the MPC controller object.

MATLAB Code Generation

Generate Code to Compute Optimal MPC Moves in MATLAB

Generate C code to compute manipulated variable moves for real-time applications.

Solve Custom MPC Quadratic Programming Problem and Generate Code

You can implement a custom MPC control algorithm that supports C code generation in MATLAB using the built-in QP solver, mpcqpsolver.

CUDA Code Generation

Use the GPU to Compute MPC Moves in MATLAB

Simulate your MPC controller in MATLAB using the GPU.

Use the GPU to Simulate an MPC Controller in Simulink

Simulate your MPC controller in Simulink using the GPU.

Using Custom Solvers

Simulate and Generate Code for MPC Controller with Custom QP Solver

Generate code for a model predictive controller that uses a custom quadratic programming solver.

Implement MPC Controllers using Embotech FORCES PRO Solvers

Use Embotech FORCES PRO Solvers with the Model Predictive Control Toolbox to solve MPC problems and deploy controllers to real-time targets.

OPC Simulation

Real-Time Control with OPC Toolbox

Implement an online model predictive controller application using the OPC client supplied with the OPC Toolbox™.