Main Content

Simulate and Generate Structured Text Code for a Stateflow Chart

This example shows how to simulate and generate code for the ControlModule Stateflow® chart from the plcdemo_stateflow_controller model.

Open the Model

open_system('plcdemo_stateflow_controller')

To start the simulation, click Run.

Generate Code

To generate code for the ControlModule chart, use plcgeneratecode. For more information, see plcgeneratecode:

generatedfiles = plcgeneratecode('plcdemo_stateflow_controller/ControlModule');

The plcdemo_stateflow_controller consists of stateflow charts to simulate a drive module. The TestHarness chart provides a test scenario of starting, holding, and resetting the drive.

open_system('plcdemo_stateflow_controller/TestHarness');

The BehaviorModel chart provides a simple chart to test the ControlModule chart behavior by injecting faults.

open_system('plcdemo_stateflow_controller/BehaviorModel');

The ControlModule chart performs the drive control logic.

open_system('plcdemo_stateflow_controller/ControlModule');