Contenu principal

Code Generation

R2026b
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.

Functions

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

Generate MEX File

buildMEXBuild MEX file that solves an 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
setCustomSolverConfigures an MPC object to use the QP solver from Optimization Toolbox as a custom solver

Blocks

expand all

MPC Controller blockMPC ControllerSimulate model predictive controller
Data-Driven MPC Controller blockData-Driven MPC ControllerSimulate data-driven model predictive controller (Since R2026a)
Adaptive MPC Controller blockAdaptive MPC ControllerSimulate adaptive and time-varying model predictive controllers
Explicit MPC Controller blockExplicit MPC ControllerExplicit model predictive controller
Multiple MPC Controllers blockMultiple MPC ControllersSimulate switching between multiple implicit MPC controllers
Multiple Explicit MPC Controllers blockMultiple Explicit MPC ControllersMultiple explicit MPC controllers
Nonlinear MPC Controller blockNonlinear MPC ControllerSimulate nonlinear model predictive controllers
Multistage Nonlinear MPC Controller blockMultistage Nonlinear MPC ControllerSimulate multistage nonlinear model predictive controllers
Adaptive Cruise Control System blockAdaptive Cruise Control SystemSimulate adaptive cruise control using model predictive controller
Lane Keeping Assist System blockLane Keeping Assist SystemSimulate lane-keeping assistance using adaptive model predictive controller
Path Following Control System blockPath Following Control SystemSimulate path-following control using adaptive model predictive controller

Topics

Code Generation Basics

Code Generation from Simulink

Code Generation from MATLAB

CUDA Code Generation

Using Custom Solvers

OPC Simulation