implement component behavior using simulink -凯发k8网页登录

main content

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.

behaviorhow to usemore information
simulink model referenceimplement 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 componentimplement 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');

2021-03-12_8-11-05.png

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.

  1. navigate to modeling > create simulink behavior. alternatively, right-click the motion component and select 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 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 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. to view the interfaces on the sensordata port converted into simulink bus elements, double-click the port in simulink.

    sensor data bus element properties.

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

  1. navigate to modeling > create simulink behavior. alternatively, right-click the motion component and select create simulink behavior

  2. from the type list, select subsystem reference. provide the model name motionsubsystem. the default name is the name of the component.

    create simulink behavior dialog with new subsystem name 'motion subsystem'.

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

    motion component as a subsystem reference component.

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.

  1. right-click the sensor component and select create simulink behavior. alternatively, navigate to modeling > 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 simulink subsystem behavior model. adding root-level ports in the subsystem behavior creates additional ports on the subsystem component.

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

    amplifier physical subsystem with electrical domain blocks.

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.

  1. right-click the subsystem component block and select block parameters (subsystem).

  2. click the subsystem reference tab.

    block parameters for a subsystem component.

  3. click convert to open the convert to subsystem reference dialog.

  4. choose a name for the new subsystem file. optionally, select transfer test harnesses to transfer test harnesses. click convert to complete the conversion.

    convert to subsystem reference dialog.

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.

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

left wheel parameters with the psi parameter set to 34.

each parameter value can be specified independently for each component that references the model.

right wheel parameters with the psi parameter set to 32.

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.

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

网站地图