Simulate and Generate Code for Speed Cruise Control System
This example shows how to simulate and generate code for a speed cruise control system. The cruise control system is modeled using Simulink® and Stateflow®.
Open the Model
The model consists of two subsystems at the top level:
Controllerthat contains the Stateflow® chart and a PID controller implemented using Simulink® library blocks.
Plantthat contains an implementation of the dynamics of a cruise control system
To generate structured text code,
In the Apps tab, click PLC Coder.
In the PLC Code tab, click Settings > PLC Code Generation. Change the Target IDE to
2.3. Click OK.
Select the top level
Controllerblock. In the PLC Code tab, click Generate PLC Code.
Alternatively, to generate code from the MATLAB command line, use the
generatedfiles = plcgeneratecode('plcdemo_cruise_control/Controller');