Skip to content

Commit

Permalink
Added Battery Management and Neural Network examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
smiller01985 committed Dec 22, 2021
1 parent 1bc2f7c commit ae94758
Show file tree
Hide file tree
Showing 138 changed files with 750 additions and 33 deletions.
18 changes: 18 additions & 0 deletions Libraries/+batteryModule/batteryCellVoltages.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
classdef batteryCellVoltages < int32
% Battery type selection definition.

% Copyright 2020-2021 The MathWorks, Inc.
enumeration
no (1)
yes (2)
end

methods(Static)
function map = displayText()
map = containers.Map;
map('no') = 'No';
map('yes') = 'Yes';
end
end
end

27 changes: 26 additions & 1 deletion Libraries/+batteryModule/batteryMultiDimModel.ssc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ end
outputs
outputCellSOC = {ones(1,Ns*Np),'1'}; % SOC
outputCellTemp = {ones(1,Ns*Np),'K'}; % Temp
outputCellV = {ones(1,Ns*Np),'V'}; % V
%
bottom_thermPort = {zeros(2,Ns*Np),'1'}; % QT_b
top_thermPort = {zeros(2,Ns*Np),'1'}; % QT_t
Expand Down Expand Up @@ -161,6 +162,7 @@ parameters
%
moduleExtHeat={zeros(1,10),'W'}; % External heat
moduleCellBalancing=batteryModule.batteryCellBalancing.none; % Cell balancing
moduleCellVoltages=batteryModule.batteryCellVoltages.no; % Output cell voltages (yes/no)
passiveShuntR={50,'Ohm'}; % Shunt resistor
passiveSWclosedR={0.01,'Ohm'}; % Switch closed resistance
passiveSWopenCond={1e-8,'1/Ohm'}; % Switch open conductance
Expand Down Expand Up @@ -277,7 +279,7 @@ annotations
UIGroup("Cell Electrical",LUTpointsTemp,cellAHvector,LUTpointsSOC,V0_mat, prm_dir, R0_mat, R0_dis_mat, R0_ch_mat, prm_leak, Rleak_vec, extrapolation_option, prm_dyn, R1_mat, tau1_mat, R2_mat, tau2_mat, R3_mat, tau3_mat, R4_mat, tau4_mat, R5_mat, tau5_mat)
UIGroup("Cell Capacity Fade", prm_fade, N0, dV0, dR0, dAH, dRleak, dR1, dR2, dR3, dR4, dR5, N0vec, Tfadevec, dV0vec, dR0vec, dAHvec, dRleakvec, dR1vec, dR2vec, dR3vec, dR4vec, dR5vec, dV0mat, dR0mat, dAHmat, dRleakmat, dR1mat, dR2mat, dR3mat, dR4mat, dR5mat)
UIGroup("Cell Thermal",cellThermalMass, cellThermalCond,cellThermalCond_inPlane)
UIGroup("Module Electrical",Ns,Np,cellTypeSelection,cellHeight,cellWidth, cellThickness, cellDiameter, cellCylinLine, moduleExternalR,moduleCellBalancing,passiveShuntR,passiveSWclosedR,passiveSWopenCond,passiveSWthreshold)
UIGroup("Module Electrical",Ns,Np,cellTypeSelection,cellHeight,cellWidth, cellThickness, cellDiameter, cellCylinLine, moduleExternalR,moduleCellBalancing,passiveShuntR,passiveSWclosedR,passiveSWopenCond,passiveSWthreshold,moduleCellVoltages)
UIGroup("Module Thermal", thermalManagement,cellHeatTrCoeff,thermal_moduleBottom,htc_bottom,moduleCooling_b,LUTpointsFlowrate_b,LUTpointsTemp_b,thermal_moduleTop,htc_top,moduleCooling_t,LUTpointsFlowrate_t,LUTpointsTemp_t,thermal_moduleRight,htc_right,moduleCooling_r,LUTpointsFlowrate_r,LUTpointsTemp_r,thermal_moduleLeft,htc_left,moduleCooling_l,LUTpointsFlowrate_l,LUTpointsTemp_l,thermal_modulePos,htc_pos,moduleCooling_p,LUTpointsFlowrate_p,LUTpointsTemp_p,thermal_moduleNeg,htc_neg,moduleCooling_n,LUTpointsFlowrate_n,LUTpointsTemp_n,moduleExtHeat)
UIGroup("Cell-to-Cell Variation",cellTemp, cellSOC, moduleCellAHpercentVar,moduleCellLeakPercentVar,moduleCellR0PercentVar)]
end
Expand Down Expand Up @@ -470,6 +472,7 @@ annotations
negEnd_thermPort_R : Side=Right;
negEnd_thermPort_C : Side=Right;
Qn : Side=Right;
outputCellV : Side=Left;
end

% Parameter definition for internal usage; processing user defined parameters
Expand Down Expand Up @@ -661,6 +664,19 @@ else
%
end

if modelComplexity == batteryModule.batteryAbstractionLevel.lumped
annotations
[moduleCellVoltages,outputCellV] : ExternalAccess=none;
end
else
if moduleCellVoltages == batteryModule.batteryCellVoltages.no
annotations
[outputCellV] : ExternalAccess=none;
end
end
end


