This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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

Code Generation in Simulink

After designing a controller in Simulink using any of the MPC blocks, you can generate code and deploy it for real-time control. You can deploy controllers to all targets supported by the following products:

  • Simulink Coder™

  • Embedded Coder®

  • Simulink PLC Coder™

  • Simulink Real-Time™

The sampling rate that a controller can achieve in real-time environment is system-dependent. For example, for a typical small MIMO control application running on Simulink Real-Time, the sampling rate can go as low as 1–10 ms. To determine the sampling rate, first test a less aggressive controller whose sampling rate produces acceptable performance on the target. Next, increase the sampling rate and monitor the execution time used by the controller. You can further decrease the sampling rate as long as the optimization safely completes within each sampling period under the normal plant operations. To reduce the sampling rate, you can also consider using explicit MPC. However, explicit MPC controllers have a larger memory footprint, since they store precomputed control laws.

You can generate code for any of the Model Predictive Control Toolbox Simulink blocks:

For more information, see Simulation and Code Generation Using Simulink Coder and Simulation and Structured Text Generation Using PLC Coder.

    Note:   The MPC Controller block is implemented using the MATLAB Function block. To see the structure, right-click the block and select Mask > Look Under Mask. Open the MPC subsystem underneath.

Code Generation in MATLAB

After designing an MPC controller in MATLAB, you can generate C code using MATLAB Coder and deploy it for real-time control.

To generate code for computing optimal MPC control moves:

  1. Generate data structures from an MPC or explicit MPC controller using getCodeGenerationData.

  2. To verify that your controller produces the expected closed-loop results, simulate it using mpcmoveCodeGeneration in place of mpcmove.

  3. Generate code for mpcmoveCodeGeneration using codegen. This step requires MATLAB Coder software.

For more information, see Generate Code To Compute Optimal MPC Moves in MATLAB.

See Also



More About

Was this topic helpful?