Main Content

coder.asap2.Measurement

R2026b

Create measurement object

Since R2022b

Description

Create a measurement object to define a signal and export it to an ASAP2 file.

Creation

signal = coder.asap2.Measurement creates a measurement object. You can use the object to define a signal and export it to an ASAP2 file.

Properties

expand all

Specify a name for the custom variable.

Example: "CustomVariable_1"

Specify comments and description of the variable.

Example: "Description of the variable"

Specify a data type for the variable.

Example: UBYTE

Specify the address of the custom variable.

Example: 0x1234

Specify a name for the conversion method of the custom variable.

Example: custom_conversionmethod

Specify the minimum possible value for the custom variable.

Example: 0

Specify the maximum possible value for the custom variable.

Example: 65535

Specify symbols for address replacement.

Example: "/* @ECU_Address@MEASUREMENT_1@ */"

Specify additional address information.

Example: 1

Specify the calibration access type for the custom variable.

Example: ReadOnly

Specify a display name for the variable to appear on calibration tool.

Example: CustomVariable_1

Specify a display format for the variable to appear on calibration tool.

Example: %3.4

Specify to handle the single bits.

Example: 0x3a

Specify the dimensions for an array data type.

Example: 2

Specify true to export the variable and false to not export the variable to ASAP2 file.

Example: false

Specify reference to symbol name within a linker map file.

Example: struct('SymbolName','p1_SymbolName','Offset',1)

Perform operation on masked out value. This property can be used with the BitMask.

Example: struct('Shift',3,'SignExtend',1)

Specify the maximum refresh rate.

Example: struct('ScalingUnit',ScalingUnits.ONE_MILLI_SEC,'Rate',100)

Specify any additional description that needs to be populated in the measurement.

Example: "additional information"

Examples

collapse all

This example shows how to programmatically customize ECU descriptions in an ASAP2 file by adding, modifying, and removing computation methods, characteristics, measurements, and lookup table parameters.

Use functions to create an ECU description object from a built model, find and filter its contents, and export a customized ASAP2 file.

In this example, you:

  • Build a model and create an ECU description object

  • Find and filter computation methods by properties

  • Add and modify a custom computation method

  • Add and modify a custom characteristic and measurement

  • Add a lookup table parameter with axis information

  • Export the customized ASAP2 file

Open and Build the Model

Open the example model ASAP2Demo and generate code from it. Building the model is a prerequisite for creating the ECU description object.

open_system("ASAP2Demo");

slbuild("ASAP2Demo");
### Searching for referenced models in model 'ASAP2Demo'.
### Total of 2 models to build.
### Starting serial code generation build.
### Starting model reference code generation target build for: ASAP2DemoModelRef
### Successfully updated the model reference code generation target for: ASAP2DemoModelRef
### Starting top model code generation target build for: ASAP2Demo
### Successful completion of build procedure for: ASAP2Demo

Build Summary

Model reference code generation targets:

Model              Build Reason                                 Status                        Build Duration
============================================================================================================
ASAP2DemoModelRef  Target (ASAP2DemoModelRef.c) did not exist.  Code generated and compiled.  0h 0m 8.5322s

Top model targets:

Model      Build Reason                         Status                        Build Duration
============================================================================================
ASAP2Demo  Target (ASAP2Demo.c) did not exist.  Code generated and compiled.  0h 0m 16.383s

2 of 2 models built (0 models already up to date)
Build duration: 0h 0m 27.316s

Create and Explore ECU Descriptions

Create the ECU description object for the built model. Use the find function to list available computation methods.

descObj = coder.asap2.getEcuDescriptions("ASAP2Demo");
Export duration: 0h 0m 0s 227ms
find(descObj, "CompuMethod")
ans = 1×9 string
    "CM_double"    "CM_double_m_per_U0028_s_U005E_2_U0029"    "CM_double_rpm"    "CM_int16_rpm"    "CM_int32"    "CM_single"    "CM_single_m_per_U0028_s_U005E_2_U0029"    "CM_single_rpm"    "CM_uint8"

Filter the computation methods to get only those that use rpm as the unit.

find(descObj, "CompuMethod", Units="rpm")
ans = 1×3 string
    "CM_double_rpm"    "CM_int16_rpm"    "CM_single_rpm"

Add a Custom Computation Method

Create a computation method with a linear conversion type and add it to the ECU description object.

CompuMethod_1 = coder.asap2.CompuMethod;
CompuMethod_1.Name = 'CompuMethod_1';
CompuMethod_1.ConversionType = "LINEAR";
CompuMethod_1.Coefficients = [2 3];
CompuMethod_1.LongIdentifier = "longIdentifierTest";
CompuMethod_1.Format = "%2.3";
CompuMethod_1.Units = "s";
add(descObj, CompuMethod_1);

Verify the properties of the newly added computation method.

