Main Content

Configure AUTOSAR CompuMethods

AUTOSAR software components use computation methods (CompuMethods) to convert between the internal values and physical representation of AUTOSAR data. Common uses for CompuMethods are linear data scaling and measurement and calibration.

Embedded Coder® imports AUTOSAR CompuMethods described in ARXML code and preserves them across round-trips between an AUTOSAR authoring tool (AAT) and Simulink®. In Simulink, you can modify imported CompuMethods or create and configure new CompuMethods.

This topic provides examples of configuring AUTOSAR CompuMethods in Simulink.

Configure AUTOSAR CompuMethod Properties

You can configure AUTOSAR CompuMethod properties in your model, either graphically or programmatically. The CompuMethod properties you can modify include name, category, unit, display format, AUTOSAR package, and Simulink data types.

To configure a CompuMethod using the graphical interface, open the AUTOSAR Dictionary and select the CompuMethods view. This view displays the modifiable CompuMethods in the model, whether imported from ARXML code or created in Simulink.

Select a CompuMethod and edit the available fields.

  • Name — Specify name text

  • Category — Select Identical, Linear, RatFunc, TextTable, or LinearAndTextTable (see CompuMethod Categories for Data Types)

  • Unit — Select from units available in the model

  • DisplayFormat — Optionally specify format to be used by measurement and calibration tools to display the data. Use an ANSI® C printf format specifier string. For example, %2.1d specifies a signed decimal number, with a minimum width of two characters and maximum precision of one digit. The string produces a displayed value such as 12.2. For more information about constructing a format specifier string, see Configure DisplayFormat.

  • Package — Specify path of AUTOSAR package to be generated for CompuMethods

  • Simulink DataTypes — Specify list of Simulink data types that reference the CompuMethod

To modify the AUTOSAR package for a CompuMethod, you can do either of the following:

  • Enter a package path in the Package parameter field.

  • To open the AUTOSAR Package Browser, click the button to the right of the Package field. Use the browser to navigate to an existing package or create and select a package. When you select a package in the browser and click Apply, the CompuMethod Package parameter value is updated with your selection. For more information about the AUTOSAR Package Browser, see Configure AUTOSAR Package for Component, Interface, CompuMethod, or SwAddrMethod.

To associate a CompuMethod with a Simulink data type used in the model, select a CompuMethod and click the Add button to the right of Simulink DataTypes. This action opens a dialog box with a list of available data types. In the list of values, select a Simulink.NumericType or Simulink.AliasType, or enter the name of a Simulink enumerated type. To add the type to the Simulink DataTypes list, click OK.

To set the Simulink DataTypes property programmatically, open the model and use an AUTOSAR property set function call similar to the following:

arProps=autosar.api.getAUTOSARProperties('cmSpeed');
set(arProps,'/pkg/CompuMethods/RpmCm','SlDataTypes',{'SpeedRpmAdt'})
sltypes=get(arProps,'/pkg/CompuMethods/RpmCm', 'SlDataTypes')
sltypes = 
    'SpeedRpmAdt'

Create AUTOSAR CompuMethods

You can create AUTOSAR CompuMethods in your model, either graphically or programmatically. To create an AUTOSAR CompuMethod using the graphical interface, open the AUTOSAR Dictionary and select the CompuMethods view. To open the Add CompuMethod dialog box, click the Add button . Configure the initial properties for the CompuMethod, such as name, category, unit, display format for calibration, AUTOSAR package to generate, and associated Simulink data type. When you click OK, the CompuMethods view in the AUTOSAR Dictionary is updated with the new CompuMethod.

When you generate code, the exported ARXML code contains the CompuMethod definition and references to it.

Configure CompuMethod Direction for Linear Functions

For designs originated in Simulink, you can control properties for an exported CompuMethod, including the direction of CompuMethod conversion between internal and physical representations of a value. Using either the AUTOSAR Dictionary or the AUTOSAR property set function, you can specify one of the following CompuMethod direction values:

  • InternalToPhys (default) — Generate CompuMethod sections for conversion of internal values into their physical representations.

  • PhysToInternal — Generate CompuMethod sections for conversion of physical values into their internal representations.

  • Bidirectional — Generate CompuMethod sections for both internal-to-physical and physical-to-internal conversion directions.

