Use Sequence Diagrams with Architecture Models
You can author sequence diagrams to describe expected system behavior as a sequence of interactions between components of a System Composer™ architecture model. Lifelines correspond to components in an architecture model, and messages correspond to the connectors between the components. You can create multiple sequence diagrams to represent different operational scenarios of the system. Sequence diagrams are integrated into the Architecture Views Gallery in System Composer.
For a roadmap of the sequence diagram topics, see Describe System Behavior Using Sequence Diagrams.
This traffic light example will show you how to:
Create a sequence diagram.
Add child lifelines in a sequence diagram.
Interact with root architecture ports in a sequence diagram using gates.
Co-create components and keep the architecture model and the sequence diagram in sync.
Create messages in a sequence diagram.
Use the model browser to add components.
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 with Hierarchy 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('TrafficLight');
Open the Architecture Views Gallery to view the sequence diagrams.
The sequence diagrams in this example represent operative scenarios in the architecture model.
InputPollNested sequence diagram: When the
poller recognizes a signal event as
inValue rises to
1, the pedestrian crossing button is pressed. Next, the
switch lifeline recognizes a signal event to
switchPed rises to
1, which activates the pedestrian crossing signal.
PedLoop sequence diagram: The traffic lamp changes
trafficColor from green (
3) to yellow (
2) to red (
1). After each traffic color change, the
tSwitch value becomes
0, which indicates that the traffic lamp has been changed. The cycle repeats in a loop for several iterations before the pedestrian crossing button is pressed.
Simulate Architecture Model
You can execute the model after setting these variables.
createWorkSpaceVar("SwitchInputs",[0 11 18],[-1 1 -1]); createWorkSpaceVar("inhibitFlag",1,0);
Create Sequence Diagram
Use an architecture model in System Composer to represent a traffic light example.
Navigate to Modeling > Sequence Diagram to open sequence diagrams in the Architecture Views Gallery.
To create a new sequence diagram, click New > Sequence Diagram.
In Element Properties on the right, enter the name
Select Component > Add Lifeline from the menu. A box with a vertical dotted line appears on the canvas. This is the new lifeline.
Click the down arrow on the lifeline to view available options. Select the component named
lampSubsystemto be represented by the lifeline.
Add Child Lifelines to Sequence Diagram
You can add child lifelines to a sequence diagram to represent model hierarchy and describe the interactions between lifelines.
From the menu, select Component > Add Lifeline. From the list that appears, select the
Child components called
controllerare located inside the
lampSubsystemlifeline. Navigate to Component > Add Lifeline > Add Child Lifeline. Select
lampcontrollerchild lifeline is now situated below
lampSubsystemin the hierarchy.
Repeat these steps for the
Controllerlifeline to add the
Create Sequence Diagram Gates
lampcontrollerlifeline, then click and drag it to the gutter region. Start typing
tSwitchinto the To box and select
tSwitchfrom the list. See that a gate called
tSwitchhas been created with a message from the
lampcontrollerlifeline at the port
Return to the architecture diagram. Observe that
tSwitchis a root architecture port connected to the
lampcontrollercomponent in the hierarchy through the
The co-creation workflow between the sequence diagram and the architecture model keeps the model synchronized as you make changes to the sequence diagram. Adding both lifelines and messages in a sequence diagram results in updates to the architecture model. This example shows component co-creation.
From the toolstrip menu, select Component > Add Lifeline. Another box with a vertical dotted line appears on the canvas to represent a lifeline. In the box, enter the name of a new component named
Observe that the
Machinecomponent is co-created in the architecture diagram.
Synchronize Sequence Diagram and Model
Machinecomponent from the architecture diagram.
Return to the sequence diagram and select Synchronize > Check Consistency. See that the
Machinelifeline is highlighted, as it does not correspond to a component.
To restore consistency, either remove the
Machinelifeline or click Undo in the architecture model to restore the
Click Check Consistency again.
For advanced sequence diagram synchronization techniques, see Synchronize Sequence Diagrams and Architecture Models.
Create Messages in Sequence Diagram
You can create a message from an existing connection.
Draw a line from the
controllerlifeline to the
lampcontrollerlifeline. Start to type
trafficin the To box, which fills in automatically as you type. Once the text fills in, select
trafficport are connected in the model, a message is created from the
trafficport to the
trafficColorport in the sequence diagram.
You can modify the source and destination of a message after the message has been created. Click the
trafficColormessage end to select it.
Click and drag the
trafficColormessage end to the
Controllerparent lifeline, then select the
trafficColorport is selected, the message end moves from the
controllerchild lifeline to the
You can also rename message ends and the associated ports by double-clicking the name of a message end.
Modify Sequence Diagram Using Model Browser
The Views Gallery model browser located on the bottom left of the canvas is called Model Components. Click and drag the
switchchild component into the sequence diagram.
The sequence diagram is updated with a new lifeline.
Click and drag to reorder the
Create Sequence Diagram from View
In the MATLAB® Command Window, enter
scKeylessEntrySystem. The architecture model opens in the Simulink Editor.
To open the Architecture Views Gallery for the model, navigate to Modeling > Views > Architecture Views.
Sound System Supplier Breakdownview and select New Sequence Diagram.
A new sequence diagram of lifelines is created with all the components from the view.