This example models an intersection of two 1-way roads controlled by a Stateflow® traffic light system. The Stateflow® chart uses active state outputsactive state outputs and a mask. 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 "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.
Active State Output
The child activity of both "Light1Controller" and "Light2Controller" is output to Simulink® via a data of enumerated type. This data is automatically managed by Stateflow®.
Open one of the Light controllers (for instance, Light1Controller).
Right click and select Properties.
Notice the "Create output port for monitoring child activity" is selected.
The field "Port 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.