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™.
Author Sequence Diagram for Traffic Light Example: Interactively create and edit a sequence diagram and learn terminology.
Implement Sequence Diagram Fragments: Learn how to implement fragments and more about fragment semantics.
Use Sequence Diagrams with Architecture Models: Create and use sequence diagrams with architecture models.
Synchronize Sequence Diagrams and Architecture Models: Learn how to synchronize sequence diagrams with architecture models.
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:
The traffic signal cycles from red to yellow to green.
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.
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.PressDetection
sequence diagram: The pedestrian presses the pedestrian crossing button and the signalsw
rises to1
. Thepoller
lifeline is activated, and aswitchEvent
message occurs on theswitch
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 signalsw
rises to1
. After some intermediary events, thelampController
lifeline transmits atrigger
signal to theped lamp
lifeline to change pedestrian lamp traffic colors fromRED
(stop) toGREEN
(go), allowing pedestrians to cross.
3.PedestrianCross
sequence diagram: First, thetraffic
value 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 thecontroller
lifeline recognizes a validpedRequest
message, the traffic lamp changes from yellow (2
) to red (1
),它允许交叉的行人。然后,届e main loop continues.
4.Inhibit
sequence diagram: Theinhibit
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. Wheninhibit
is set to0
,crossing button exists. Wheninhibit
is set to1
,crossing button does not exist. TheswitchEvent
value is1
, which indicates that the pedestrians would like to cross. Once theswitchEvent
value is set to1
, ifinhibit
is0
,controller
lifeline recognizes thepedRequest
message to initiate a change in the pedestrian lamp color. Additionally, theswitchPed
value is1
, so the traffic lamp will change from yellow to red. Otherwise, ifinhibit
is1
,switchPed
value 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);