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.
Select the
Motion
component. Navigate to Modeling > Create Simulink Behavior. Alternatively, right-click theMotion
component and selectCreate Simulink Behavior
.From the Type list, select
Model Reference
. Provide the model nameMotionSimulink
. The default name is the name of the component.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 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.To view the interfaces on the SensorData port converted into Simulink bus elements, double-click the port in Simulink.
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.
Select the
Motion
component. Navigate to Modeling > Create Simulink Behavior. Alternatively, right-click theMotion
component and selectCreate Simulink Behavior
.From the Type list, select
Subsystem Reference
. Provide the model nameMotionSubsystem
. The default name is the name of the component.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 icon on the component indicates that the component has a Simulink subsystem behavior.
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.
Right-click the
Sensor
component and selectCreate Stateflow Chart Behavior
. Alternatively, select theSensor
component, then navigate to Modeling > Create Stateflow Chart Behavior.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.Select the SensorData output and view the interface in the Property Inspector. You can access this 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.
Rename the
Trajectory Planning
component toTrajectoryPlanning
so that it is a valid C variable name.Right-click the
TrajectoryPlanning
component and selectCreate Software Architecture Model
, or, navigate to Modeling > Create Software Architecture Model.Specify the name of the software architecture as
TrajectorySoftware
. Click OK.The software architecture model
TrajectorySoftware.slx
is referenced from theTrajectoryPlanning
component.Double-click the
TrajectoryPlanning
component to interact with theTrajectorySoftware
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.
Create a new sequence diagram by navigating to Modeling > Sequence Diagram. The Architecture Views Gallery opens. To create a new sequence diagram, click New > Sequence Diagram.
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 diagramRobotArmSequence
.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 namedMotion
.Select the vertical dotted line for the
Sensor
lifeline. Click and drag to theMotion
lifeline. In the To box, start to typeSensordata
and chooseSensorData
from the drop down menu. A message is created from the SensorData port on theSensor
component to the SensorData port on theMotion
component.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.