get(descObj, "CompuMethod", "CompuMethod_1")
ans = 
  CompuMethod with properties:

               Name: 'CompuMethod_1'
     LongIdentifier: "longIdentifierTest"
             Format: "%2.3"
              Units: "s"
       Coefficients: [2 3]
     ConversionType: "LINEAR"
    CompuVTabValues: [1×1 struct]
         CustomData: ""

Update the conversion type to TAB_VERB and define the corresponding CompuVTabValues. Use the set function to modify properties of an existing description.

set(descObj, "CompuMethod", "CompuMethod_1", ConversionType="TAB_VERB");
set(descObj, "CompuMethod", "CompuMethod_1", CompuVTabValues=struct("Literals", ["false" "true"], "Values", [0 1]));

Verify the modified fields.

modifiedProp = get(descObj, "CompuMethod", "CompuMethod_1")
modifiedProp = 
  CompuMethod with properties:

               Name: 'CompuMethod_1'
     LongIdentifier: "longIdentifierTest"
             Format: "%2.3"
              Units: "s"
       Coefficients: [2 3]
     ConversionType: "TAB_VERB"
    CompuVTabValues: [1×1 struct]
         CustomData: ""

modifiedProp.CompuVTabValues
ans = struct with fields:
    Literals: ["false"    "true"]
      Values: [0 1]

Add a Custom Characteristic

Create a characteristic that represents a calibration parameter and add it to the ECU description object. Then update its UpperLimit property.

param1 = coder.asap2.Characteristic;
param1.Name = "Custom_parameter1";
param1.LongIdentifier = "longIdentifierParam";
param1.UpperLimit = 255;
param1.LowerLimit = 0;
add(descObj, param1);
get(descObj, "Characteristic", "Custom_parameter1")
ans = 
  Characteristic with properties:

                   Name: "Custom_parameter1"
         LongIdentifier: "longIdentifierParam"
                   Type: 'VALUE'
             EcuAddress: '0x0000'
        CompuMethodName: 'NO_COMPU_METHOD'
             LowerLimit: 0
             UpperLimit: 255
      EcuAddressComment: ""
    EcuAddressExtension: []
      CalibrationAccess: 'Calibration'
      DisplayIdentifier: ""
                 Format: ""
                BitMask: []
               AxisInfo: []
           RecordLayout: ""
             Dimensions: []
                 Export: 1
             MaxRefresh: [1×1 struct]
             SymbolLink: [1×1 struct]
             CustomData: ""

set(descObj, "Characteristic", "Custom_parameter1", UpperLimit=128)

Add a Custom Measurement

Create a measurement that represents a signal and add it to the ECU description object. Then update its CalibrationAccess property.

signal1 = coder.asap2.Measurement;
signal1.Name = "Custom_signal1";
signal1.LongIdentifier = "longIdentifierSignal";
signal1.UpperLimit = 255;
signal1.LowerLimit = 0;
add(descObj, signal1);
get(descObj, "Measurement", "Custom_signal1")
ans = 
  Measurement with properties:

                   Name: "Custom_signal1"
         LongIdentifier: "longIdentifierSignal"
               DataType: 'UBYTE'
             EcuAddress: '0x0000'
        CompuMethodName: ""
             LowerLimit: 0
             UpperLimit: 255
                 Raster: [1×1 struct]
      EcuAddressComment: ""
    EcuAddressExtension: []
      CalibrationAccess: 'NoCalibration'
      DisplayIdentifier: ""
                 Format: ""
                BitMask: []
             Dimensions: []
                 Export: 1
               MaskData: [1×1 struct]
             MaxRefresh: [1×1 struct]
             SymbolLink: [1×1 struct]
             CustomData: ""

set(descObj, "Measurement", "Custom_signal1", CalibrationAccess="Calibration")

Add a Lookup Table Parameter

Create a lookup table parameter of type MAP with two axes. Each axis requires a name, computation method, maximum number of axis points, and axis type.

lutParam = coder.asap2.Characteristic;
lutParam.Name = "custom_lookup_table";
lutParam.Type = "MAP";
axisData = coder.asap2.AxisInfo;
axisData(1).Name = "BP3";
axisData(2).Name = "Bp4";
axisData(1).CompuMethodName = "ASAP2Demo_CM_double";
axisData(2).CompuMethodName = "ASAP2Demo_CM_double";
axisData(1).MaxAxisPoints = "3";
axisData(2).MaxAxisPoints = "3";
axisData(1).AxisType = "STD_AXIS";
axisData(2).AxisType = "STD_AXIS";
lutParam.AxisInfo = axisData;
add(descObj, lutParam)

Export the Customized ASAP2 File

Export the ASAP2 file using the updated ECU description object. Verify that the generated file contains the custom computation method, characteristic, measurement, and lookup table parameter.

coder.asap2.export("ASAP2Demo", CustomEcuDescriptions=descObj);

Remove Custom Descriptions

Remove the custom descriptions from the ECU description object.

delete(descObj, "CompuMethod", "CompuMethod_1");
delete(descObj, "Characteristic", "Custom_parameter1");
delete(descObj, "Measurement", "Custom_signal1");

Version History

Introduced in R2022b