To specify CompuMethod direction in the MATLAB® Command Window, use an AUTOSAR property set function call similar to the following:

hModel = 'autosar_swc_expfcns';
addpath(fullfile(matlabroot,'/examples/autosarblockset/main'));
open_system(hModel);
arProps=autosar.api.getAUTOSARProperties(hModel);
set(arProps,'XmlOptions','CompuMethodDirection','Bidirectional');
get(arProps,'XmlOptions','CompuMethodDirection')

To specify CompuMethod direction in the AUTOSAR Dictionary, select XML Options. Select a value for parameter CompuMethod Direction. Click Apply.

When you generate code for your model, the CompuMethods in the exported ARXML code contain the requested directional sections. For example, here is a CompuMethod generated with the CompuMethod direction set to Bidirectional.

<COMPU-METHOD UUID="...">
    <SHORT-NAME>COMPU_EngSpdValue</SHORT-NAME>
    <CATEGORY>LINEAR</CATEGORY>
    <COMPU-INTERNAL-TO-PHYS>
    <COMPU-SCALES>
        <COMPU-SCALE>
        <SHORT-LABEL>intToPhys</SHORT-LABEL>
        <LOWER-LIMIT INTERVAL-TYPE="CLOSED">0</LOWER-LIMIT>
        <UPPER-LIMIT INTERVAL-TYPE="CLOSED">24000</UPPER-LIMIT>
        <COMPU-RATIONAL-COEFFS>
            <COMPU-NUMERATOR>
            	<V>0</V>
            	<V>1</V>
            </COMPU-NUMERATOR>
            <COMPU-DENOMINATOR>
            	<V>8</V>
            </COMPU-DENOMINATOR>
        </COMPU-RATIONAL-COEFFS>
        </COMPU-SCALE>
    </COMPU-SCALES>
    </COMPU-INTERNAL-TO-PHYS>
    <COMPU-PHYS-TO-INTERNAL>
    <COMPU-SCALES>
        <COMPU-SCALE>
        <SHORT-LABEL>physToInt</SHORT-LABEL>
        <LOWER-LIMIT INTERVAL-TYPE="CLOSED">0</LOWER-LIMIT>
        <UPPER-LIMIT INTERVAL-TYPE="CLOSED">3000</UPPER-LIMIT>
        <COMPU-RATIONAL-COEFFS>
            <COMPU-NUMERATOR>
            	<V>0</V>
            	<V>8</V>
            </COMPU-NUMERATOR>
            <COMPU-DENOMINATOR>
            	<V>1</V>
            </COMPU-DENOMINATOR>
        </COMPU-RATIONAL-COEFFS>
        </COMPU-SCALE>
    </COMPU-SCALES>
    </COMPU-PHYS-TO-INTERNAL>
</COMPU-METHOD>

Note

CompuMethods of category TEXTTABLE, which are generated for Boolean or enumerated data types, use only InternalToPhys, regardless of the direction parameter setting.

Export CompuMethod Unit References

The ARXML importer preserves unit and physical dimension information found in imported CompuMethods. The software preserves CompuMethod unit and physical dimension information across round-trips between an AUTOSAR authoring tool (AAT) and Simulink.

For designs originated in Simulink, the exporter generates a unit reference for each CompuMethod. By convention, each CompuMethod references a unit named NoUnit. For example, here is a Boolean data type CompuMethod and the unit it references.

<COMPU-METHOD UUID="...">
    <SHORT-NAME>COMPU_Boolean</SHORT-NAME>
    <CATEGORY>TEXTTABLE</CATEGORY>
    <UNIT-REF DEST="UNIT">/mymodel_pkg/mymodel_dt/NoUnit</UNIT-REF>
    ...
</COMPU-METHOD>
<UNIT UUID="...">
    <SHORT-NAME>NoUnit</SHORT-NAME>
    <FACTOR-SI-TO-UNIT>1</FACTOR-SI-TO-UNIT>
    <OFFSET-SI-TO-UNIT>0</OFFSET-SI-TO-UNIT>
