主要内容

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

在电池模型中注入故障

自 R2023b 起

此示例说明了如何使用 Simscape™ Battery™ 和 Simulink™ 软件在仿真过程中向电池模型注入故障。首先,您将探索将电池电芯从电池模组内的并联组件中断开连接的影响。电芯断开通常是由于焊接故障或电芯电流中断装置故障造成的。然后,在电池模组内的并联组件的一个电芯上添加一个内部短路故障。该故障触发了一系列放热反应,称为热失控。在仿真时间为 30 秒时,使用定时触发器激活两个故障。

故障注入是一种在开发用于锂离子电池等安全关键系统的高可靠性控制软件过程中非常有效的技术。此示例生成一个电池模型,添加非侵入性故障,然后使用 batterySimulationChart 对象显示仿真结果。

创建电池模组对象

要创建电池 Module 对象,必须先设计并创建电池模组的基本元素。

创建 Cell 对象并定义可视化变量

创建和定义电池电芯的几何形状。使用 batteryCylindricalGeometry 函数,该函数返回一个 CylindricalGeometry 对象。然后,要将几何形状应用到生成的 Cell 对象,请使用 batteryCell 函数,并将 CylindricalGeometry 对象指定为第一个参量。

cylindricalGeometry = batteryCylindricalGeometry;
cylindricalCell = batteryCell(cylindricalGeometry);

Module 对象的基本电芯模型模块更改为使用 Battery Equivalent Circuit 模块。在 batterycell 对象中指定 CellModelOptions 属性的 CellModelBlockPath 属性。

cylindricalCell.CellModelOptions.CellModelBlockPath = "batt_lib/Cells/Battery Equivalent Circuit";

您可以使用 Cell 对象通过简单的一维模型仿真电池电芯的热效应。要仿真电池电芯的热效应,请在 Cell 对象的 CellModelOptions 属性的 BlockParameters 属性中,将 ThermalModel 属性设置为 "LumpedThermalMass"。只有将 Cell 对象的 ThermalModel 属性设置为 "LumpedThermalMass",才能添加放热反应故障。只有先在电芯级别定义热模型,才能定义电池并联组件和模组的热边界条件。

cylindricalCell.CellModelOptions.BlockParameters.ThermalModel = "LumpedThermalMass";

创建 ParallelAssembly 对象

并联组件包括多个电池电芯,这些电池电芯在特定的拓扑配置或几何排列下电连接成并联。在此示例中,您将创建一个由九个圆柱形电芯组成的并联组件。

要创建 ParallelAssembly 对象,请使用 batteryParallelAssembly 函数。将电芯定义为第一个参量,将并行电芯的数量定义为第二个参量。

parallelAssembly = batteryParallelAssembly(cylindricalCell, ...
    9, ...
    Rows=3, ...
    ModelResolution="Detailed", ...
    Topology="Square");

创建 Module 对象

现在,您已经拥有创建电池模组的所有基本元素。电池模组由多个串联的并联组件组成。在此示例中,您将创建一个由三个并联组件组成的电池模组,并设置详细的模型分辨率。

要创建此 Module 对象,请使用 batteryModule 函数。将并联组件定义为第一个参量,并将串联的并联组件数定义为第二个参量。要指定附加模组属性,请使用可选的名称-值参量。

module = batteryModule(parallelAssembly, ...
    3, ...
    AmbientThermalPath="CellBasedThermalResistance", ...
    CoolantThermalPath="CellBasedThermalResistance", ...
    ModelResolution="Detailed", ...
    InterCellThermalPath="on", ...
    InterParallelAssemblyGap=simscape.Value(0.005,"m"));

可视化电池模组并检查模型分辨率

要获得用于仿真的 Battery Equivalent Circuit 模块的数量,请使用 Module 对象的 NumModels 属性。

要在构建系统模型之前可视化电池模组并查看其模型分辨率,请在要可视化模组的位置创建图形,然后使用 batteryChart 函数。

