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

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


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

Simulink Code Generation

MATLAB Code Generation

CUDA Code Generation

Using Custom Solvers

OPC Simulation