Implement Component Behavior Using Simulink
System design and architecture definitions can involve a behavior definition for some components, such as the algorithm for a data processing component. Define components in System Composer™ architecture models as behaviors using Simulink® subsystem components that are part of the parent model, or referenced behaviors by linking components to Simulink models or subsystems, or FMU files.
Behavior | How to Use | More Information |
---|---|---|
Simulink model reference | Implement component behaviors with a linked Simulink model to define your system behavior and easily reuse these definitions across architectural components. | Create Reusable Simulink Behavior Using Model Reference Component |
Simulink subsystem reference | Implement component behaviors with a linked Simulink subsystem to define your system behavior and easily reuse these definitions across architectural components. Subsystems support root-level physical ports to use with Simscape™ physical behaviors. | Create Reusable Simulink Behavior Using Subsystem Reference Component |
Simulink subsystem component | Implement component behaviors with a Simulink subsystem that is part of the parent architecture model to define your system behavior once. Subsystems support root-level physical ports to use with Simscape physical behaviors. | Create Simulink Behavior Using Subsystem Component |
Stateflow® chart component | Implement component behaviors with a Stateflow chart that is part of the parent architecture model to define your system behavior once. | Implement Component Behavior Using Stateflow Charts |
FMU reference component | Implement component behaviors with a linked functional mockup unit (FMU) to define your component behavior and easily reuse these definitions across architectural components. | Link to Existing FMU Files |
Note
System Composer interfaces mirror Simulink interfaces that use buses and value types. When you plan to link Simulink behaviors to System Composer components, consider these resources:
For buses at Simulink interfaces, see Composite Interface Guidelines.
To use model interfaces with bus element ports, see Simplify Subsystem and Model Interfaces with Bus Element Ports.
For value types at Simulink interfaces, see Specify Common Set of Signal Properties as Value Type.
You can simulate the Simulink component implementations in System Composer. Use the Simulation Data Inspector to view and compare simulation results between model designs.
Tip
To learn more about how System Composer concepts apply to systems engineering design, see System Composer Concepts.
Create Simulink Behavior with Robot Arm Model
This example shows how to use a robot arm model to create Simulink® behavior from the Motion
component.
1. Open the Robot.slx
model.
model = systemcomposer.openModel('Robot');
The Robot
model has an interface sensordata
applied on the ports SensorData
.
2. Look up the Motion
component.
motionComp = lookup(model,'Path','Robot/Motion');
3. Create a Simulink behavior.
motionComp.createSimulinkBehavior('MotionSimulink');
Create Referenced Simulink Behavior Model
When a component does not require decomposition from an architecture standpoint, you can design and define the behavior of the component in Simulink. When you link to a Simulink behavior, the Component block becomes a Reference Component block.
A reference component is a component whose definition is a separate architecture model, Simulink behavior model, or Simulink subsystem behavior. A reference component represents a logical hierarchy of other compositions.
You can synchronize and reuse reference components as Reference Component blocks. There are three types of reference components:
Model references are Simulink models.
Subsystem references are Simulink subsystems.
Architecture references are System Composer architecture models or subsystems.
In this section, you create a model reference and a subsystem reference. For more information on architecture references, see Create Architecture Model Reference.
Referenced or linked models are useful for collaborative design with version control using Simulink projects. For more information, see Organize System Composer Files in Projects.
Create Reusable Simulink Behavior Using Model Reference Component
Use Simulink model references to describe the implementation of System Composer components.
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.
For more information on removing referenced behaviors, see Remove Architecture Reference.
Create Reusable Simulink Behavior Using Subsystem Reference Component
Use subsystem references to author Simulink or Simscape behaviors with physical ports, connections, and blocks. For more information, see Implement Component Behavior Using Simscape.
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.
You can access and edit referenced Simulink models and subsystems by double-clicking the Reference Component block in the architecture model. When you save the architecture model, all unsaved referenced Simulink behaviors are also saved, and all linked components are updated.
Create Simulink Behavior Using Subsystem Component
A subsystem component is a Simulink subsystem that is part of the parent System Composer architecture model.
Add Simulink subsystem behavior to a component to author a subsystem component in System Composer. You cannot synchronize and reuse subsystem components as Reference Component blocks because the component is part of the parent model.
Right-click the
Sensor
component and selectCreate Simulink Behavior
. Alternatively, navigate to Modeling > Create Simulink Behavior.From the Type list, select
Subsystem
.Click OK. The
Sensor
component is now a Simulink subsystem of the same name that is part of the parent System Composer architecture model.The root-level ports of the Simulink model reflect the ports of the component. The icon on the component indicates that the component has a Simulink subsystem behavior.
You can continue to provide specific dynamics and algorithms in the Simulink subsystem behavior model. Adding root-level ports in the subsystem behavior creates additional ports on the subsystem component.
You can use subsystem components to author Simscape component behaviors with physical ports, connections, and blocks. For example, this amplifier physical system uses electrical domain blocks inside a subsystem component in a System Composer architecture model.
Convert Simulink Subsystem Component to Subsystem Reference Component
You can convert existing Simulink subsystem components that are part of the parent System Composer model to subsystem reference components. The subsystem reference components are saved separately as a reusable artifact.
Right-click the subsystem component block and select
Block Parameters (Subsystem)
.Click the Subsystem Reference tab.
Click Convert to open the Convert to Subsystem Reference dialog box.
Choose a name for the new subsystem file. Optionally, select Transfer test harnesses to transfer test harnesses. Click Convert to complete the conversion.
To convert a subsystem component to a subsystem reference programmatically, use
the createSimulinkBehavior
function.
Link to Existing Simulink Behavior Model
You can link to an existing Simulink behavior model or subsystem 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. Type in or browse for the name of a Simulink model or subsystem, such as MotionSimulink.slx
. Click
OK to create the link.
Any subcomponents and ports in the components are deleted when the component links to a Simulink model or subsystem. A prompt displays to continue and lose information about subcomponents and ports.
Note
Linking a System Composer component to a Simulink model with root-level enable or trigger ports is not supported.
You can link protected Simulink models (.slxp
) to create component behaviors. You can
also convert an already linked Simulink behavior model to a protected model. The model reflects the change when
you refresh the model.
Drag to Add Reference Components to Architecture Models
You can drag to add a reference component linked to a model or subsystem into a System Composer model. Drag a model or subsystem file from the file explorer to add a reference component to the architecture model canvas.
For example, dragging a model SLX file into the architecture model canvas adds a Reference Component block that references the model in the SLX file.
Files that you drag to add must be on the MATLAB® path. Creating reference components by dragging files from the MATLAB Editor into the model canvas is not supported.
Link to Existing FMU Files
Since R2024b
You can link to an existing FMU file from a System Composer component, if the component is not already linked to a reference
architecture. Right-click the component and select Link to FMU.
Type in or browse for the name of an FMU file, such as actuator.fmu
.
Click OK to create the link.
System Composer preserves the architectural data on an FMU in the architecture model so that an FMU component is compatible with the rest of the architecture model. Ports and interfaces defined in an FMU are visible on the FMU component and in the Property Inspector.
You are unable to modify properties of the FMU component from System Composer architecture models. For more information about importing FMU files into Simulink, see the FMU block.
Multiple FMU components that link to the same FMU file share information such as
applied profiles and stereotypes. All FMU architectural data is managed in a separate
.mldatx
file in the format:
<fmuFileName>.fmu.mldatx
.
Link and Unlink Profiles from Reference Components to Assign Stereotypes
To add custom data to a reference component linked to a model or subsystem, you can import profiles to that referenced model or subsystem.
Note
For a System Composer component linked to a Simulink behavior model through a Reference Component block, you must import the profile into the model before applying a stereotype to the component. Since the Simulink Property Inspector does not display stereotypes, you cannot add or edit stereotypes from Simulink.
A profile is a package of stereotypes.
You can use profiles to create a domain of specialized element types. Author profiles and apply profiles to a model using the Profile Editor. You can store stereotypes for a project in one or several profiles. When you save profiles, they are stored in XML files.
To learn more about how to import and manage profiles using the Profile Editor and Manage Profiles tools, see Apply Stereotypes to Extend Model Elements.
Note
When your profile is not synchronized with your Reference Component block, you might be prompted to fix it in the Diagnostic Viewer. This option removes stereotypes that do not match the definition in the reference component.
Access Model Arguments as Parameters on Reference Components
System Composer exposes instance-specific parameter values for reusable referenced models.
A parameter is an instance-specific value of a value type.
Parameters are available for inlined architectures and components. Parameters are also available for components linked to model, subsystem, or architecture references that specify model arguments. You can specify independent values for a parameter on each component.
Instance-specific parameter values are visible on the component level. View and edit these values using the Property Inspector.
You can specify the parameter value independently for each component that references the model.
For more information, see Use Parameters to Store Instance Values with Components.
To add or modify parameters for architectures or components using the Parameter Editor, see Author Parameters in System Composer Using Parameter Editor.
Create Simulink Behavior from Template for Component
To create user-defined templates for Simulink models, see Create Template from Model.
After creating and saving a user-defined template, you can link the template to a
Simulink behavior. Right-click the component and select Create
Simulink Behavior
or navigate to Modeling > Create Simulink Behavior.
On the Create Simulink behavior dialog box, choose the template and enter a new data dictionary name if local interfaces are defined. Click OK. The component exhibits a Simulink behavior according to the template with shared interfaces, if present. Blocks and lines in the template are excluded, and only configuration settings are preserved. Configuration settings include annotations and styling.
You can use architecture templates by right-clicking a component and selecting
Save As Architecture Model
, or by navigating to Modeling > Save As Architecture Model.
Create the new model from a Simulink template and a new data dictionary.
See Also
Functions
createSimulinkBehavior
|linkToModel
|inlineComponent
|createArchitectureModel
|createArchitectureSubsystem
|systemcomposer.parameter.ParameterDefinition