Main Content

Configure AUTOSAR Adaptive Software Components

In Simulink®, you can flexibly model the structure and behavior of software components for the AUTOSAR Adaptive Platform. The AUTOSAR Adaptive Platform defines a service-oriented architecture for automotive components that must flexibly adapt to external events and conditions.

An AUTOSAR adaptive software component provides and consumes services. Each software component contains:

  • An automotive algorithm, which performs tasks in response to received events.

  • Required and provided ports, each associated with a service interface.

  • Service interfaces, with associated events and associated namespaces.

For more information, see Model AUTOSAR Adaptive Software Components.

This example configures a Simulink representation of an automotive algorithm as an AUTOSAR adaptive software component. The configuration steps use example models LaneGuidance and autosar_LaneGuidance.

  1. Open a Simulink model that either is empty or contains a functional algorithm. This example uses ERT algorithm model LaneGuidance.

  2. Using the Model Configuration Parameters dialog box, Code Generation pane, configure the model for adaptive AUTOSAR code generation. Set System target file to autosar_adaptive.tlc. Apply the change.

    The new setting affects other model settings. For example, the target file selection:

    • Sets Language to C++.

    • Selects Generate code only.

    • Sets Toolchain to AUTOSAR Adaptive | CMake.

    • Sets Interface > Code interface packaging to C++ class.

  3. Develop the model algorithmic content for use in an AUTOSAR adaptive software component. If the model is empty, construct or copy in an algorithm. Possible sources for algorithms include algorithmic elements in other Simulink models. Examples include subsystems, referenced models, MATLAB Function blocks, and C Caller blocks.

  4. At the top level of the model, set up event-based communication, which the AUTOSAR Adaptive Platform requires for AUTOSAR required and provided ports. AUTOSAR Blockset provides Event Receive and Event Send blocks to make the necessary event/signal connections.

    • After each root inport, add an Event Receive block, which converts an input event to a signal while preserving the signal values and data type.

    • Before each root outport, add an Event Send block, which converts an input signal to an event while preserving the signal values and data type.

    Note

    Alternatively, you can skip this step. A later step provides a finished mapped model with event conversion blocks included.

    Here is example model LaneGuidance with the event blocks added and connected.

  5. Map the algorithm model to an AUTOSAR adaptive software component.

    1. To map the algorithm model, in the Apps tab, click AUTOSAR Component Designer. In this example the AUTOSAR Component Quick Start opens because the model is unmapped. Otherwise, to map algorithm information you can click the perspective control in the lower-right corner and select Code, or use the API to call MATLAB® function autosar.api.create(modelName).

    2. Work through the quick-start procedure. Click Finish to map the model.

    3. The model opens in the AUTOSAR Code perspective. The perspective displays the mapping of Simulink elements to AUTOSAR adaptive software component elements and an AUTOSAR Dictionary, which contains AUTOSAR adaptive component elements with default properties.

  6. If you completed the adaptive configuration steps, save the AUTOSAR adaptive software component model with a unique name.

    If you skipped any steps, open an example of a finished mapped AUTOSAR adaptive software component, example model autosar_LaneGuidance.

  7. Using the AUTOSAR Code perspective and the AUTOSAR Dictionary (or equivalent AUTOSAR map and property functions), further refine the AUTOSAR adaptive model configuration.

    • In the model window, check model data to see if you need to make post-mapping adjustments to types or other attributes. For example, verify that event data is configured correctly for your design.

    • In the AUTOSAR Code perspective, examine the mapping of Simulink inports and outports to AUTOSAR required and provided ports and events.

    • To open the AUTOSAR Dictionary, select an inport or outport and click the AUTOSAR Dictionary button . The dictionary opens in the view of the corresponding mapped AUTOSAR port.

      Select a port to configure its AUTOSAR attributes, such as manifest attributes or, for required ports, a service discovery mode.

    • In the dictionary, you can expand service interface nodes to examine the AUTOSAR events created by the default component mapping.

    • In the dictionary, you can define a unique namespace for each service interface. Example model autosar_LaneGuidance defines namespaces company::chassis::provided and company::chassis::required for the respective service interfaces. When you build the model, generated C++ code uses the service interface namespaces.

    • In the dictionary, in the XML options view, you can configure characteristics of exported AUTOSAR XML. To generate compact code, example model autosar_LaneGuidance sets XML option Exported XML file packaging to Single file. In the Model Configuration Parameters dialog box, the example model sets Code Placement > File packaging format to Compact.

  8. Build the AUTOSAR adaptive software component model. For example, in the model window, enter Ctrl+B. Building the model generates:

    • C++ files that implement the model algorithms for the AUTOSAR Adaptive Platform and provide shared data type definitions.

    • AUTOSAR XML descriptions of the AUTOSAR adaptive software component and manifest information for application deployment and service configuration.

    • C++ file that implements a main program module: main.cpp.

    • AUTOSAR Runtime Adaptive (ARA) environment header files.

    • CMakeLists.txt file that supports CMake generation of executables.

