Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

结合使用 CDFX 文件和 Simulink 数据字典

此示例说明如何将来自 ASAM CDFX 文件的标定数据存储在数据字典中,并将这些值用作 Simulink® 模型的参数。

导入数据

使用 cdfx 函数导入标定数据。

cdfxObj = cdfx("CDFXExampleFile.cdfx")
cdfxObj = 
  CDFX with properties:

       Name: "CDFXExampleFile.cdfx"
       Path: "/mathworks/home/rollinb/Documents/MATLAB/Examples/vnt-ex73237310-20190405222527/CDFXExampleFile.cdfx"
    Version: "CDF20"

使用标定数据创建和填充数据字典

使用 getValue 将所需参数提取到 MATLAB® 工作区中。

dictName = "CDFXExampleDD.sldd"
dictName = 
"CDFXExampleDD.sldd"

检查字典是否已在工作文件夹中。

if isfile(dictName)
    % If data dictionary exists, open it.
    dDict = Simulink.data.dictionary.open(dictName)
else
    % If dictionary does not exist, create it and populate with CDFX data.
    dDict = Simulink.data.dictionary.create(dictName)
    ddSection = getSection(dDict, "Design Data")
    
    addEntry(ddSection, "gainParam", getValue(cdfxObj, "ASAM.C.SCALAR.GAIN"))
    addEntry(ddSection, "mapParam", getValue(cdfxObj, "ASAM.C.MAP"))
end
dDict = 
  Dictionary with properties:

                    DataSources: {0×1 cell}
       HasAccessToBaseWorkspace: 0
    EnableAccessToBaseWorkspace: 0
              HasUnsavedChanges: 0
                NumberOfEntries: 2

显示数据字典的内容。

listEntry(dDict)
  Section       Name        Status   DataSource           LastModified       LastModifiedBy   Class    

  Design Data   gainParam            CDFXExampleDD.sldd   2019-04-05 22:33   rollinb          double   
  Design Data   mapParam             CDFXExampleDD.sldd   2019-04-05 22:33   rollinb          struct   

将数据字典链接到 Simulink 模型

打开 Simulink 模型,然后使用 set_param 将该数据字典链接到您的模型。这将允许模型访问在字典中定义的值。

open_system("CDFXSLDDModel.slx");
cdfxMdl = gcs
cdfxMdl = 
'CDFXSLDDModel'
set_param(gcs, "DataDictionary", dictName)

我们现在可以关闭与数据字典的连接。

close(dDict)

查找-增益模型

该模型包含:

  • 2-D Lookup Table 模块,表示 CDFX 文件中的 ASAM.C.MAP 参数。“表数据”字段,表示实例的物理值;“断点”字段,表示轴的物理值。

  • Gain 模块,表示 CDFX 文件中的 ASAM.C.SCALAR.GAIN 参数。

  • To Workspace 模块,用于记录仿真数据。

Indexing Logic 子系统

Indexing Logic 子系统使用 ASAM.C.MAP 参数轴的物理值以及信号路由模块和触发子系统,来生成查找索引的所有有效组合。如果您需要在标定参数的全部可能输入值范围内进行测试,这种配置会很有用。

在 MATLAB 中记录输出数据

仿真的输出由 To Workspace 模块发送到 MATLAB,在那里它存储为时间序列对象,称为 mapData。现在可以在 MATLAB 工作区中检查和可视化这些数据。

sim(cdfxMdl);
plot(mapData)
title("Simulation Output for ASAM.C.MAP")

% Copyright 2018-2021 The MathWorks, Inc.