f = uifigure(Color="w");
tl = tiledlayout(1,2,Parent=f,TileSpacing="Compact");
nexttile(tl)
moduleChart1 = batteryChart(tl,module);
nexttile(tl)
moduleChart2 = batteryChart(tl,module,SimulationStrategyVisible="On");

构建模组对象的 Simscape 模型

创建电池对象后,需要将其转换为 Simscape 模型,以便在模块图中使用。然后,您可以将这些模型作为参考,用于系统集成和需求评估、冷却系统设计、控制策略开发、硬件在环等许多应用。

要创建一个包含 Module 对象的 Simscape Battery 模型的库,请使用 buildBattery 函数。要创建一个可以单独定义所有电池参数的脚本,请将函数 buildBattery 的参量 MaskParameters 设置为 "VariableNamesByType"。要将初始目标作为脚本的一部分包括在内,请将 buildBattery 函数的 MaskInitialTargets 参量设置为 VariableNamesByInstance"

在工作文件夹中创建 packVisualization_libpackVisualization SLX 库文件。packVisualization_lib 库包含 Modules 和 ParallelAssemblies 子库。此函数还创建一个扩展名为 .mpackVisualization_param 脚本,该脚本创建运行电池仿真所需的所有参数。

libraryname = "moduleFaults";
buildBattery(module, ...
    "LibraryName",libraryname, ...
    "MaskParameters","VariableNamesByType", ...
    "Verbose","off");

创建并仿真电池模型

创建包含所需电池模型的电池库后,必须创建 Simulink 模型。然后,仿真此模型,以获得记录的仿真数据。

创建 Simulink 模型

创建并打开 Simulink 模型。定义模型名称并使用 open_system 函数。

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

该示例以编程方式添加了仿真电池模组模型所需的所有模块。要添加这些模块,请将其模块路径定义为工作区中的变量。

batteryBlockPath = strcat(modelname,"/","Module1");
electricalRefBlockPath = strcat(modelname,"/","ElectricalReference");
solverConfigBlockPath = strcat(modelname,"/","Solver");
currentSourceBlockPath = strcat(modelname,"/","Controlled Current Source");
ambientTemperatureSourceBlockPath = strcat(modelname,"/","Temperature Source");
coolantTemperatureSourceBlockPath = strcat(modelname,"/","Temperature Source Clnt");

使用函数 add_block 将模块添加到模型中。

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(-400),ShowName="off");
add_block("fl_lib/Thermal/Thermal Sources/Temperature Source",ambientTemperatureSourceBlockPath,position=[80,195,120,235],ShowName="off",orientation="left");
add_block("fl_lib/Thermal/Thermal Sources/Temperature Source",coolantTemperatureSourceBlockPath,position=[80,120,120,160],ShowName="off",orientation="left");

使用函数 simscape.addConnection 连接模块端口。

simscape.addConnection(batteryBlockPath,"n",solverConfigBlockPath,"port","autorouting","smart");
simscape.addConnection(batteryBlockPath,"n",electricalRefBlockPath,"V","autorouting","smart");
simscape.addConnection(batteryBlockPath,"n",currentSourceBlockPath,"n","autorouting","smart");
simscape.addConnection(batteryBlockPath,"p",currentSourceBlockPath,"p","autorouting","smart");
simscape.addConnection(batteryBlockPath,"ClntH",coolantTemperatureSourceBlockPath,"A","autorouting","smart");
simscape.addConnection(batteryBlockPath,"AmbH",ambientTemperatureSourceBlockPath,"A","autorouting","smart");

下图显示了生成的电池模型:

准备仿真模型

要可视化 BatterySimulationChart 对象中的电池仿真输出,必须先启用 Simscape 信号记录。要启用记录,请在 Simulink 模型中将 SimscapeLogType 属性设置为 "all"

set_param(modelname,"SimscapeLogType","all")

要运行仿真,必须先运行参数化脚本。

