Main Content

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.

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 with Hierarchy 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 green to yellow to red.

  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("TrafficLight");

Open the Architecture Views Gallery to view the sequence diagrams.

openViews(model)

The sequence diagram in this example represents an operative scenario 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 lampcontroller as switchPed rises to 1, which activates the pedestrian crossing signal.

InputPollNested sequence diagram

Create Sequence Diagram

Use an architecture model in System Composer to represent a traffic light example.

Architecture model for a traffic light with an input subsystem, controller, and lamp subsystem

  1. Navigate to Modeling > Sequence Diagram to open sequence diagrams in the Architecture Views Gallery.

  2. To create a new sequence diagram, click New > Sequence Diagram.

  3. In Sequence Diagram Properties on the right, enter the name PedLoop.

  4. Select Component > Add Lifeline from the menu. A box with a vertical dotted line appears on the canvas. This is the new lifeline.

  5. Click the down arrow on the lifeline to view available options. Select the component named lampSubsystem to be represented by the lifeline.

A sequence diagram with a menu open to select a new lifeline for the lamp subsystem.

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.

  1. From the menu, select Component > Add Lifeline. From the list that appears, select the Controller component.

    A menu with the lifeline named Controller selected.

  2. Child components called lampcontroller and controller are located inside the lampSubsystem and Controller components, respectively.

    The lamp subsystem component with a child component named lampcontroller.

  3. Select the lampSubsystem lifeline. Navigate to Component > Add Lifeline > Add Child Lifeline. Select lampcontroller. The lampcontroller child lifeline is now situated below lampSubsystem in the hierarchy.

  4. Repeat these steps for the Controller lifeline to add the controller child lifeline.

    A list of two child lifelines named controller and switch for the Controller lifeline

Create Sequence Diagram Gates

  1. Select the lampcontroller lifeline, then click and drag it to the gutter region. Start typing tSwitch into the To box and select tSwitch from the list. See that a gate called tSwitch has been created with a message from the lampcontroller lifeline at the port tSwitch.

    A message between the tSwitch gate and the lampcontroller lifeline.

  2. Return to the architecture diagram. Observe that tSwitch is a root architecture port connected to the lampcontroller component in the hierarchy through the lampSubsystem component.

    The architecture diagram shows the corresponding root architecture from the sequence diagram for tSwitch.

Co-Create Components

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.

  1. 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 Machine.

    A new component named Machine displays in the sequence diagram.

  2. Observe that the Machine component is co-created in the architecture diagram.

    A new component has been added to the architecture diagram called Machine.

Synchronize Sequence Diagram and Model

  1. Remove the Machine component from the architecture diagram.

  2. Return to the sequence diagram and select Synchronize > Check Consistency. See that the Machine lifeline is highlighted, as it does not correspond to a component.

    The Machine lifeline highlighted.

  3. To restore consistency, either remove the Machine lifeline or click Undo in the architecture model to restore the Machine component.

  4. 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.

  1. Draw a line from the controller lifeline to the lampcontroller lifeline. Start to type traffic in the To box, which fills in automatically as you type. Once the text fills in, select traffic.

    A message named traffic connect in bus and out bus ports between lifelines

  2. Since the trafficColor port and traffic port are connected in the model, a message is created from the traffic port to the trafficColor port in the sequence diagram.

    A message displays between the traffic color and traffic ports between the lampcontroller and controller lifelines.

  3. You can modify the source and destination of a message after the message has been created. Click the trafficColor message end to select it.

    Select the traffic color message end in the sequence diagram.

  4. Click and drag the trafficColor message end to the Controller parent lifeline, then select the trafficColor port.

    Change location of message end and choose the traffic color port on the parent lifeline in the sequence diagram.

  5. Once the trafficColor port is selected, the message end moves from the controller child lifeline to the Controller parent lifeline.

    New location of message end in sequence diagram.

    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

  1. The Views Gallery model browser located on the bottom left of the canvas is called Model Components. Click and drag the switch child component into the sequence diagram.

    The Model Components panel is on the left side of the screen. The switch component is highlighted.

  2. The sequence diagram is updated with a new lifeline.

    The final sequence diagram with shows additional model components.

  3. Click and drag to reorder the lampSubsystem and the Controller lifelines.

    Lifelines swapped in the sequence diagram.

Use Annotations to Describe Elements of Sequence Diagram

You can add plain-text annotations to a sequence diagram to describe elements, such as lifelines, messages, and fragments.

To create an annotation, double-click the canvas at the desired location. Then, enter the annotation text in the text box that appears on the canvas.

Sequence diagram with an annotation.

Press Esc or click anywhere outside the text box to apply the changes.

Create Sequence Diagram from View

  1. In the MATLAB® Command Window, enter scKeylessEntrySystem. The architecture model opens in the Simulink Editor.

  2. To open the Architecture Views Gallery for the model, navigate to Modeling > Views > Architecture Views.

  3. Right-click the Sound System Supplier Breakdown view and select New Sequence Diagram.

    The View Browser is open on the left side of the screen. The option to create a New Sequence Diagram from the Sound System Supplier Breakdown View is selected.

  4. A new sequence diagram of lifelines is created with all the components from the view.

    A sequence diagram from the Sound System View has Sound Controller and Dashboard Speaker components.

Related Topics