主要内容

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

batterySimulationLog

将电池模块的记录的 Simscape 仿真数据存储在 Simulink 模型中

自 R2023b 起

说明

使用 batterySimulationLog 构建一个电池仿真对象,该对象将特定电池模块的记录的 Simscape™ 仿真数据存储在 Simulink® 模型中。

此 Simulink 模型必须包含至少一个使用电池包模型生成器中的对象和函数生成的 Simscape Battery™ 模块,包括 ParallelAssemblyModuleModuleAssemblyPack

将此对象作为 BatterySimulationChart 对象的输入,使用颜色映射在三维电池仿真图顶部动态可视化特定变量的值。

使用 BatterySimulationLog 对象执行以下操作:

  • 存储特定电池模块的动态输出数据。

  • 指定要在 BatterySimulationChart 对象中可视化的模块变量。

  • 指定一个相应的 Simscape 单位来可视化所选变量。

创建对象

描述

battsimlog = batterySimulationLog(Battery,SimLog) 创建一个 BatterySimulationLog 对象,用于存储 Simulink 属性中指定的电池对象的 Battery 模型记录的 Simscape 仿真数据 Parent

示例

battsimlog = batterySimulationChart(Battery,SimLog,Name=Value) 使用一个或多个名称-值参量设置进一步的 属性

属性

全部展开

与仿真中的模块关联的电池对象,指定为 ParallelAssemblyModuleModuleAssemblyPack 对象。

从仿真输出记录的电池模块仿真数据,指定为 simscape.logging.Node 对象。要了解如何获取记录的仿真数据,请参阅 Enable Simscape Data Logging for the Whole Model

在电池仿真图中可视化的电池模块的变量名称,指定为字符串标量。

电池模块中要在电池仿真图中可视化的变量的单位,指定为字符串标量。

此 属性 为只读。

Battery 属性中为电池模块的 SelectedVariable 属性指定的模块变量列表,以字符串数组的形式返回。

示例

全部折叠

创建 Simscape Battery 模块。

cell = batteryCell(batteryCylindricalGeometry);
cell.CellModelOptions.BlockParameters.thermal_port = "model";
pset = batteryParallelAssembly(cell,15,Rows=3);
module = batteryModule(pset, ...
    ModelResolution="Detailed", ...
    AmbientThermalPath="CellBasedThermalResistance");
libraryname = "Batteries";
buildBattery(module,"LibraryName",libraryname);

创建并打开 Simulink 电池模型。

modelname = "batterymodel";
open_system(new_system(modelname));

命名所需的模块并将其添加到模式中。

batteryBlockPath = strcat(modelname,"/","Module1");
electricalRefBlockPath = strcat(modelname,"/","ElectricalReference");
solverConfigBlockPath = strcat(modelname,"/","Solver");
currentSourceBlockPath = strcat(modelname,"/","Current Source");
temperatureSourceBlockPath = strcat(modelname,"/","Temperature Source");

% Add blocks to the model
add_block( strcat(libraryname,"_lib/",module.Name),batteryBlockPath,'position',[150,100,300,250]);
add_block("fl_lib/Electrical/Electrical Elements/Electrical Reference",electricalRefBlockPath,'position',[215,320,235,340],'orientation',"down");
add_block("nesl_utility/Solver Configuration",solverConfigBlockPath,'position',[-80,280,-30,320]);
add_block("fl_lib/Electrical/Electrical Sources/DC Current Source",currentSourceBlockPath,'position',[-30,150,0,200],'orientation',"down",'i0',num2str(-500));
add_block("fl_lib/Thermal/Thermal Sources/Temperature Source",temperatureSourceBlockPath,'position',[80,160,120,200],'orientation',"left");

获取模块端口的句柄,并连接所有模块。

batteryBlockPortHandles = get_param(batteryBlockPath,'PortHandles');
electricalRefBlockPortHandles = get_param(electricalRefBlockPath,'PortHandles');
solverConfigBlockPortHandles = get_param(solverConfigBlockPath,'PortHandles');
currentSourceBlockPortHandles = get_param(currentSourceBlockPath,'PortHandles');
temperatureSourceBlockPortHandles = get_param(temperatureSourceBlockPath,'PortHandles');

% Connect all blocks
add_line(modelname,batteryBlockPortHandles.RConn,currentSourceBlockPortHandles.RConn,autorouting='smart');
add_line(modelname,batteryBlockPortHandles.LConn(2),currentSourceBlockPortHandles.LConn,autorouting='smart');
add_line(modelname,batteryBlockPortHandles.RConn,electricalRefBlockPortHandles.LConn,autorouting='smart');
add_line(modelname,batteryBlockPortHandles.RConn,solverConfigBlockPortHandles.RConn,autorouting='smart');
add_line(modelname,batteryBlockPortHandles.LConn(1),temperatureSourceBlockPortHandles.LConn,autorouting='smart');

启用模型的记录仿真数据。

set_param(modelname,"SimscapeLogType",'all')
set_param(batteryBlockPath,"AmbientResistance",strcat("[",num2str((60-1).*rand(15,1)' + 1),"]"));

对模型进行仿真。

out = sim(modelname,'StartTime','0','StopTime','160');

创建一个 BatterySimulationLog 对象。选择要可视化的变量,然后显示对象。

batterySimLog = batterySimulationLog(module,out.simlog.Module1,SelectedVariable="temperatureCell");
disp(batterySimLog)
  BatterySimulationLog with properties:

                 Battery: [1×1 simscape.battery.builder.Module]
                  SimLog: [1×1 simscape.logging.Node]
        SelectedVariable: "temperatureCell"
    SelectedVariableUnit: "K"
          ModelVariables: ["vCell"    "temperatureCell"    "iCell"    "numCyclesCell"    "socCell"]

版本历史记录

在 R2023b 中推出