run(strcat(libraryname,"_param.m"))

仿真模组故障中断开连接的电芯

要创建一个新的故障,首先使用 save_system 函数保存模型,并使用模型的名称作为输入。

save_system(modelname)

在此示例中,您通过向特定电芯添加大电阻来建模将电芯与其对应的并联组件断开的故障。要确定用于激活故障的索引,请显示模组的 CellNumbering 属性。

module.CellNumbering.Cells
ans = 3×3

     1     4     7
     2     5     8
     3     6     9

ans = 3×3

     1     4     7
     2     5     8
     3     6     9

ans = 3×3

     1     4     7
     2     5     8
     3     6     9

使用函数 Simulink.fault.addFault 为第二个并联组件的第五个电芯添加一个附加的电阻故障。要将此故障添加到故障模型中,请使用 addBehavior 函数。

additionalResistanceFault = Simulink.fault.addFault(strcat(batteryBlockPath,"/ParallelAssembly1(2)/Cell1(5)/Additional resistance"));
faultModel = strcat(modelname,"_FaultModel");
addBehavior(additionalResistanceFault,faultModel);

现在编辑并激活故障。通过分别更改 additionalResistanceFault 对象的 TriggerTypeStartTime 属性来更改触发类型和故障事件时间。

additionalResistanceFault.TriggerType = "Timed";
additionalResistanceFault.StartTime = 30;

要激活该故障,请使用 additionalResistanceFault 对象的 activate 函数。

additionalResistanceFault.activate;

要运行仿真,请使用 sim 函数并定义 StartTimeStopTime 参量。

out = sim(modelname,StartTime="0",StopTime="600");

可视化电池故障

要选择在 BatterySimulationChart 中绘制的变量和变量单位,必须先使用 batterySimulationLog 函数创建一个 batterySimulationLog 对象。指定用于创建电池模型库的电池对象作为第一个参量,并指定来自 Simulink 模型中的该电池模块的仿真输出数据作为第二个参量。默认情况下,用于绘制的变量是温度。

batterySimLog = batterySimulationLog(module,out.simlog.Module1);

要显示可以绘制的变量,请查询 BatterySimulationLog 对象的 ModelVariables 属性。这些变量与基本电芯模型模块中的公共变量相对应。

disp(batterySimLog.ModelVariables)
    "batteryVoltage"    "batteryTemperature"    "socCell"    "batteryCurrent"    "numCycles"

要选择另一个变量,请指定 SelectedVariable 属性。软件会自动为变量选择默认单位。然后,您就可以在 SelectedVariableUnit 属性中定义一个相称的单位。

batteryCurrentSimLog = batterySimLog;
batteryCurrentSimLog.SelectedVariable = "batteryCurrent";

要可视化温度变量的值,请使用函数 batterySimulationChart

f = uifigure(Color="w");
g = uigridlayout(f,[2 1]);
packChart = batterySimulationChart(g, ...
    batterySimLog);
packChartColorBar = colorbar(packChart);
ylabel(packChartColorBar,strcat("Cell temperature"," (",batterySimLog.SelectedVariableUnit,")"),FontSize=14);

可视化电流和荷电状态。

packCurrentChart = batterySimulationChart(g, ...
    batteryCurrentSimLog);
packCurrentChart.colormap("parula")
packCurrentChartColorBar=colorbar(packCurrentChart);
ylabel(packCurrentChartColorBar,strcat("Cell current"," (",batteryCurrentSimLog.SelectedVariableUnit,")"),FontSize=14);

故障电芯会导致端电压下降,以及模组内并联组件之间的荷电状态出现差异。

要消除此故障的影响,请将 AddedResistance 故障元素设置为关闭。

Simulink.fault.enable(additionalResistanceFault.ModelElement,false);

仿真具有放热反应故障的短路

在此场景中,您添加一个触发热失控事件的故障,并观察热量在模组中的传播情况。在实际应用中,热失控事件的引发机制多种多样,包括短路、过充和高温等。在此示例中,内部短路触发了放热反应。