The generated C++ model files include model class definitions and AUTOSAR Runtime for Adaptive Applications (ARA) calls to implement the adaptive software component services. For example, model file autosar_LaneGuidance.cpp contains initialization code for each service interface and event. The code reflects the service interface namespaces and event names configured in the AUTOSAR Dictionary.

// Model initialize function
void autosar_LaneGuidance::initialize()
{
  {
    ara::com::ServiceHandleContainer< company::chassis::required::proxy::
      RequiredInterfaceProxy::HandleType > handles;

    // Initialize service provider instance - ProvidedPort
    ProvidedPort = std::make_shared< company::chassis::provided::skeleton::
      ProvidedInterfaceSkeleton >(ara::com::InstanceIdentifier(ara::core::
      StringView("2")), ara::com::MethodCallProcessingMode::kEventSingleThread);
    ProvidedPort->OfferService();

    // Initialize service requester instance - RequiredPort
    handles = company::chassis::required::proxy::RequiredInterfaceProxy::
      FindService(ara::com::InstanceIdentifier(ara::core::StringView("1")));
    if (handles.size() > 0U) {
      RequiredPort = std::make_shared< company::chassis::required::proxy::
        RequiredInterfaceProxy >(*handles.begin());

      // Subscribe events
      RequiredPort->LeftCarInBlindSpot.Subscribe(1U);
      RequiredPort->LeftLaneDistance.Subscribe(1U);
      RequiredPort->LeftTurnIndicator.Subscribe(1U);
      RequiredPort->RightCarInBlindSpot.Subscribe(1U);
      RequiredPort->RightLaneDistance.Subscribe(1U);
      RequiredPort->RightTurnIndicator.Subscribe(1U);
    }
  }
}
}

Model file autosar_LaneGuidance.cpp also contains step code for each service interface event. For example, the step code for RequiredInterface, event rightCarInBlindSpot, calls a function to fetch and handle new rightCarInBlindSpot event data received by AUTOSAR Runtime Adaptive (ARA) environment middleware.

// Model step function
void autosar_LaneGuidanceModelClass::step()
{
...
  if (RequiredPort) {
    resultPtr = std::make_shared< ara::core::Result<size_t> >
      (RequiredPort->LeftLaneDistance.GetNewSamples(std::move(std::bind
         (&autosar_LaneGuidance::RequiredPortLeftLaneDistanceReceive, this, std::
          placeholders::_1)), 1U));
    resultPtr->ValueOrThrow();
  }
...
}

The exported AUTOSAR XML code includes descriptions of AUTOSAR elements that you configured by using the AUTOSAR Dictionary. For example, component file autosar_LaneGuidance.arxml describes the namespaces and events specified for required and provided interfaces.

<SERVICE-INTERFACE UUID="...">
    <SHORT-NAME>RequiredInterface</SHORT-NAME>
    <NAMESPACES>
        <SYMBOL-PROPS>
            <SHORT-NAME>company</SHORT-NAME>
            <SYMBOL>company</SYMBOL>
        </SYMBOL-PROPS>
        <SYMBOL-PROPS>
            <SHORT-NAME>chassis</SHORT-NAME>
            <SYMBOL>chassis</SYMBOL>
        </SYMBOL-PROPS>
        <SYMBOL-PROPS>
            <SHORT-NAME>required</SHORT-NAME>
            <SYMBOL>required</SYMBOL>
        </SYMBOL-PROPS>
    </NAMESPACES>
    <EVENTS>
    ...
        <VARIABLE-DATA-PROTOTYPE UUID="...">
            <SHORT-NAME>RightCarInBlindSpot</SHORT-NAME>
            <CATEGORY>VALUE</CATEGORY>
            <SW-DATA-DEF-PROPS>
                <SW-DATA-DEF-PROPS-VARIANTS>
                    <SW-DATA-DEF-PROPS-CONDITIONAL>
                        <SW-CALIBRATION-ACCESS>READ-ONLY</SW-CALIBRATION-ACCESS>
                        <SW-IMPL-POLICY>QUEUED</SW-IMPL-POLICY>
                     </SW-DATA-DEF-PROPS-CONDITIONAL>
                </SW-DATA-DEF-PROPS-VARIANTS>
             </SW-DATA-DEF-PROPS>
             <TYPE-TREF DEST="STD-CPP-IMPLEMENTATION-DATA-TYPE">/AUTOSAR/StdTypes/double</TYPE-TREF>
         </VARIABLE-DATA-PROTOTYPE>
    </EVENTS>
</SERVICE-INTERFACE>

The generated C++ main program file provides a framework for running adaptive software component service code. For the autosar_LaneGuidance model, the main.cpp file:

  • Instantiates the adaptive software component model object.

  • Reports the adaptive application state to ARA.

  • Calls the model initialize and terminate functions.

  • Sets up asynchronous function call objects for each task.

  • Runs asynchronous function calls in response to base-rate tick semaphore posts.

See Also

|

Related Examples

More About