Main Content

Configure Lookup Tables for AUTOSAR Measurement and Calibration

In Simulink®, you can implement standard axis (STD_AXIS) and common axis (COM_AXIS) lookup tables for AUTOSAR applications. AUTOSAR applications can use lookup tables in either or both of two ways:

  • Implement fast search operations.

  • Support tuning of the application with measurement and calibration tools.

To model lookup tables for automotive application tuning, use the classes Simulink.LookupTable and Simulink.Breakpoint. By creating Simulink.LookupTable and Simulink.Breakpoint objects in the model workspace, you can store and share lookup table and breakpoint data and configure the data for AUTOSAR code generation.

Configure STD_AXIS Lookup Tables by Using Lookup Table Objects

This example shows how to create STD_AXIS lookup tables in Simulink, using Simulink.LookupTable objects, and configure the lookup tables for AUTOSAR code generation. The example uses the model mAutosarLutObjs.slx from matlabroot/help/toolbox/autosar/examples. To copy the model file to your working folder, enter this MATLAB® command:

copyfile(fullfile(matlabroot,'help/toolbox/autosar/examples/mAutosarLutObjs.slx'),'.')
  1. Model an AUTOSAR lookup table in a STD_AXIS configuration.

    1. In a mapped AUTOSAR software component model, add an AUTOSAR Blockset Curve or Map block. This example adds a Curve block.

    2. Open the Curve block and configure it to generate a routine from the AUTOSAR 4.0 code replacement library (CRL). As you modify block settings, the block dialog box updates the name of the targeted AUTOSAR routine.

      In the block dialog box, make these selections:

      • To generate a floating-point routine, select IFL (floating-point).

      • In the Table Specification tab, to specify table data using a lookup table object, set Data Specification to Lookup table object.

    3. In the model workspace, create a Simulink.LookupTable object and configure it to store the lookup table data.

    4. In the Curve block dialog box, Table Specification tab, enter the Simulink.LookupTable object name in the Name field.

    5. In the block dialog box, Algorithm tab, set Integer Rounding Method to Zero. Leave Interpolation Method set to Linear point-slope and Index Search Method set to Linear search.

    Table data appears in generated AUTOSAR C code as fields of a single structure. To control the characteristics of the structure type, such as its name, use the properties of the object.

  2. Connect the Curve or Map block.

    • Add AUTOSAR operating points to the lookup tables. Connect a root-level inport to the Curve or Map block. Alternatively, configure an input signal to the Curve or Map block with static global memory.

    • Connect an outport to the Curve or Map block.

  3. In the AUTOSAR code perspective, use the Code Mappings editor to map Simulink.LookupTable objects to AUTOSAR internal calibration parameters. In the Parameters tab, select each Simulink.LookupTable object that you created. Map each object to AUTOSAR parameter type ConstantMemory, SharedParameter, or Auto. To accept software mapping defaults, specify Auto.

    In this example, STD_AXIS lookup table object L_4_single is mapped to AUTOSAR ConstantMemory.

  4. For each parameter, if you select a parameter type other than Auto, use the Property Inspector to view or modify other code and calibration attributes. For more information on parameter properties, see Map Model Workspace Parameters to AUTOSAR Component Parameters.

  5. Configure the model to generate C code based on the AUTOSAR 4.0 library. Open the Configuration Parameters dialog box and select Code Generation > Interface. Set the Code replacement library parameter to AUTOSAR 4.0. For more information, see Code Generation with AUTOSAR Code Replacement Library.

  6. Build the model. The generated C code contains the expected Ifl and Ifx lookup function calls and Rte data access function calls. For example, you can search the HTML code generation report for the Ifl or Ifx routine prefix.

    The generated ARXML files contain data types of category CURVE (1-D table data) and MAP (2-D table data). The data types have the data calibration properties that you configured.

Configure COM_AXIS Lookup Tables by Using Lookup Table and Breakpoint Objects

This example shows how to create COM_AXIS lookup tables in Simulink, using Simulink.LookupTable and Simulink.Breakpoint objects, and configure the lookup tables for AUTOSAR code generation. The example uses the model mAutosarLutObjs.slx from matlabroot/help/toolbox/autosar/examples. To copy the model file to your working folder, enter this MATLAB command:

copyfile(fullfile(matlabroot,'help/toolbox/autosar/examples/mAutosarLutObjs.slx'),'.')

