Class that represents signal interface
The SignalInterface
class represents the structure of the
signal interface at a given port.
Create an interface.
interface = addInterface(dictionary,'newInterface')
Dictionary
— Parent dictionary of interfaceParent dictionary of interface, specified as a systemcomposer.interface.Dictionary
object.
Name
— Interface nameInterface name, specified as a character vector.
Example: 'NewInterface'
Data Types: char
Elements
— Elements in interfaceElements in interface, specified as an array of systemcomposer.interface.SignalElement
objects.
UUID
— Universal unique identifierUniversal unique identifier for signal interface, specified as a character vector.
Example: '91d5de2c-b14c-4c76-a5d6-5dd0037c52df'
Data Types: char
ExternalUID
— Unique external identifierUnique external identifier, specified as a character vector. The external ID is
preserved over the lifespan of the signal interface and through all operations that
preserve the UUID
.
Data Types: char
Model
— Parent System Composer™ modelParent model of signal interface, specified as a systemcomposer.arch.Model
object.
addElement | Add signal interface element |
getElement | Get object for signal interface element |
removeElement | Remove signal interface element |
applyStereotype | Apply stereotype to architecture model element |
getStereotypes | Get stereotypes applied on element of architecture model |
removeStereotype | Remove stereotype from model element |
getProperty | Get property value corresponding to stereotype applied to element |
getEvaluatedPropertyValue | Get evaluated value of property from component |
setProperty | Set property value corresponding to stereotype applied to element |
destroy | Remove model element |
This example shows how to build an architecture model using the System Composer™ API.
Prepare Workspace
Clear all profiles from the workspace.
systemcomposer.profile.Profile.closeAll;
Build a Model
To build a model, add a data dictionary with interfaces and interface elements, then add components, ports, and connections. After the model is built, you can create custom views to focus on a specific concern. You can also query the model to collect different model elements according to criteria you specify.
Add Components, Ports, and Connections
Create the model and extract its architecture.
model = systemcomposer.createModel('mobileRobotAPI');
arch = model.Architecture;
Create data dictionary and add an interface. Link the interface to the model.
dictionary = systemcomposer.createDictionary('SensorInterfaces.sldd'); interface = addInterface(dictionary,'GPSInterface'); interface.addElement('Mass'); linkDictionary(model,'SensorInterfaces.sldd');
Add components, ports, and connections. Set the interface to ports, which you will connect later.
components = addComponent(arch,{'Sensor','Planning','Motion'}); sensorPorts = addPort(components(1).Architecture,{'MotionData','SensorData'},{'in','out'}); sensorPorts(2).setInterface(interface); planningPorts = addPort(components(2).Architecture,{'Command','SensorData1','MotionCommand'},{'in','in','out'}); planningPorts(2).setInterface(interface); motionPorts = addPort(components(3).Architecture,{'MotionCommand','MotionData'},{'in','out'});
Connect components with an interface rule. This rule connects ports on components that share the same interface.
c_sensorData = connect(arch,components(1),components(2),'Rule','interfaces'); c_motionData = connect(arch,components(3),components(1)); c_motionCommand = connect(arch,components(2),components(3));
Save Data Dictionary
Save the changes to the data dictionary.
dictionary.save();
Add and Connect an Architecture Port
Add an architecture port on the architecture.
archPort = addPort(arch,'Command','in');
The connect
command requires a component port as argument. Obtain the component port and connect:
compPort = getPort(components(2),'Command');
c_Command = connect(archPort,compPort);
Save the model.
save(model)
Open the model
open_system(gcs);
Arrange the layout by pressıng Ctrl+Shift+A or using the following command:
Simulink.BlockDiagram.arrangeSystem('mobileRobotAPI');
Create and Apply Profile and Stereotypes
Profiles are xml
files that can be applied to any model. You can add stereotypes with properties to profiles and then populate the properties with specific values. Along with System Composer’s built-in analysis capabilities, stereotypes can guide optimizations of your system for performance, cost, and reliability.
Create a Profile and Add Stereotypes
Create a profile.
profile = systemcomposer.createProfile('GeneralProfile');
Create a stereotype that applies to all element types:
elemSType = addStereotype(profile,'projectElement');
Create stereotypes for different types of components. These types are dictated by design needs and are up to your discretion:
pCompSType = addStereotype(profile,'physicalComponent','AppliesTo','Component'); sCompSType = addStereotype(profile,'softwareComponent','AppliesTo','Component');
Create a stereotype for connections:
sConnSType = addStereotype(profile,'standardConn','AppliesTo','Connector');
Add Properties
Add properties to stereotypes. You can use properties to capture metadata for model elements and analyze non-functional requirements. These properties are added to all elements to which the stereotype is applied, in any model that imports the profile.
addProperty(elemSType,'ID','Type','uint8'); addProperty(elemSType,'Description','Type','string'); addProperty(pCompSType,'Cost','Type','double','Units','USD'); addProperty(pCompSType,'Weight','Type','double','Units','g'); addProperty(sCompSType,'develCost','Type','double','Units','USD'); addProperty(sCompSType,'develTime','Type','double','Units','hour'); addProperty(sConnSType,'unitCost','Type','double','Units','USD'); addProperty(sConnSType,'unitWeight','Type','double','Units','g'); addProperty(sConnSType,'length','Type','double','Units','m');
Save the Profile
save(profile);
Apply Profile to Model
Apply the profile to the model:
applyProfile(model,'GeneralProfile');
Apply stereotypes to components. Some components are physical components, and others are software components.
applyStereotype(components(2),'GeneralProfile.softwareComponent') applyStereotype(components(1),'GeneralProfile.physicalComponent') applyStereotype(components(3),'GeneralProfile.physicalComponent')
Apply the connector stereotype to all connections:
batchApplyStereotype(arch,'Connector','GeneralProfile.standardConn');
Apply the general element stereotype to all connectors and ports:
batchApplyStereotype(arch,'Component','GeneralProfile.projectElement'); batchApplyStereotype(arch,'Connector','GeneralProfile.projectElement');
Set properties for each component:
setProperty(components(1),'GeneralProfile.projectElement.ID','001'); setProperty(components(1),'GeneralProfile.projectElement.Description','''Central unit for all sensors'''); setProperty(components(1),'GeneralProfile.physicalComponent.Cost','200'); setProperty(components(1),'GeneralProfile.physicalComponent.Weight','450'); setProperty(components(2),'GeneralProfile.projectElement.ID','002'); setProperty(components(2),'GeneralProfile.projectElement.Description','''Planning computer'''); setProperty(components(2),'GeneralProfile.softwareComponent.develCost','20000'); setProperty(components(2),'GeneralProfile.softwareComponent.develTime','300'); setProperty(components(3),'GeneralProfile.projectElement.ID','003'); setProperty(components(3),'GeneralProfile.projectElement.Description','''Motor and motor controller'''); setProperty(components(3),'GeneralProfile.physicalComponent.Cost','4500'); setProperty(components(3),'GeneralProfile.physicalComponent.Weight','2500');
Set the properties of connections to be identical:
connections = [c_sensorData c_motionData c_motionCommand c_Command]; for k = 1:length(connections) setProperty(connections(k),'GeneralProfile.standardConn.unitCost','0.2'); setProperty(connections(k),'GeneralProfile.standardConn.unitWeight','100'); setProperty(connections(k),'GeneralProfile.standardConn.length','0.3'); end
Add Hierarchy
Add two components named Controller
and Scope
inside the Motion
component. Define the ports. Connect them to the architecture and to each other, applying a connector stereotype. Hierarchy in an architecture diagram creates an additional level of detail that specifies how components behave internally.
motionArch = components(3).Architecture; motion = motionArch.addComponent({'Controller','Scope'}); controllerPorts = addPort(motion(1).Architecture,{'controlIn','controlOut'},{'in','out'}); controllerCompPortIn = motion(1).getPort('controlIn'); controllerCompPortOut = motion(1).getPort('controlOut'); scopePorts = addPort(motion(2).Architecture,{'scopeIn','scopeOut'},{'in','out'}); scopeCompPortIn = motion(2).getPort('scopeIn'); scopeCompPortOut = motion(2).getPort('scopeOut'); c_planningController = connect(motionPorts(1),controllerCompPortIn); c_planningScope = connect(scopeCompPortOut,motionPorts(2)); c_planningConnect = connect(controllerCompPortOut,scopeCompPortIn,'GeneralProfile.standardConn');
Save the model.
save(model)
Arrange the layout by pressıng Ctrl+Shift+A or using the following command:
Simulink.BlockDiagram.arrangeSystem('mobileRobotAPI/Motion');
Create a Model Reference
Model references are useful to organize large models hierarchically and allow you to define architectures or behaviors once and reuse it. When a component references another model, any existing ports on the component are removed and ports that exist on the referenced model will appear on the component.
Create a new System Composer model. Convert the Sensor
component into a reference component to reference the new model. To add additional ports on the Sensor
component, you must update the referenced model mobileSensor
.
newModel = systemcomposer.createModel('mobileSensor'); newArch = newModel.Architecture; newComponents = addComponent(newArch,'ElectricSensor'); save(newModel); linkToModel(components(1),'mobileSensor');
Apply a stereotype to the linked reference model's architecture and component.
referenceModel = get_param('mobileSensor','SystemComposerModel'); referenceModel.applyProfile('GeneralProfile'); referenceModel.Architecture.applyStereotype('GeneralProfile.softwareComponent'); batchApplyStereotype(referenceModel.Architecture,'Component','GeneralProfile.projectElement')
Add ports and connections to the reference component.
sensorPorts = addPort(components(1).Architecture,{'MotionData','SensorData'},{'in','out'}); sensorPorts(2).setInterface(interface) connect(arch,components(1),components(2),'Rule','interfaces'); connect(arch,components(3),components(1));
Save the models.
save(referenceModel) save(model)
Make a Variant Component
You can convert the Planning
component into a variant component using the makeVariant
function. The original component is embedded within a variant component as one of the available variant choices. You can design other variant choices within the variant component and toggle the active choice. Variant components allow you to choose behaviorial designs programmatically in an architecture model to perform trade studies and analysis.
[variantComp,choice1] = makeVariant(components(2));
Add an additional variant choice named PlanningAlt
. The second argument defines the name, and the third argument defines the label. The label identifies the choice. The active choice is controlled by the label.
choice2 = addChoice(variantComp,{'PlanningAlt'},{'PlanningAlt'});
Create the necessary ports on PlanningAlt
.
setActiveChoice(variantComp,choice2) planningAltPorts = addPort(choice2.Architecture,{'Command','SensorData1','MotionCommand'},{'in','in','out'}); planningAltPorts(2).setInterface(interface);
Make PlanningAlt
the active variant.
setActiveChoice(variantComp,'PlanningAlt')
Arrange the layout by pressıng Ctrl+Shift+A or using the following command:
Simulink.BlockDiagram.arrangeSystem('mobileRobotAPI/Planning');
Save the model.
save(model)
Clean Up
Uncomment the following code and run to clean up the artifacts created by this example:
% bdclose('mobileRobotAPI') % bdclose('mobileSensor') % Simulink.data.dictionary.closeAll % systemcomposer.profile.Profile.closeAll % delete('Profile.xml') % delete('SensorInterfaces.sldd')
Term | Definition | Application | More Information |
---|---|---|---|
interface | An interface defines the kind of information that flows through a port. The same interface can be assigned to multiple ports. An interface can be composite, meaning that it can include elements that describe the properties of an interface signal. | Interfaces represent the information that is shared through a connector and enters or exits a component through a port. Use the Interface Editor to create and manage interfaces and interface elements and store them in an interface data dictionary for reuse between models. | Define Interfaces |
interface element | An interface element describes a portion of an interface, such as a communication message, a calculated or measured parameter, or other decomposition of that interface. | Interface elements describe the decompositions of an interface:
| Assign Interfaces to Ports |
interface dictionary | An interface data dictionary is a consolidated list of all the interfaces in an architecture and where they are used. Local interfaces on a System Composer model can be saved in an interface data dictionary using the Interface Editor. | Interface dictionaries can be reused between models that need to use a given set of interfaces and interface elements. Data dictionaries are stored in separate .sldd files. | |
adapter | An adapter helps connect two components with incompatible port interfaces by mapping between the two interfaces. An adapter can also act as a unit delay or rate transition. | With an adapter, you can perform three functions on the Interface Adapter dialog:
| Interface Adapter |
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
Select web siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.