Main Content

Combine and Simulate AUTOSAR Software Components

When you develop multiple AUTOSAR software component models that are interconnected and work together, you can combine them in an AUTOSAR composition model for simulation. A composition is an AUTOSAR software component that aggregates related groups of software components.

To create a Simulink® representation of an AUTOSAR composition, take one of these actions:

  • Import an AUTOSAR XML (ARXML) description of a composition (Classic Platform).

  • Create a model and use Model blocks to reference and connect AUTOSAR component models.

Alternatively, if you have System Composer™ software, you can create an AUTOSAR architecture model and use Software Composition blocks to model AUTOSAR compositions. For more information, see Software Architecture Modeling.

When you simulate a composition model, you simulate the combined behavior of the aggregated AUTOSAR components.

After you develop AUTOSAR components and compositions, you can test groups of components that belong together in a system-level simulation. For example, you can create a system-level model containing compositions, components, a scheduler, a plant model, and potentially Basic Software service components and callers. You can configure system-level models to perform closed-loop or open-loop system simulations.

Import AUTOSAR Composition as Model (Classic Platform)

A composition is an AUTOSAR software component that aggregates related groups of software components. Compositions support component scaling and help to manage complexity in a design.

If you are developing software components for the AUTOSAR Classic Platform, you can create an AUTOSAR composition model by importing a composition description from ARXML files. Use the AUTOSAR importer function createCompositionAsModel. This function call creates composition model ThrottlePositionControlComposition from the example ARXML file ThrottlePositionControlComposition.arxml.

openExample('autosarblockset/ImportAUTOSARCompositionToSimulinkExample');
ar = arxml.importer('ThrottlePositionControlComposition.arxml');
createCompositionAsModel(ar,'/Company/Components/ThrottlePositionControlComposition');

To simulate the combined behavior of the aggregated AUTOSAR components, simulate the composition model. Click the Run button in the model window or enter this MATLAB® command.

simOutComposition = sim('ThrottlePositionControlComposition');

For more information, see Import AUTOSAR Composition to Simulink.

Create Composition Model for Simulating AUTOSAR Components

To combine related AUTOSAR software components in a composition model for simulation, create a Simulink model and use Model blocks to reference and connect AUTOSAR component models.

This example creates an AUTOSAR composition model. The created model is a simplified version of AUTOSAR example model autosar_composition. To expedite configuration and resolve issues, you can compare the new model against example model autosar_composition. If needed, you can copy elements such as inports and outports between the models. For a diagram of the finished composition model, see step 4.

  1. Move AUTOSAR software component models that you want to simulate together into a working folder and cd to that folder. This example uses the following component models.

    • autosar_swc_actuator

    • autosar_swc_controller

    • autosar_swc_pedal_sensor

    • autosar_swc_throttle_sensor

    These models can be accessed by using the openExample command, where the input argument is the name of the model specified as a character vector.

  2. Create a Simulink model. Save the model to the working folder with the name composition.

  3. For each AUTOSAR component model:

    1. Open the component model separately and verify that it simulates.

    2. In the composition model, add a Model block and configure the block to reference the component. In the Model block parameters, select option Schedule rates. This option allows rate-based runnable tasks to be scheduled on the same basis as exported functions.

    3. Add ports that the component requires.

    4. Component model autosar_swc_throttle_sensor requires a special adjustment, because parent model composition (unlike example model autosar_composition) references the component only once. Open Model Explorer, select the model workspace for autosar_swc_throttle_sensor, select data object TPSPercent_LkupTbl, and clear the Argument option.

  4. When you have created Model blocks for each AUTOSAR component, connect the components as shown here.

To simulate the combined behavior of the aggregated AUTOSAR components, simulate the composition model. Click the Run button in the model window or enter this MATLAB command.

simOutComposition = sim('composition');

For more information, see Design and Simulate AUTOSAR Components and Generate Code.

Alternatives for AUTOSAR System-Level Simulation

After you develop AUTOSAR components and compositions, you can test groups of components that belong together in a system-level simulation. For example, you can create a system-level model containing compositions, components, a plant model, and potentially Basic Software service components and callers. You can configure system-level models to perform closed-loop or open-loop system simulations. For a system-level model, use a Simulink model or a Simulink Test™ test harness model.

For an example of a closed-loop simulation, open example model autosar_system. This model provides a system-level test harness for the AUTOSAR composition model autosar_composition.

openExample('autosar_system');

A throttle position scope opens with the model. If you simulate system-level model autosar_system, the scope indicates how well the throttle-position control algorithms in composition model autosar_composition are tracking the pedal input. To improve the behavior, you can modify component algorithms in the composition or change a sensor source.

simOutSystem = sim('autosar_system');

For more information, see Design and Simulate AUTOSAR Components and Generate Code.

For an example of open-loop simulation using Simulink Test, see Testing AUTOSAR Compositions (Simulink Test). This example performs back-to-back testing for an AUTOSAR composition model.

For an example of simulating AUTOSAR Basic Software services, see Simulate AUTOSAR Basic Software Services and Run-Time Environment.

See Also

Related Examples

More About