使用函数 addFault 为第二个并联组件的第五个电芯添加内部短路故障。要将此故障添加到故障模型中,请使用 addBehavior 函数。

internalShortFault = Simulink.fault.addFault(strcat(batteryBlockPath,"/ParallelAssembly1(2)/Cell1(5)/Internal short"));
addBehavior(internalShortFault,faultModel);

编辑并激活故障。通过分别指定 internalShortFault 对象的 TriggerTypeStartTime 属性,更改触发类型和故障事件时间。

internalShortFault.TriggerType = "Timed";
internalShortFault.StartTime = 30;

要激活该故障,请使用 internalShortFault 对象的 activate 函数。

internalShortFault.activate

现在,使用 addFault 函数在第二个并联组件的第五个电芯中添加一个放热反应故障。要将此故障添加到故障模型中,请使用 addBehavior 函数。

exothermicReactionsFault = Simulink.fault.addFault(strcat(batteryBlockPath,"/ParallelAssembly1(2)/Cell1(5)/Exothermic reactions"));
addBehavior(exothermicReactionsFault,faultModel);

编辑并激活故障。默认情况下,放热反应故障的触发类型为 "Always On"

要激活该故障,请调用 exothermicReactionsFault 对象的 activate 函数。

exothermicReactionsFault.activate

您可以启用模组中所有电芯的放热反应,以查看传热引发的一系列放热反应。通过使每个电芯都发生放热反应,可以更准确地仿真实际电池系统。在此示例中,您不修改电芯之间的热传递,每次只有一个电芯发生放热反应故障。如果所有电芯都能发生放热反应,则由于使用了理想的 Current Source (Simscape Electrical) 模块,求解器可能会遇到求解方程的问题。您可以通过将 5 欧姆电阻与电池模组并联来解决此不稳定问题。

要运行仿真,请使用 sim 函数并定义 StartTimeStopTime 参量。

out = sim(modelname,StartTime="0",StopTime="600");

可视化电池故障

要选择在 BatterySimulationChart 中绘制的变量和变量单位,必须先使用 batterySimulationLog 函数创建一个 BatterySimulationLog 对象。指定用于创建电池模型库的电池对象作为第一个参量,并指定来自 Simulink 模型中的该电池模块的仿真输出数据作为第二个参量。默认情况下,用于绘制的变量是温度。

batterySimLog = batterySimulationLog(module,out.simlog.Module1);

要显示可以绘制的变量,请查询 BatterySimulationLog 对象的 ModelVariables 属性。这些变量与基本电芯模型模块中的公共变量相对应。

disp(batterySimLog.ModelVariables)
    "batteryVoltage"    "batteryTemperature"    "socCell"    "batteryCurrent"    "numCycles"

要选择另一个变量,请指定 SelectedVariable 属性。软件会自动为变量选择默认单位。您可以在 SelectedVariableUnit 属性中定义一个相应的单位。

batteryCurrentSimLog = batterySimLog;
batteryCurrentSimLog.SelectedVariable = "batteryCurrent";

要可视化温度变量的值,请使用 batterySimulationChart 函数。

f = uifigure(Color="w");
g = uigridlayout(f,[2,1]);
packChart = batterySimulationChart(g, ...
    batterySimLog);
packChartColorBar=colorbar(packChart);
ylabel(packChartColorBar,strcat("Cell temperature"," (",batterySimLog.SelectedVariableUnit,")"),FontSize=14);

可视化电流和荷电状态。

packCurrentChart = batterySimulationChart(g, ...
    batteryCurrentSimLog);
packCurrentChart.colormap("parula")
packCurrentChartColorBar=colorbar(packCurrentChart);
ylabel(packCurrentChartColorBar,strcat("Cell current"," (",batteryCurrentSimLog.SelectedVariableUnit,")"),FontSize=14);

另请参阅

| |

主题