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.

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 (Since R2020a)
nlmpcmoveCodeGenerationCompute nonlinear MPC control moves with code generation support (Since R2020a)

Generate MEX File

buildMEXBuild MEX file that solves an MPC control problem (Since R2020a)
mpcActiveSetSolverSolve quadratic programming problem using active-set algorithm (Since R2020a)
mpcActiveSetOptionsCreate default option set for mpcActiveSetSolver (Since R2020a)
mpcInteriorPointSolverSolve a quadratic programming problem using an interior-point algorithm (Since R2020a)
mpcInteriorPointOptionsCreate default option set for mpcInteriorPointSolver (Since R2020a)
setCustomSolverConfigures an MPC object to use the QP solver from Optimization Toolbox as a custom solver (Since R2021b)

Blocks

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 (Since R2019a)

Topics

Code Generation Basics

Simulink Code Generation

MATLAB Code Generation

CUDA Code Generation

Using Custom Solvers

OPC Simulation