Main Content

Implement Behaviors for Architecture Model Simulation

A basic systems engineering workflow in System Composer™ includes composing an architecture system, defining requirements, adding metadata, performing analyses, and representing the architecture through views. After fulfilling these steps, your system design is closer to meeting stakeholder goals and customer needs.

You can also now begin to design the actual system components using Simulink®, Stateflow®, and Simscape™. You can fully specify, test, and analyze the behavior of a component using the model-based design process.

In this tutorial, you will perform these steps on the robot arm architecture model.

Robot Arm Architecture Model

Open the architecture model of a robot arm that consists of sensors, motion actuators, and a planning algorithm. You can use System Composer to view the interfaces and manage the requirements for this model.

Reference Simulink Behavior Model in Component

When a component does not require further architectural decomposition, you can enable model simulation and an end-to-end workflow. To enable model simulation, implement Simulink behaviors for components. You can associate a Simulink model with a component or link to an existing Simulink model.

  1. Right-click the Motion component and select Create Simulink Behavior. Alternatively, navigate to Modeling > Component > Create Simulink Behavior.

  2. From the Type list, select Model Reference. Provide the model name MotionSimulink. The default name is the name of the component.

    Create Simulink Behavior dialog with new model name 'Motion Simulink' with options browse, from Simulink template, new data dictionary name, OK, cancel, and help.

  3. A new Simulink model with the provided name is created and linked to the component in the architecture model.

    The motion component with referenced Simulink model between chevrons with arrow pointing to what is inside. There is a Simulink base model inside with in-ports and out-ports designated.

You can also link to an existing Simulink behavior model from a System Composer component, provided that the component is not already linked to a reference architecture. Right-click the component and select Link to Model. You can type or browse for the name of a Simulink model.

You can also add Simulink subsystem behavior to a component. The new subsystem component is part of the parent System Composer architecture model. From the Type list, select Subsystem.

Create Simulink subsystem behavior dialog.

Subsystem components are required to author Simscape component behaviors with physical ports, connections, and blocks.

Add Stateflow Chart Behavior to Component

To implement event-based modeling with state machines, add Stateflow chart behavior to a component. State charts consist of a finite set of states with transitions between them to capture the modes of operation for the component. This functionality requires a Stateflow license.

A System Composer component with stereotypes, interfaces, requirement links, and ports, is preserved when you add Stateflow Chart (Stateflow) behavior.

  1. Right-click the Sensor component and select Create Stateflow Chart Behavior. Alternatively, navigate to Modeling > Component > Create Stateflow Chart Behavior.

  2. Double-click Sensor, which has the Stateflow icon. In the Modeling menu, select Design Data, then click Symbols Pane to view the Stateflow symbols. The input port Encoder appears as input data in the symbols pane and the output port SensorData appears as output data.

    Sensor state chart with symbols.

  3. Select the SensorData output and view the interface in the Property Inspector. You can access the interface like a Simulink bus signal.

    The interface named sensor data is shown as a bus.

Design Software Architecture in Component

To design a software architecture, define function execution order, simulate, and generate code, create a software architecture from a System Composer component.

  1. Rename the Trajectory Planning component to TrajectoryPlanning so that it is a valid C variable name.

  2. Right-click the TrajectoryPlanning component and select Create Software Architecture Model, or, navigate to Modeling > Component > Create Software Architecture Model.

  3. Specify the name of the software architecture as TrajectorySoftware. Click OK.

    Create a software architecture model named Trajectory Software from a component.

  4. The software architecture model TrajectorySoftware.slx is referenced from the TrajectoryPlanning component.

    Trajectory planning component has a trajectory software architecture model reference.

  5. Double-click the TrajectoryPlanning component to interact with the TrajectorySoftware software component.

    Trajectory software component.

Represent System Interaction Using Sequence Diagrams

To represent the interaction between structural elements of an architecture as a sequence of message exchanges, use a sequence diagram in the Architecture Views Gallery.

Observe the robot arm architecture model consisting of components, ports, connections, and behaviors. The model simulation results must match the interactions within the sequence diagrams.

The robot arm model with a software architecture, state chart, and Simulink behavior.

  1. Create a new sequence diagram by navigating to Modeling > Views > Architecture Views. The Architecture Views Gallery opens. To create a new sequence diagram, click new New > Sequence Diagram.

  2. A new sequence diagram called SequenceDiagram1 is created in the View Browser, and the Sequence Diagram tab becomes active. Under Element Properties, rename the sequence diagram RobotArmSequence.

  3. Select Component > Add Lifeline button to add a lifeline. A new lifeline with no name is created and is indicated by a dotted line.

  4. Click the down arrow and select Sensor. Add a second lifeline named Motion.

  5. Select the vertical dotted line for the Sensor lifeline. Click and drag to the Motion lifeline. In the To box, start to type Sensordata and choose SensorData from the drop down menu. A message is created from the SensorData port on the Sensor component to the SensorData port on the Motion component.

  6. Click on the message to see where to place the message condition. Enter a message trigger condition in the form:


    The signal name is a data element on a data interface. The message will be recognized at the zero-crossing event when the value of SensorData.distance1 rises to 1.

Finished sequence diagram.

Related Topics