Why Use a Simulink Function in a Stateflow Chart?

Advantages of Using Simulink Functions in a Stateflow Chart

When you define a function that uses Simulink® function-call subsystem blocks or schedule execution of multiple controllers without Simulink functions, the model requires these elements:

  • Simulink function-call subsystem blocks

  • Stateflow® chart with function-call output events

  • Signal lines between the chart and each function-call subsystem port

Simulink functions in a Stateflow chart provide these advantages:

  • No function-call subsystem blocks

  • No output events

  • No signal lines

Benefits of Using a Simulink Function to Access Simulink Blocks

The sections that follow compare two ways of defining a function that uses Simulink blocks.

Model Method Without a Simulink Function

You define a function-call subsystem in the Simulink model (see Using Function-Call Subsystems. Use an output event in a Stateflow chart to call the subsystem, as shown.

Model Method With a Simulink Function

You place one or more Simulink blocks in a Simulink function of a Stateflow chart. Use a function call to execute the blocks in that function, as shown.

In the chart, the during action in selection_state contains a function call to calc_th, which is a function that contains Simulink blocks.

This modeling method minimizes the objects in your model.

For more information, see Improve Chart Design by Using Simulink Functions.

Benefits of Using a Simulink Function to Schedule Execution of Multiple Controllers

The sections that follow compare two ways of scheduling execution of multiple controllers.

Model Method Without Simulink Functions

You define each controller as a function-call subsystem block and use output events in a Stateflow chart to schedule execution of the subsystems, as shown in the sf_temporal_logic_scheduler model.

Model Method With Simulink Functions

You define each controller as a Simulink function in a Stateflow chart and use function calls to schedule execution of the subsystems, as shown in the sf_temporal_logic_scheduler_with_sl_fcns model.

This modeling method minimizes the objects in your model.

Related Topics