In this example, to model an AUTOSAR lookup table in a COM_AXIS configuration, you pair AUTOSAR Blockset Prelookup blocks with Curve Using Prelookup or Map Using Prelookup blocks.

  1. Configure Prelookup blocks.

    1. In a mapped AUTOSAR software component model, add one or more AUTOSAR Blockset Prelookup blocks. This example adds one Prelookup block.

    2. Open each block and configure it to generate a routine from the AUTOSAR 4.0 code replacement library (CRL). As you modify block settings, the block updates the name of the targeted AUTOSAR routine.

      In the block dialog box, make these selections:

      • To generate a floating-point routine, select IFL (floating-point).

      • In the Table Specification tab, to specify breakpoint data using a breakpoint object, set Breakpoints specification to Breakpoint object.

    3. For each breakpoint vector, in the model workspace, create and configure a Simulink.Breakpoint object.

    4. In the Prelookup block dialog box, Table Specification tab, enter the Simulink.Breakpoint object name in the Name field. You can reduce memory consumption by sharing breakpoint data between lookup tables.

    5. In the block dialog box, Algorithm tab, set Integer Rounding Method to Zero. Leave Index Search Method set to Linear search.

  2. Configure Curve Using Prelookup and Map Using Prelookup blocks.

    1. In the model, add one or more AUTOSAR Blockset Curve Using Prelookup or Map Using Prelookup blocks. Each block immediately follows a Prelookup block with which it is paired. This example adds one Curve Using Prelookup block.

    2. Open each Curve Using Prelookup or Map Using Prelookup block and configure it to generate a routine from the AUTOSAR 4.0 code replacement library (CRL). As you modify block settings, the block dialog box updates the name of the targeted AUTOSAR routine.

      In the block dialog box, make these selections:

      • To generate a floating-point routine, select IFL (floating-point).

      • In the Table Specification tab, to specify table data using a lookup table object, set Data Specification to Lookup table object.

    3. For each set of table data, in the model workspace, create and configure a Simulink.LookupTable object.

    4. In each Curve Using Prelookup or Map Using Prelookup block dialog box, Table Specification tab, enter a Simulink.LookupTable object name in the Name field.

    5. In the block dialog box, Algorithm tab, set Integer Rounding Method to Zero. Leave Interpolation Method set to Linear point-slope.

    Each set of table data appears in the generated C code as a separate array variable. If the table size is tunable, each breakpoint vector appears as a structure. The structure contains a field to store the breakpoint data and, optionally, a field to store the length of the vector. The second field enables you to tune the effective size of the table. If the table size is not tunable, each breakpoint vector appears as an array.

  3. Connect the Prelookup, Curve Using Prelookup, and Map Using Prelookup blocks.

    • Add AUTOSAR operating points to the lookup tables. Connect root-level inports to the Prelookup blocks. Alternatively, configure input signals to the Prelookup blocks with static global memory.

    • Connect outports to the Curve Using Prelookup and Map Using Prelookup blocks.

    • Connect each Prelookup block to its matched Curve Using Prelookup or Map Using Prelookup block.

  4. In the AUTOSAR code perspective, use the Code Mappings editor to map Simulink.LookupTable and Simulink.Breakpoint objects to AUTOSAR internal calibration parameters. In the Parameters tab, select each Simulink.LookupTable and Simulink.Breakpoint object that you created. Map each object to AUTOSAR parameter type ConstantMemory, SharedParameter, or Auto. To accept software mapping defaults, specify Auto.

    In this example, COM_AXIS breakpoint object Bp_4_single and lookup table object Lcom_4_single are mapped to AUTOSAR SharedParameters. All instances of the AUTOSAR software component share the COM_AXIS parameters.

  5. For each parameter, if you select a parameter type other than Auto, use the Property Inspector to view or modify other code and calibration attributes. For more information on parameter properties, see Map Model Workspace Parameters to AUTOSAR Component Parameters.

  6. Configure the model to generate C code based on the AUTOSAR 4.0 library. Open the Configuration Parameters dialog box and select Code Generation > Interface. Set the Code replacement library parameter to AUTOSAR 4.0. For more information, see Code Generation with AUTOSAR Code Replacement Library.

  7. Build the model. The generated C code contains the expected Ifl and Ifx lookup function calls and Rte data access function calls. For example, you can search the HTML code generation report for the Ifl or Ifx routine prefix.

    The generated ARXML files contain data types of category CURVE (1-D table data), MAP (2-D table data), and COM_AXIS (axis data). The data types have the data calibration properties that you configured.

Configure Array Layout for Multidimensional Lookup Tables

If an AUTOSAR model contains multidimensional lookup tables, you can configure the layout of lookup table array data for code generation as column-major or row-major. In the Simulink Configuration Parameters dialog box, Interface pane, set Array layout (Simulink Coder) to Column-major (the default) or Row-major. The array layout selection affects code generation, including C code and exported ARXML descriptions.

If you select row-major layout, go to the Math and Data Types pane and select the configuration option Use algorithms optimized for row-major array layout. The algorithm selection affects simulation and code generation.

