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.
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 subsystem 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 subsystem 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 |
you can simulate the simulink component implementations in system composer. use the simulation data inspector to view and compare simulation results between model designs.
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 reuse compositions in the model using reference components. 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 will create a model reference and a subsystem reference. for more information on architecture references, see .
referenced or linked models are useful for collaborative design with version control using simulink projects. for more information, see .
create reusable simulink behavior using model reference component
use simulink model references to describe the implementation of system composer components.
navigate to modeling > create simulink behavior. alternatively, right-click the
motion
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.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.
to view the interfaces on the sensordata port converted into simulink bus elements, double-click the port in simulink.
to remove model behavior, right-click the linked
motion
component and select inline model.
for more information on removing referenced behaviors, see .
create reusable simulink subsystem 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.
navigate to modeling > create simulink behavior. alternatively, right-click the
motion
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.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 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 subsystem 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
.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.
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 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.
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 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.
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 references 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 .
each parameter value can be specified independently for each component that references the model.
for more information, see .
to add or modify parameters for architectures or components using the , see .
create simulink behavior from template for component
to create user-defined templates for simulink models, see .
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, 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 > save as architecture model.
see also
functions
- | | |