Common base class for all components in architecture model
A systemcomposer.arch.BaseComponent
cannot be constructed.
Either create a systemcomposer.arch.Component
or systemcomposer.arch.VariantComponent
. This class is derived from systemcomposer.arch.Element
.
Name
— Name of componentName of component, specified as a character vector.
Example: 'newComponent'
Data Types: char
Architecture
— Architecture that defines component structureArchitecture that defines component structure, specified as a systemcomposer.arch.Architecture
object. For a component that references a
different architecture model, this property returns a handle to the root architecture of
that model. For variant components, the architecture is that of the active
variant.
Parent
— Architecture that owns componentArchitecture that owns component, specified as a systemcomposer.arch.Architecture
object.
Ports
— Input and output ports of componentInput and output ports of component, specified as a systemcomposer.arch.ComponentPort
object.
OwnedArchitecture
— Architecture owned by componentArchitecture owned by component, specified as a systemcomposer.arch.Architecture
object.
OwnedPorts
— Component portsComponent ports, specified as an array of systemcomposer.arch.ComponentPort
objects. For reference components, this
property is empty.
Position
— Position of component on canvasPosition of component on canvas, specified as a vector of coordinates, in pixels
[left top right bottom]
.
Data Types: double
UUID
— Universal unique identifierUniversal unique identifier for model component, 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 element and through all operations that preserve the
UUID
.
Data Types: char
Model
— Parent System Composer™ modelParent model of component, specified as a systemcomposer.arch.Model
object.
SimulinkHandle
— Simulink handleSimulink handle for component, specified as a double
. This
property is necessary for several Simulink related work flows and for using Simulink
Requirement APIs.
Example: handle = get(object,'SimulinkHandle')
Data Types: double
SimulinkModelHandle
— Simulink handle to parent System Composer modelSimulink handle to parent model of component, specified as a
double
. This property is necessary for several Simulink related
work flows and for using Simulink Requirement APIs.
Example: handle = get(object,'SimulinkModelHandle')
Data Types: double
getProperty | Get property value corresponding to stereotype applied to element |
setProperty | Set property value corresponding to stereotype applied to element |
getPropertyValue | Get value of architecture property |
getEvaluatedPropertyValue | Get evaluated value of property from component |
getStereotypeProperties | Get stereotype property names on element |
applyStereotype | Apply stereotype to architecture model element |
getStereotypes | Get stereotypes applied on element of architecture model |
removeStereotype | Remove stereotype from model element |
isReference | Find if component is reference to another model |
connect | Create architecture model connections |
getPort | Get port from component |
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 |
---|---|---|---|
architecture | A System Composer architecture represents a system of components and how they interface with each other structurally and behaviorally. You can represent specific architectures using alternate views. | Different types of architectures describe different aspects of systems:
| Compose Architecture Visually |
model | A System Composer model is the file that contains architectural information, including components, ports, connectors, interfaces, and behaviors. | Perform operations on a model:
System Composer models are stored as | Create an Architecture Model |
component | A component is a nontrivial, nearly-independent, and replaceable part of a system that fulfills a clear function in the context of an architecture. A component defines an architecture element, such as a function, a system, hardware, software, or other conceptual entity. A component can also be a subsystem or subfunction. | Represented as a block, a component is a part of an architecture model that can be separated into reusable artifacts. | Components |
port | A port is a node on a component or architecture that represents a point of interaction with its environment. A port permits the flow of information to and from other components or systems. | There are different types of ports:
| Ports |
connector | Connectors are lines that provide connections between ports. Connectors describe how information flows between components or architectures. | A connector allows two components to interact without defining the nature of the interaction. Set an interface on a port to define how the components interact. | Connections |
Component | systemcomposer.arch.Component
| systemcomposer.arch.Element
| systemcomposer.arch.VariantComponent
다음 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.