Main Content

Simulate and Generate Code for Speed Cruise Control System

This example shows how to simulate and generate code for the Controller subsystem from a speed cruise control model by using Simulink® and Stateflow®.

Open the Model


To start the simulation, click Run.

Generate Code

To generate code for the Controller subsystem, use plcgeneratecode:

generatedfiles = plcgeneratecode('plcdemo_cruise_control/Controller');

The Controller subsystem performs the Enable and Setpoint calculations by using a Triggered Stateflow® chart. The Throttle Command is computed by using a discrete PID controller.