This example models an intersection of one-way roads controlled by a Stateflow® traffic light system. The Stateflow chart tracks the state of each traffic light by using active state output. The behavior of the traffic lights is controlled by parameters on the Stateflow mask.
The phase of the animated traffic lights is determined by the output data from the Stateflow chart. The value of the output data corresponds to the active child of the substates Light1Controller
and Light2Controller
, respectively.
The Stateflow chart Traffic Controller manages two traffic controllers in parallel. Each controller determines the phase of the downstream traffic light based on traffic congestion at the intersection, an input from Simulink®, and parameters on the chart's mask. For more information, see Create a Mask to Share Parameters with Simulink.
The child activity of both Light1Controller
and Light2Controller
is output to Simulink through a data of enumerated type. Stateflow manages this data automatically. For more information, see Monitor State Activity Through Active State Data.
Open one of the Light controllers (for instance, Light1Controller
).
Right click and select Properties.
Notice that the Create output for monitoring option is selected and set to Child activity
.
The field Data name corresponds to the name of the output data on the linked instance.
This output is mapped to a chart level output called Light1
.
Simulate the model to see the traffic light blocks animate.