</UNIT>

Providing a unit for each exported CompuMethod helps support measurement and calibration tool use of exported AUTOSAR data.

Modify Linear Scaling for SCALE_LINEAR_AND_TEXTTABLE CompuMethod

You can import and export an AUTOSAR CompuMethod that uses LINEAR and TEXTTABLE scaling. Importing application data types that reference CompuMethods of category SCALE_LINEAR_AND_TEXTTABLE creates Simulink.NumericType or Simulink.AliasType data objects in the Simulink workspace. In Simulink, you can modify the LINEAR scaling for the CompuMethods. The TEXTTABLE scaling is read-only.

For example, here is a CompuMethod with one LINEAR scale and two TEXTTABLE scales.

When you import the CompuMethod into a model, the importer creates a Simulink.NumericType with linear scaling. To modify the linear scaling, open the Simulink.NumericType data object and modify its fields.

For read-only access to the TEXTTABLE scaling information, use AUTOSAR property get function calls similar to the following:

>> arProps=autosar.api.getAUTOSARProperties('mySWC');
>> % Get literals for COMPU_myType TEXTTABLE scales
>> get(arProps,'/simple_ar_package/simple_ar_dt/COMPU_myType','CellOfEnums')
ans =
    'SensorError'    'SignalNotAvailable'
>> % Get internal values for COMPU_myType TEXTTABLE scales
>> get(arProps,'/simple_ar_package/simple_ar_dt/COMPU_myType','IntValues')
ans =
   350   351

Configure Rational Function CompuMethod for Dual-Scaled Parameter

For an AUTOSAR dual-scaled parameter, which stores two scaled values of the same physical value, the software generates the CompuMethod category RAT_FUNC. The computation method can be a first-order rational function.

To configure and generate a dual-scaled parameter:

  1. Open an AUTOSAR model. For the purposes of this example, create a Constant block from which to reference an AUTOSAR dual-scaled parameter. In the model, connect the Constant block to a Simulink outport.

  2. Open the Model Data Editor (on the Modeling tab, click Model Data Editor) and select the Parameters tab. Find the parameter entry for the Constant block. Use the Value column to reference the name of a dual-scaled parameter. This example uses the parameter name T1Rec.

  3. Create the T1Rec data object. In the Model Data Editor, to the right of the value T1Rec, click the action button and select Create.

    In the Create New Data dialog box, set Value to AUTOSAR.DualScaledParameter and click Create. An AUTOSAR.DualScaledParameter data object appears in the base workspace. The dual-scaled parameter property dialog box opens.

  4. Configure the attributes of the dual-scaled parameter T1Rec. Execute the following MATLAB code. The code sets up a conversion from an internal calibration time value to a physical frequency (time reciprocal) value.

    % Conversion from Time to Frequency
    % F = 1/T
    % In Other Words F = (0*T + 1)/(1*T+0);
    T1Rec.CompuMethodName = 'CM3';  %Specify AUTOSAR CompuMethod name
    T1Rec.DataType ='fixdt(1,32,0.01,0)';
    T1Rec.CalToMainCompuNumerator=1;
    T1Rec.CalToMainCompuDenominator=[1 0];
    T1Rec.CalibrationMin = 0.001;
    T1Rec.CalibrationMax = 1.0;
    T1Rec.CalibrationValue = 0.1500;
    T1Rec.CoderInfo.StorageClass = 'Custom';
    T1Rec.CoderInfo.Identifier = '';
    T1Rec.CoderInfo.CustomStorageClass = 'InternalCalPrm';
    T1Rec.CoderInfo.CustomAttributes.PerInstanceBehavior =...
      'Parameter shared by all instances of the Software Component';
    T1Rec.Description = '';
    % T1Rec.Min = [];
    % T1Rec.Max = [];
    T1Rec.Unit = '';
    T1Rec.CalibrationDocUnits = 'm/s²';
  5. Inspect the property dialog box for the dual-scaled parameter T1Rec. Here are the main attributes set by the MATLAB code.

  6. Here are the calibration attributes set by the MATLAB code.

  7. If CompuMethod direction is not already set to bidirectional in the AUTOSAR properties, use the AUTOSAR Dictionary, XML Options view, to set it.

  8. Generate code from the model.

