Main Content

Configure AUTOSAR Architecture Model Programmatically

An AUTOSAR architecture model provides resources and a canvas for developing AUTOSAR composition and component models. You develop the software architecture by using graphical user interfaces, equivalent architecture modeling functions, or both. AUTOSAR Blockset provides functions for these architecture related tasks.

TasksFunctions
Create, load, open, save, or close an AUTOSAR architecture modelautosar.arch.createModel
autosar.arch.loadModel
close
open
save
Specify the platform kind of an AUTOSAR architecture modelsetPlatform
Add, connect, or remove AUTOSAR components, composition, and portsaddComponent
addComposition
addPort
connect
destroy
importFromARXML
layout
Find AUTOSAR elements and modify propertiesfind
get
set
Define component behavior by creating or linking Simulink® modelscreateModel
linkToModel
Add Basic Software (BSW) service component blocks for simulating BSW service callsaddBSWService
Export composition and component ARXML descriptions and generate component code (requires Embedded Coder®)export
getXmlOptions
setXmlOptions

Programmatically Create and Configure Architecture Model

This example shows how to programmatically interact with AUTOSAR architecture models, their compositions and components, creating and linking to Simulink® implementation models, and data dictionary workflows.

This example uses programmatic interfaces to perform the following tasks:

  1. Create and open an AUTOSAR architecture model.

  2. Open and link a data dictionary containing data types and interfaces.

  3. Set the platform kind of the architecture model to the Classic Platform explicitly.

  4. Add a composition and components.

  5. Add architecture, composition, and component ports.

  6. Connect architecture, composition, and component ports.

  7. Create and link Simulink implementation models for components.

  8. Arrange architecture model layout based on heuristics.

  9. Set component and port properties.

  10. Remove a component.

  11. Search for elements at different levels of the architecture model hierarchy.

  12. List property values for composition ports.

Copy commands from the steps below to the MATLAB® command window.

1. Create and open an AUTOSAR architecture model, myArchModel.

modelName = "myArchModel";
archModel = autosar.arch.createModel(modelName);

2. Open the data dictionary, tpc_interfaces.sldd, and link it to myArchModel.

dictName = "tpc_interfaces.sldd";
archDataObj = Simulink.dictionary.archdata.open("tpc_interfaces.sldd");
set_param(modelName,"DataDictionary",dictName);

3. Set the platform kind of the architecture model to the AUTOSAR Classic Platform. By default the autosar.arch.createModel function creates an architecture model configured for the Classic Platform, but you can also set the platform kind directly using the setPlatform function.

setPlatform(archModel,"Classic");

4. Add a composition, Sensors, to myArchModel.

composition = addComposition(archModel,"Sensors");

5. Add components representing the pedal and throttle sensors to the composition Sensors.

names = {"PedalSnsr","ThrottleSnsr"};
sensorSWCs = addComponent(composition,names,"Kind","SensorActuator");

6. Use the layout function to auto-arrange the composition layout.

layout(composition);

7. At the top level of the architecture model, add components representing the controller and actuator.

controller = addComponent(archModel,"Controller");
actuator = addComponent(archModel,"Actuator");

8. Set the Kind property of the actuator and organize the layout of the model, now that new components have been added.

set(actuator,"Kind","SensorActuator");
layout(archModel); 

9. Add ports to myArchModel and Sensors. Specify the port kind to be either Sender or Receiver.

addPort(archModel,"Receiver",{'APP_HwIO', 'TPS_HwIO'});
addPort(archModel,"Sender","ThrCmd_HwIO");
addPort(composition,"Receiver",{'TPS_HwIO','APP_HwIO'});
addPort(composition,"Sender",{'APP_Percent', 'TPS_Percent'});

10. Link the components representing the pedal sensor, actuator and controller to the pre-existing Simulink models: autosar_tpc_pedal_sensor, autosar_tpc_actuator, and autosar_tpc_controller.

pedalSnsr = find(composition,"Component","Name","PedalSnsr");
linkToModel(pedalSnsr,"autosar_tpc_pedal_sensor");
linkToModel(actuator, "autosar_tpc_actuator");
linkToModel(controller, "autosar_tpc_controller")

11. Use the find function to find the throttle sensor component of the Sensors composition.

ThrottleSensor = find(composition,"Component","Name","ThrottleSnsr");

12. Add ports to the throttle sensor component using the addPort function.

sport = addPort(ThrottleSensor,"Sender","TPS_Percent");
rport = addPort(ThrottleSensor,"Receiver","TPS_HwIO");

13. Get and set the interfaces for the sender and receiver ports from the data dictionary.

sInt = getInterface(archDataObj,"TPS_Percent");
rInt = getInterface(archDataObj,"TPS_HwIO");
setInterface(sport,sInt);
setInterface(rport,rInt);

14. Create the model representing the throttle sensor.

createModel(ThrottleSensor);

15. Connect the composition and components based on their matching port names and using the connect function.

connect(archModel,composition,controller);
connect(archModel,controller,actuator);
connect(archModel,[],composition);
connect(archModel,actuator,[]);
connect(composition,[],pedalSnsr);
connect(composition,[],ThrottleSensor);
connect(composition,pedalSnsr,[]);
connect(composition,ThrottleSensor,[]);
connect(archModel,composition,controller);

16. Alternatively, use the find function to find specific ports, and then use the found information to only connect specific ports.

ThrCmd_Percent_pport = find(controller,"Port","Name","ThrCmd_Percent");
ThrCmd_Percent_rport = find(actuator,"Port","Name","ThrCmd_Percent");
connect(archModel, ThrCmd_Percent_pport, ThrCmd_Percent_rport);

layout(archModel);  

17. Use the find function to search for components in the top level of an architecture model:

components_in_arch_top_level = find(archModel,"Component");

Search an entire hierarchy:

components_in_all_hierarchy = find(archModel,"Component","AllLevels",true);

Search only a single composition:

composition_ports = find(composition,"Port");

18. List specific property values for composition ports using a for loop.

for ii=1:length(composition_ports)
    Port = composition_ports(ii);
    portName = get(Port,"Name");
    portKind = get(Port,"Kind");
    fprintf('%s port %s\n',portKind,portName);
end
Receiver port TPS_HwIO
Receiver port APP_HwIO
Sender port APP_Percent
Sender port TPS_Percent

19. Finally, simulate the architecture model.

sim(modelName);

See Also

| | |

Related Topics