if modelComplexity == batteryModule.batteryAbstractionLevel.grouped
equations
assert(groupedModelCheck>0,'Monitoring cells must be apart by more than twice the number of parallel cells');
Expand Down Expand Up @@ -1491,6 +1507,7 @@ if modelComplexity == batteryModule.batteryAbstractionLevel.detailed
% Record output
outputCellTemp == [battery_thermal.temperature];
outputCellSOC == [battery_thermal.stateOfCharge];
outputCellV == [battery_thermal.v];
end
% Loop over number of cells and create array of components for Cell Model
% and the relevant heat transfer
Expand Down Expand Up @@ -2329,9 +2346,17 @@ elseif modelComplexity == batteryModule.batteryAbstractionLevel.grouped
SOCval3 = ones(1,k)*SOCval(3);
SOCval4 = ones(1,l)*SOCval(4);
SOCval5 = ones(1,m)*SOCval(5);
% Voltage is assumed to be dropping equally among all series strings
cellVoltval = [battery_thermal_grouped.v];
cellVoltval1 = ones(1,i)*cellVoltval(1)/(Np*i);
cellVoltval2 = ones(1,j)*cellVoltval(2)/(Np*j);
cellVoltval3 = ones(1,k)*cellVoltval(3)/(Np*k);
cellVoltval4 = ones(1,l)*cellVoltval(4)/(Np*l);
cellVoltval5 = ones(1,m)*cellVoltval(5)/(Np*m);
in
outputCellTemp == [tempVal1,tempVal2,tempVal3,tempVal4,tempVal5];
outputCellSOC == [SOCval1,SOCval2,SOCval3,SOCval4,SOCval5];
outputCellV == [cellVoltval1,cellVoltval2,cellVoltval3,cellVoltval4,cellVoltval5];
end
end
%
Expand Down
2 changes: 1 addition & 1 deletion Libraries/+batteryModule/bottomCoolantPlate.ssc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ component bottomCoolantPlate
% bottomCoolantPlate:7:rotates

% Copyright 2020-2021 The MathWorks, Inc.

nodes
amb = foundation.thermal.thermal; % Amb
coolantIn = foundation.thermal_liquid.thermal_liquid;% in
Expand Down
Binary file not shown.
Binary file modified Models/BEV_Battery_Plant_Model/Battery_Module_Design.slx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Models/Battery_Management_System.slx
Binary file not shown.
Binary file added Models/Battery_Management_System_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Models/Battery_Pack_Thermal_Management.slx
Binary file not shown.
Binary file added Models/Battery_TempPredUsingNN_PhysicsModel.slx
Binary file not shown.
Binary file modified Models/EV_Thermal_Management.slx
Binary file not shown.
75 changes: 75 additions & 0 deletions Overview/Battery_Management_System.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
%% Battery Management System
%
% This example shows how to model a battery management system for the state
% of charge estimation. The battery pack comprises of two battery modules,
% which are combinations of cells in series and parallel. The *Battery
% (Table-Based)* Simscape Electrical(TM) block models each battery cell.
% In this example, all cells have the same initial temperature and state of
% charge, but different resistance. The state of each cell is estimated
% using battery pack current and the measured cell voltages.
%
% Copyright 2021 The MathWorks, Inc.


%% Model Overview
% This example models a battery pack connected to an auxiliary power load
% due to the coolant pump. The BMS subsystem defines the required amount of
% the coolant flowrate to cool the high voltage (HV) battery pack. A
% controlled current source defines the DC current demand from the HV
% battery pack. To calculate the state of charge for the battery pack, the
% BMS subsystem uses the cell voltages and temperature, and the battery
% pack current. The cell capacity does not change with time or cycling and
% is the same for all the cells.

open_system('Battery_Management_System')

%% Battery Cell Overview
% The battery cell is modeled using the equivalent circuit method. You can
% find the equivalent circuit parameters used for each cell in the
% |Battery_Management_System_param.m| initialization file . To characterize a
% lithium-ion cell, this example uses a 1-RC model by setting the |charge dynamics|
% parameter to |One time-constant dynamics|. This example does not consider
% cell capacity fade or charge leakage.

%% Build Battery Pack
% The Battery Pack comprises of 2 series connected Battery Modules. Each
% module consists of 10 series connected |Pouch| type cells. The value of
% the terminal resistance, |R0|, in the first cell of the first module is
% 5% higher than the value of terminal resistance in the other cells. The
% value of the terminal resistance, |R0|, in the third cell of the second
% module is 3% lower than the value of |R0| in the other cells. The
% |Battery_Management_System_param.m| file sets this scenario by specifying
% |iniR01(1,1)| to 1.05 and |iniR02(1,3)| to 0.97.
%

open_system('Battery_Management_System/Battery Pack')

%% Define Battery Management System
% The BMS subsystem calculates the battery state of charge and controls the
% coolant flowrate. The coolant pump power loss is calculated based on the
% value at the |FlwR| input port, with 500W being the maximum pump power
% consumption. This example uses the extended Kalman-Filter (EKF) in the
% SOC estimation subsystem to calculate the state of charge.

open_system('Battery_Management_System/BMS')

%% Define Battery State-of-Charge Estimation
% To calculate the state of charge, the EKF uses the pack current, cell
% voltages, and temperature data. The SOC estimation subsystem also
% implements a lookup table to define the cell model. The EKF reduces the
% error between the prediction and measurement of the cell voltages.

open_system('Battery_Management_System/BMS/SOC estimation')

%% Simulation Results
% This figure shows the simulation results with the parameters defined in
% the |Battery_Management_System_param.m| file. The cell voltages are
% different for the cells with different resistance |R0|. The BMS accurately
% tracks the state of charge of all cells.

Battery_Management_System_plot1state


%%
close all
bdclose all
Binary file modified Overview/batteryModuleDoc_example.slx
Binary file not shown.
Loading

0 comments on commit ae94758

Please sign in to comment.