Main Content

Import AUTOSAR Composition to Simulink

Create Simulink® model from XML description of AUTOSAR software composition.

Import AUTOSAR Composition from ARXML File to Simulink

Here is an AUTOSAR software composition that implements a throttle position control system. The composition contains six interconnected AUTOSAR software component prototypes -- four sensor/actuator components and two application components.

The composition was created in an AUTOSAR authoring tool and exported to the file ThrottlePositionControlComposition.arxml.

Use the MATLAB function createCompositionAsModel to import the AUTOSAR XML (ARXML) description and create an initial Simulink representation of the AUTOSAR composition. First, parse the ARXML description file and list the compositions it contains.

ar = arxml.importer('ThrottlePositionControlComposition.arxml');
names = getComponentNames(ar,'Composition')
names = 1x1 cell array

For the listed software composition, use createCompositionAsModel to create a Simulink representation.

Created model 'ThrottlePositionSensor' for component 1 of 5: /Company/Components/ThrottlePositionSensor
Created model 'ThrottlePositionMonitor' for component 2 of 5: /Company/Components/ThrottlePositionMonitor
Created model 'Controller' for component 3 of 5: /Company/Components/Controller
Created model 'AccelerationPedalPositionSensor' for component 4 of 5: /Company/Components/AccelerationPedalPositionSensor
Created model 'ThrottlePositionActuator' for component 5 of 5: /Company/Components/ThrottlePositionActuator
Created model 'ThrottlePositionControlComposition' for composition 1 of 1:

The function call creates a composition model that contains six component models, one for each atomic software component in the composition. Simulink inports and outports represent AUTOSAR ports and signal lines represent AUTOSAR component connectors.

Develop AUTOSAR Component Algorithms, Simulate, and Generate Code

After creating an initial Simulink representation of the AUTOSAR composition, you develop each component in the composition. For each component, you refine the AUTOSAR configuration and create algorithmic model content.

For example, the Controller component model in the ThrottlePositionControlComposition composition model contains an atomic subsystem Runnable_Step_sys, which represents an AUTOSAR periodic runnable. The Runnable_Step_sys subsystem contains the initial stub implementation of the controller behavior.

Here is a possible implementation of the throttle position controller behavior. (To explore this implementation, see the model autosar_swc_controller, which is provided with the example Design and Simulate AUTOSAR Components and Generate Code.) The component takes as inputs an APP sensor percent value from a pedal position sensor and a TPS percent value from a throttle position sensor. Based on these values, the controller calculates the error. The error is the difference between where the operator wants the throttle, based on the pedal sensor, and the current throttle position. In this implementation, a Discrete PID Controller block uses the error value to calculate a throttle command percent value to provide to a throttle actuator. A scope displays the error value and the Discrete PID Controller block output value over time.

As you develop AUTOSAR components, you can:

  • Simulate component models individually or together in a containing composition.

  • Generate ARXML component description files and algorithmic C code for testing in Simulink or integration into an AUTOSAR run-time environment. (AUTOSAR code generation requires Simulink Coder and Embedded Coder.)

For more information on developing, simulating, and building AUTOSAR components, see example Design and Simulate AUTOSAR Components and Generate Code.

Update AUTOSAR Composition Model with Architectural Changes from Authoring Tool

Suppose that, after you imported the AUTOSAR software composition into Simulink and began developing algorithms, architectural changes were made to the composition in the AUTOSAR authoring tool.

Here is the revised composition. The changes delete a sensor component, add a logger component, and add ports and connections at the composition and component levels. In the AUTOSAR authoring tool, the revised composition is exported to the file ThrottlePositionControlComposition_updated.arxml.

Use the MATLAB function updateModel to import the architectural revisions from the ARXML file. The function updates the AUTOSAR composition model with the changes and reports the results.

ar2 = arxml.importer('ThrottlePositionControlComposition_updated.arxml');
### Updating model ThrottlePositionSensor
### Saving original model as ThrottlePositionSensor_backup.slx
### Creating HTML report ThrottlePositionSensor_update_report.html
Updated model 'ThrottlePositionSensor' for component 1 of 6:
### Updating model ThrottlePositionMonitor
### Saving original model as ThrottlePositionMonitor_backup.slx
### Creating HTML report ThrottlePositionMonitor_update_report.html
Updated model 'ThrottlePositionMonitor' for component 2 of 6:
Updated model 'Logger' for component 3 of 6: /Company/Components/Logger
### Updating model Controller
### Saving original model as Controller_backup.slx
### Creating HTML report Controller_update_report.html
Updated model 'Controller' for component 4 of 6: /Company/Components/Controller
### Updating model AccelerationPedalPositionSensor
### Saving original model as AccelerationPedalPositionSensor_backup.slx
### Creating HTML report AccelerationPedalPositionSensor_update_report.html
Updated model 'AccelerationPedalPositionSensor' for component 5 of 6:
### Updating model ThrottlePositionActuator
### Saving original model as ThrottlePositionActuator_backup.slx
### Creating HTML report ThrottlePositionActuator_update_report.html
Updated model 'ThrottlePositionActuator' for component 6 of 6:
Updated model 'ThrottlePositionControlComposition' for composition 1 of 1:
### Updating model ThrottlePositionControlComposition
### Saving original model as ThrottlePositionControlComposition_backup.slx
### Creating HTML report ThrottlePositionControlComposition_update_report.html

After the update, in the composition model, highlighting indicates where changes occurred.

The function also generates and displays an HTML AUTOSAR update report. The report lists changes that the update made to Simulink and AUTOSAR elements in the composition model. In the report, you can click hyperlinks to navigate from change descriptions to model changes, and to navigate from the main report to individual component reports.

Related Links