Main Content

Model an Intersection of One-Way Streets

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.

Intersection Model

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.

Traffic Controller

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 mask parameters for the chart. For more information, see Create a Mask to Share Parameters with Simulink.

Active State Output

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.

Simulation

Simulate the model to see the traffic light blocks animate.

Related Topics