This example shows how to build an architecture model using the System Composer API.
systemcomposer.profile.Profile.closeAll;
model = systemcomposer.createModel('mobileRobotAPI'); arch = model.Architecture; components = addComponent(arch,{'Sensor','Planning','Motion'}); sensorPorts = addPort(components(1).Architecture,{'MotionData','SensorData'},{'in','out'}); planningPorts = addPort(components(2).Architecture,{'Command','SensorData','MotionCommand'},{'in','in','out'}); motionPorts = addPort(components(3).Architecture,{'MotionCommand','MotionData'},{'in','out'}); c_sensorData = connect(arch,components(1),components(2)); c_motionData = connect(arch,components(3),components(1)); c_motionCommand = connect(arch,components(2),components(3));
Add a port on the architecture. This is an architecture port.
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');
Profiles are xml
files that can be applied to any model.
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 at the discretion of the user:
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 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');
Apply profile to the model:
applyProfile(model,'GeneralProfile');
Apply stereotypes to components. Some components are physical components, 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
Create a data dictionary and add an interface:
dictionary = systemcomposer.createDictionary('SensorInterfaces.sldd'); interface = addInterface(dictionary,'GPSInterface');
Link the interface to the model:
linkDictionary(model,'SensorInterfaces.sldd');
Identify the interface in the dictionary:
interface_GPS = getInterface(model.InterfaceDictionary,'GPSInterface');
Set the interface for the port:
setInterface(sensorPorts(2),interface_GPS);
Save the changes to the data dictionary.
dictionary.save();
Uncomment the following code and run to clean up the artifacts created by this example:
% bdclose('mobileRobotAPI'); % systemcomposer.profile.Profile.closeAll; % delete('SensorInterfaces.sldd');