Main Content

Describe System Behavior Using Sequence Diagrams

A sequence diagram is a behavior diagram that represents the interaction between structural elements of an architecture as a sequence of message exchanges.

Use sequence diagrams to describe how the parts of a static system interact.

Sequence diagrams are integrated with architecture models in System Composer™.


This example uses Stateflow® blocks. If you do not have a Stateflow license, you can open and simulate the model but can only make basic changes, such as modifying block parameters.

Traffic Light Example for Sequence Diagrams

This traffic light example contains sequence diagrams to describe pedestrians crossing an intersection. The model describes these steps:

  1. The traffic signal cycles from red to yellow to green.

  2. When the pedestrian crossing button is pressed, if the traffic signal is green, the traffic signal transitions from yellow to red for a limited time.

  3. The pedestrians cross while the walk signal is active.

Open the System Composer model that contains the sequence diagrams.

model = systemcomposer.openModel('TLExample');

Open the Architecture Views Gallery to view the sequence diagrams.


The sequence diagrams in this example represent operative scenarios in the architecture model.

1. PressDetection sequence diagram: The pedestrian presses the pedestrian crossing button and the signal sw rises to 1. The poller lifeline is activated, and a switchEvent message occurs on the switch lifeline to change the traffic signals to allow the pedestrian to cross.

2. SignalSequence sequence diagram: The pedestrian presses the pedestrian crossing button, and the signal sw rises to 1. After some intermediary events, the lampController lifeline transmits a trigger signal to the ped lamp lifeline to change pedestrian lamp traffic colors from RED (stop) to GREEN (go), allowing pedestrians to cross.

3. PedestrianCross sequence diagram: First, the traffic value is 3, which indicates that the traffic light color is green. The traffic light loops from yellow (2) to red (1) to green (3) and again. When the pedestrian crossing button is pressed and the controller lifeline recognizes a valid pedRequest message, the traffic lamp changes from yellow (2) to red (1), which allows the pedestrians to cross. Then, the main loop continues.

4. Inhibit sequence diagram: The inhibit flag determines whether a pedestrian crossing button is set up for pedestrians to press to control the traffic lamp signal on an intersection and cross. When inhibit is set to 0, the crossing button exists. When inhibit is set to 1, the crossing button does not exist. The switchEvent value is 1, which indicates that the pedestrians would like to cross. Once the switchEvent value is set to 1, if inhibit is 0, the controller lifeline recognizes the pedRequest message to initiate a change in the pedestrian lamp color. Additionally, the switchPed value is 1, so the traffic lamp will change from yellow to red. Otherwise, if inhibit is 1, the switchPed value is 2, so the traffic lamp will continue normal operation and not change to red to specifically allow the pedestrians to cross.

Simulate Architecture Model

You can execute the model after setting these variables.

createWorkSpaceVar("SwitchInputs",[0 11 18],[-1 1 -1]);

Related Topics