主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

coder.asap2.CompuMethod

创建 compu 方法对象

自 R2022b 起

说明

创建一个计算方法对象来定义计算方法元素并将其导出到 ASAP2 文件。

创建对象

compu = coder.asap2.CompuMethod 创建一个 compu method 对象。您可以使用该对象定义计算方法并将其导出到 ASAP2 文件。

属性

全部展开

为自定义计算方法指定一个名称。

示例: "CustomCompuMethod_1"

指定计算方法的注释和描述。

示例: "Description of the compu method"

指定计算方法在校准工具上显示的显示格式。

示例: %3.4

指定计算方法的物理单位。

示例: "sec"

指定分数有理函数的系数。

示例: 0 100 0 0 1 1

指定内部源值到物理值的转换类型。

示例: LINEAR

ConversionType 的 compu 方法的值指定为 TAB_VERB。

示例: struct with literals and values

指定需要在 compu 方法中填充的任何其他描述。

示例: "additional information"

示例

全部折叠

在 ASAP2 文件中添加、更新、过滤、查找和删除 ECU 描述。

打开并构建示例模型

打开示例模型 ASAP2Demo

open_system("ASAP2Demo");

编译模型。

slbuild("ASAP2Demo");
### Searching for referenced models in model 'ASAP2Demo'.
### Total of 2 models to build.
### Starting serial code generation build.
### Successfully updated the model reference code generation target for: ASAP2DemoModelRef
### Starting build procedure 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 5.8839s 

Top model targets:

Model      Build Reason                                         Status                        Build Duration
============================================================================================================
ASAP2Demo  Information cache folder or artifacts were missing.  Code generated and compiled.  0h 0m 12.037s 

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

为模型创建 ECU 描述对象。

descObj = coder.asap2.getEcuDescriptions("ASAP2Demo");

获取描述对象中可用的计算方法列表。

find(descObj,"CompuMethod")
ans = 1×10 string
    "ASAP2DemoModelRef_CM_double"    "ASAP2DemoModelRef_CM_int16_rpm"    "ASAP2Demo_CM_double"    "ASAP2Demo_CM_double_m_per__s_2_"    "ASAP2Demo_CM_double_rpm"    "ASAP2Demo_CM_int32"    "ASAP2Demo_CM_single"    "ASAP2Demo_CM_single_m_per__s_2_"    "ASAP2Demo_CM_single_rpm"    "ASAP2Demo_CM_uint8"

过滤计算方法,获取以 rpm 为单位的计算方法列表。

find(descObj,"CompuMethod",Units='rpm')
ans = 1×3 string
    "ASAP2DemoModelRef_CM_int16_rpm"    "ASAP2Demo_CM_double_rpm"    "ASAP2Demo_CM_single_rpm"

创建并添加自定义计算方法

要向 ASAP2 文件添加新的计算方法,请创建自定义计算方法。

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';

将自定义计算方法添加到 ECU 描述对象。

add(descObj,CompuMethod_1);

获取新添加的计算方法的属性。

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: ""

要修改计算方法的属性,请使用 set 函数。将计算方法的 ConversionType 字段更新为 TAB_VERB ,并定义 CompuVTabValues.

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

获取属性来查看修改的字段。

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]

使用更新后的 ECU 描述对象生成 ASAP2 文件,并验证 ASAP2 文件是否包含计算方法 CompuMethod_1

coder.asap2.export("ASAP2Demo",CustomEcuDescriptions=descObj);
Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "ASAP2Demo_DW.ASAP2DemoModelRef_InstanceData"

删除计算方法

从描述对象中移除新添加的计算方法。

delete(descObj,"CompuMethod","CompuMethod_1");

创建并添加自定义特征

要向 ASAP2 文件添加新特性,请创建自定义特性。

Parameter_1 = coder.asap2.Characteristic;
Parameter_1.Name = 'Custom_parameter1';
Parameter_1.LongIdentifier = 'longIdentifierParam';
Parameter_1.UpperLimit = 255;
Parameter_1.LowerLimit = 0;

将自定义特性添加到 ECU 描述对象。

add(descObj,Parameter_1);

获取新添加的特性的属性。

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 函数。更新特征的 UpperLimit 字段。

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

使用更新的 ECU 描述对象生成 ASAP2 文件,并验证 ASAP2 文件是否包含特性 Custom_parameter1

coder.asap2.export("ASAP2Demo",CustomEcuDescriptions=descObj);
Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "ASAP2Demo_DW.ASAP2DemoModelRef_InstanceData"

从描述对象中删除新添加的特征。

delete(descObj,"Characteristic","Custom_parameter1");

创建并添加自定义测量

要向 ASAP2 文件添加新测量,请创建自定义测量。

Signal_1 = coder.asap2.Measurement;
Signal_1.Name = 'Custom_signal1';
Signal_1.LongIdentifier = 'longIdentifierSignal';
Signal_1.UpperLimit = 255;
Signal_1.LowerLimit = 0;

将自定义测量添加到 ECU 描述对象。

add(descObj,Signal_1);

获取新添加的测量的属性。

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 函数。更新测量的 CalibrationAccess 字段。

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

使用更新的 ECU 描述对象生成 ASAP2 文件,并验证 ASAP2 文件是否包含名为 Custom_signal1 的测量值。

coder.asap2.export("ASAP2Demo",CustomEcuDescriptions=descObj);
Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "ASAP2Demo_DW.ASAP2DemoModelRef_InstanceData"

从描述对象中删除新添加的测量。

delete(descObj,"Measurement","Custom_signal1");

创建并添加查找表参数

添加查找表参数。

LUT_Parameter = coder.asap2.Characteristic;
LUT_Parameter.Name = "custom_lookup_table";
LUT_Parameter.Type = "MAP";

创建并添加轴信息到参数。

axis_data = coder.asap2.AxisInfo;
axis_data(1).Name = 'BP3';
axis_data(2).Name = 'Bp4';
axis_data(1).CompuMethodName = 'ASAP2Demo_CM_double';
axis_data(2).CompuMethodName = 'ASAP2Demo_CM_double';
axis_data(1).MaxAxisPoints = '3';
axis_data(2).MaxAxisPoints = '3';
axis_data(1).AxisType = 'STD_AXIS';
axis_data(2).AxisType = 'STD_AXIS';
LUT_Parameter.AxisInfo = axis_data;

将查找表参数添加到描述对象。

add(descObj,LUT_Parameter)

使用更新后的 ECU 描述对象生成 ASAP2 文件,并验证 ASAP2 文件是否包含查找表参数 custom_lookup_table

coder.asap2.export("ASAP2Demo",CustomEcuDescriptions=descObj);
Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "ASAP2Demo_DW.ASAP2DemoModelRef_InstanceData"

版本历史记录

在 R2022b 中推出