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.

For more information about the model-based systems engineering workflow within System Composer, see Compose and Analyze Systems Using Architecture Models.

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 or subsystem.

  1. Select the Motion component. Navigate to Modeling > Create Simulink Behavior. Alternatively, right-click the Motion component and select 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 box with the new model reference name, MotionSimulink.

  3. Click OK. A new Simulink model file with the provided name is created in the current folder. The root-level ports of the Simulink model reflect the ports of the component. The component in the architecture model is linked to the Simulink model. The Simulink icon on the component indicates that the component has a Simulink behavior.

    Note

    To remove model behavior, right-click the linked Motion component and select Inline Model.

    The motion component with referenced Simulink model showing a Simulink base model inside with input ports and output ports designated

  4. To view the interfaces on the SensorData port converted into Simulink bus elements, double-click the port in Simulink.

    Sensor data bus element properties

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 link a referenced Simulink subsystem behavior to a component. Use subsystem references to author Simulink or Simscape behaviors with physical ports, connections, and blocks.

  1. Select the Motion component. Navigate to Modeling > Create Simulink Behavior. Alternatively, right-click the Motion component and select Create Simulink Behavior.

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

    Create Simulink Behavior dialog box with the new subsystem reference name, MotionSubsystem.

  3. Click OK. A new Simulink subsystem file with the provided name is created in the current folder. The root-level ports of the Simulink subsystem reflect the ports of the component. The component in the architecture model is linked to the Simulink subsystem. The Subsystem icon on the component indicates that the component has a Simulink subsystem behavior.

    Motion component as a subsystem reference component

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, select the Sensor component, then navigate to Modeling > Create Stateflow Chart Behavior.

  2. Double-click Sensor, which has the Stateflow icon. From the Modeling menu, 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 this 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 > 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 > Sequence Diagram. 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 Sequence Diagram 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:

    rising(SensorData.distance1-1)

    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