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.
Motioncomponent and select
Create Simulink Behavior. Alternatively, navigate to Modeling > Component > Create Simulink Behavior.
From the Type list, select
Model Reference. Provide the model name
MotionSimulink. The default name is the name of the component.
A new Simulink model with the provided name is created and linked to the component in the architecture model.
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 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.
Sensorcomponent and select
Create Stateflow Chart Behavior. Alternatively, navigate to Modeling > Component > Create Stateflow Chart Behavior.
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
Encoderappears as input data in the symbols pane and the output port
SensorDataappears as output data.
SensorDataoutput and view the interface in the Property Inspector. You can access the interface like a Simulink bus signal.
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.
Trajectory Planningcomponent to
TrajectoryPlanningso that it is a valid C variable name.
TrajectoryPlanningcomponent and select
Create Software Architecture Model, or, navigate to Modeling > Component > Create Software Architecture Model.
Specify the name of the software architecture as
TrajectorySoftware. Click OK.
The software architecture model
TrajectorySoftware.slxis referenced from the
TrajectoryPlanningcomponent to interact with the
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.
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 > Sequence Diagram.
A new sequence diagram called
SequenceDiagram1is created in the View Browser, and the Sequence Diagram tab becomes active. Under Element Properties, rename the sequence diagram
Select Component > Add Lifeline to add a lifeline. A new lifeline with no name is created and is indicated by a dotted line.
Click the down arrow and select
Sensor. Add a second lifeline named
Select the vertical dotted line for the
Sensorlifeline. Click and drag to the
Motionlifeline. In the To box, start to type
SensorDatafrom the drop down menu. A message is created from the
SensorDataport on the
Sensorcomponent to the
SensorDataport on the
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.distance1rises to 1.