Exporting multidimensional lookup tables generates ARXML lookup table descriptions with the SwRecordLayout category set to either COLUMN_DIR or ROW_DIR. For example, this program listing shows the SwRecordLayout descriptions exported for an AUTOSAR model that contains a 2-dimensional row-major lookup table. The lookup table is implemented by using an AUTOSAR Map block.

<AR-PACKAGE>
    <SHORT-NAME>SwRecordLayouts</SHORT-NAME>
    <ELEMENTS>
        <SW-RECORD-LAYOUT UUID="...">
            <SHORT-NAME>Map_s16</SHORT-NAME>
            <SW-RECORD-LAYOUT-GROUP>
                <SHORT-LABEL>Val</SHORT-LABEL>
                <CATEGORY>ROW_DIR</CATEGORY>
                <SW-RECORD-LAYOUT-GROUP-AXIS>1</SW-RECORD-LAYOUT-GROUP-AXIS>
                <SW-RECORD-LAYOUT-GROUP-INDEX>X</SW-RECORD-LAYOUT-GROUP-INDEX>
                <SW-RECORD-LAYOUT-GROUP-FROM>1</SW-RECORD-LAYOUT-GROUP-FROM>
                <SW-RECORD-LAYOUT-GROUP-TO>-1</SW-RECORD-LAYOUT-GROUP-TO>
                <SW-RECORD-LAYOUT-GROUP>
                    <SW-RECORD-LAYOUT-GROUP-AXIS>2</SW-RECORD-LAYOUT-GROUP-AXIS>
                    <SW-RECORD-LAYOUT-GROUP-INDEX>Y</SW-RECORD-LAYOUT-GROUP-INDEX>
                    <SW-RECORD-LAYOUT-GROUP-FROM>1</SW-RECORD-LAYOUT-GROUP-FROM>
                    <SW-RECORD-LAYOUT-GROUP-TO>-1</SW-RECORD-LAYOUT-GROUP-TO>
                    <SW-RECORD-LAYOUT-V>
                        <SHORT-LABEL>Val</SHORT-LABEL>
                        <BASE-TYPE-REF DEST="SW-BASE-TYPE">
                          /DataTypes/SwBaseTypes/sint32
                        </BASE-TYPE-REF>
                        <SW-RECORD-LAYOUT-V-AXIS>0</SW-RECORD-LAYOUT-V-AXIS>
                        <SW-RECORD-LAYOUT-V-PROP>VALUE</SW-RECORD-LAYOUT-V-PROP>
                        <SW-RECORD-LAYOUT-V-INDEX>X Y</SW-RECORD-LAYOUT-V-INDEX>
                    </SW-RECORD-LAYOUT-V>
                </SW-RECORD-LAYOUT-GROUP>
            </SW-RECORD-LAYOUT-GROUP>
        </SW-RECORD-LAYOUT>
        <SW-RECORD-LAYOUT UUID="...">
            <SHORT-NAME>Distr_s8_M</SHORT-NAME>
            <SW-RECORD-LAYOUT-GROUP>
                <SHORT-LABEL>Y</SHORT-LABEL>
                <CATEGORY>INDEX_INCR</CATEGORY>
                <SW-RECORD-LAYOUT-GROUP-AXIS>1</SW-RECORD-LAYOUT-GROUP-AXIS>
                <SW-RECORD-LAYOUT-GROUP-FROM>1</SW-RECORD-LAYOUT-GROUP-FROM>
                <SW-RECORD-LAYOUT-GROUP-TO>-1</SW-RECORD-LAYOUT-GROUP-TO>
                <SW-RECORD-LAYOUT-V>
                    <SHORT-LABEL>VALUE</SHORT-LABEL>
                    <BASE-TYPE-REF DEST="SW-BASE-TYPE">
                      /DataTypes/SwBaseTypes/sint32
                    </BASE-TYPE-REF>
                    <SW-RECORD-LAYOUT-V-AXIS>1</SW-RECORD-LAYOUT-V-AXIS>
                    <SW-RECORD-LAYOUT-V-PROP>VALUE</SW-RECORD-LAYOUT-V-PROP>
                </SW-RECORD-LAYOUT-V>
            </SW-RECORD-LAYOUT-GROUP>
        </SW-RECORD-LAYOUT>
    </ELEMENTS>
</AR-PACKAGE>

Importing ARXML files with multidimensional lookup table descriptions creates Simulink lookup tables with Array layout set to Column-major or Row-major. If the ARXML files contain only row-major multidimensional lookup table descriptions, the ARXML importer creates Simulink lookup tables with Array layout set to Row-major and Use algorithms optimized for row-major array layout enabled.

See Also

| | | | | | | |

Related Examples

More About