When you generate code from the model, the ARXML exporter generates a CompuMethod of category RAT_FUNC.

<COMPU-METHOD UUID="...">
    <SHORT-NAME>CM3</SHORT-NAME>
    <CATEGORY>RAT_FUNC</CATEGORY>
    <UNIT-REF DEST="UNIT">/mymodel_pkg/mymodel_dt/m_s_</UNIT-REF>
    <COMPU-INTERNAL-TO-PHYS>
        <COMPU-SCALES>
            <COMPU-SCALE>
                <COMPU-RATIONAL-COEFFS>
                    <COMPU-NUMERATOR>
                        <V>-100</V>
                    </COMPU-NUMERATOR>
                    <COMPU-DENOMINATOR>
                        <V>0</V>
                        <V>-1</V>
                    </COMPU-DENOMINATOR>
                </COMPU-RATIONAL-COEFFS>
            </COMPU-SCALE>
        </COMPU-SCALES>
    </COMPU-INTERNAL-TO-PHYS>
    <COMPU-PHYS-TO-INTERNAL>
        <COMPU-SCALES>
            <COMPU-SCALE>
                <COMPU-RATIONAL-COEFFS>
                    <COMPU-NUMERATOR>
                        <V>100</V>
                    </COMPU-NUMERATOR>
                    <COMPU-DENOMINATOR>
                        <V>0</V>
                        <V>1</V>
                    </COMPU-DENOMINATOR>
                </COMPU-RATIONAL-COEFFS>
            </COMPU-SCALE>
        </COMPU-SCALES>
    </COMPU-PHYS-TO-INTERNAL>
</COMPU-METHOD>

The CompuMethod is referenced from the application data type generated for T1Rec.

<APPLICATION-PRIMITIVE-DATA-TYPE UUID="...">
  <SHORT-NAME>T1Rec_DualScaled</SHORT-NAME>
  <CATEGORY>VALUE</CATEGORY>
  <SW-DATA-DEF-PROPS>
    <SW-DATA-DEF-PROPS-VARIANTS>
      <SW-DATA-DEF-PROPS-CONDITIONAL>
        <SW-CALIBRATION-ACCESS>READ-WRITE</SW-CALIBRATION-ACCESS>
        <COMPU-METHOD-REF DEST="COMPU-METHOD">/mymodel_pkg/mymodel_dt/CM3</COMPU-METHOD-REF>
        <DATA-CONSTR-REF DEST="DATA-CONSTR">/mymodel_pkg/mymodel_dt/ApplDataTypes/
                                 DataConstrs/DC_T1Rec_DualScaled</DATA-CONSTR-REF>
      </SW-DATA-DEF-PROPS-CONDITIONAL>
    </SW-DATA-DEF-PROPS-VARIANTS>
  </SW-DATA-DEF-PROPS>
</APPLICATION-PRIMITIVE-DATA-TYPE>

The application data type T1Rec_DualScaled is referenced from the parameter data prototype generated for T1Rec.

<PARAMETER-DATA-PROTOTYPE UUID="...">
  <SHORT-NAME>T1Rec</SHORT-NAME>
  <SW-DATA-DEF-PROPS>
    <SW-DATA-DEF-PROPS-VARIANTS>
      <SW-DATA-DEF-PROPS-CONDITIONAL>
        <SW-CALIBRATION-ACCESS>READ-WRITE</SW-CALIBRATION-ACCESS>
        <SW-IMPL-POLICY>STANDARD</SW-IMPL-POLICY>
      </SW-DATA-DEF-PROPS-CONDITIONAL>
    </SW-DATA-DEF-PROPS-VARIANTS>
  </SW-DATA-DEF-PROPS>
  <TYPE-TREF DEST="APPLICATION-PRIMITIVE-DATA-TYPE">/mymodel_pkg/mymodel_dt/ApplDataTypes/
                                                              T1Rec_DualScaled</TYPE-TREF>
  ...
</PARAMETER-DATA-PROTOTYPE>

Related Examples

More About