Main Content

Describe System Behavior Using Sequence Diagrams

Asequence diagramis 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™.

Note

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.

openViews(model)

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

1.PressDetectionsequence diagram: The pedestrian presses the pedestrian crossing button and the signalswrises to1. Thepollerlifeline is activated, and aswitchEventmessage occurs on theswitchlifeline to change the traffic signals to allow the pedestrian to cross.

2.SignalSequencesequence diagram: The pedestrian presses the pedestrian crossing button, and the signalswrises to1. After some intermediary events, thelampControllerlifeline transmits atriggersignal to theped lamplifeline to change pedestrian lamp traffic colors fromRED(stop) toGREEN(go), allowing pedestrians to cross.

3.PedestrianCrosssequence diagram: First, thetrafficvalue is3, 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 thecontrollerlifeline recognizes a validpedRequestmessage, the traffic lamp changes from yellow (2) to red (1),它允许交叉的行人。然后,届e main loop continues.

4.Inhibitsequence diagram: Theinhibitflag determines whether a pedestrian crossing button is set up for pedestrians to press to control the traffic lamp signal on an intersection and cross. Wheninhibitis set to0,crossing button exists. Wheninhibitis set to1,crossing button does not exist. TheswitchEventvalue is1, which indicates that the pedestrians would like to cross. Once theswitchEventvalue is set to1, ifinhibitis0,controllerlifeline recognizes thepedRequestmessage to initiate a change in the pedestrian lamp color. Additionally, theswitchPedvalue is1, so the traffic lamp will change from yellow to red. Otherwise, ifinhibitis1,switchPedvalue is2,所以交通信号灯控制inue 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]); createWorkSpaceVar("inhibitFlag",1,0);

Related Topics