Main Content

Describe 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 inlined behaviors using Simulink® subsystem components, or referenced behaviors by linking components to Simulink models.

You can simulate the Simulink component implementations in System Composer. To observe simulation results, see View Data in the Simulation Data Inspector.

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 its behavior in Simulink. When you link to a Simulink behavior, the Component block becomes a Reference Component block. A reference component represents a logical hierarchy of other compositions. You can reuse compositions in the model by using reference components.

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

    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.

  4. You can continue to provide specific dynamics and algorithms in the referenced Simulink model. Adding root-level ports in the Simulink model creates additional ports on the System Composer Reference Component block.

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

Sensor data bus element properties.

You can access and edit a referenced Simulink model by double-clicking the component in the architecture model. When you save the architecture model, all unsaved Simulink behavior models it references are also saved, and all linked components are updated.

Create Simulink Behavior Using Simulink Subsystem

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.

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

  2. From the Type list, select Subsystem.

    Create Simulink subsystem behavior dialog.

  3. 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 Simulink icon on the component indicates that the component has a Simulink subsystem behavior.

    Sensor component is now a Simulink subsystem component.

  4. You can continue to provide specific dynamics and algorithms in the inlined Simulink behavior model. Adding root-level ports in the inlined Simulink model creates additional ports on the Simulink subsystem component.

Subsystem components are required 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.

Amplifier physical subsystem with electrical domain blocks.

For more information, see Describe Component Behavior Using Simscape.

Link to an Existing Simulink Behavior Model

You can 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. Type in or browse for the name of a Simulink model.

Link to model dialog with existing model name 'Motion Simulink'. Press Enter for OK.

Any subcomponents and ports in the components are deleted when the component links to a Simulink model. A prompt displays to continue and lose 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 change is reflected when you refresh the model.

Create a Simulink Behavior from Template for a 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 > Component > Create Simulink Behavior.

Create Simulink Behavior for a component. Create the new model from a Simulink template and a new data dictionary.

On the Create Simulink behavior dialog, 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.

Note that you can use architecture templates by right-clicking a component and selecting Save As Architecture Model, or navigating to Modeling > Component > Save As Architecture Model.

Save component as an architecture model. Create the new model from a Simulink template and a new data dictionary.

See Also

Functions

Blocks

Related Topics