Build a Simple Model of a Battery Pack in MATLAB and Simscape
This example shows how to create and build a Simscape™ system model of a battery pack in Simscape™ Battery™. The battery pack is a 400 V pouch battery for automotive applications. To create the system model of a battery pack, you must first create the Cell,
ParallelAssembly,
Module,
and ModuleAssembly
objects that comprise the battery pack, and then use the buildBattery
function. The buildBattery
function allows you to automatically generate Simscape models for these Simscape Battery objects:
This function creates a library in your working folder that contains a system model block of a battery pack that you can use as reference in your simulations. The run-time parameters for these models, such as the battery cell impedance or the battery open-circuit voltage, are defined after the model creation and are therefore not covered by the Battery Pack Builder classes. To define the run-time parameters, you can either specify them in the block mask of the generated Simscape models or use the MaskParameters argument of the buildBattery
function.
To use the functions and objects in Simscape Battery, first import the required Simscape Battery package:
import simscape.battery.builder.*
Create Battery Pack Object in MATLAB
To create a battery pack, you must first design and create the foundational elements of the battery pack.
This figure shows the overall process to create a battery pack object in a bottom-up approach:
A battery pack comprises multiple module assemblies. These module assemblies, in turn, comprise a number of battery modules connected electrically in series or in parallel. The battery modules are made of multiple parallel assemblies which, in turn, comprise a number of battery cells connected electrically in parallel under a specific topological configuration or geometrical arrangement.
Create Cell Object
To create the battery Module
object, first create a Cell
object of pouch format.
pouchGeometry = PouchGeometry(Height = simscape.Value(0.1,"m"),... Length = simscape.Value(0.3,"m"), TabLocation = "Opposed" )
pouchGeometry = PouchGeometry with properties: Length: [1x1 simscape.Value] Thickness: [1x1 simscape.Value] TabLocation: "Opposed" TabWidth: [1x1 simscape.Value] TabHeight: [1x1 simscape.Value] Height: [1x1 simscape.Value]
The PouchGeometry
object allows you to define the pouch geometrical arrangement of the battery cell. You can specify the height, length, and location of tabs of the cell by setting the Height, Length, and TabLocation properties of the PouchGeometry
object. For more information on the possible geometrical arrangements of a battery cell, see the CylindricalGeometry
and PrismaticGeometry
documentation pages.
Now use this PouchGeometry
object to create a pouch battery cell.
batteryCell = Cell(Geometry = pouchGeometry)
batteryCell = Cell with properties: Geometry: [1x1 simscape.battery.builder.PouchGeometry] CellModelOptions: [1x1 simscape.battery.builder.CellModelBlock] Mass: [1x1 simscape.Value] Show all properties
For more information, see the Cell
documentation page.
Create ParallelAssembly Object
A battery parallel assembly comprises multiple battery cells connected electrically in parallel under a specific topological configuration or geometrical arrangement. In this example, you create a parallel assembly of three pouch cells.
To create the ParallelAssembly object, use the Cell
object you created before and specify the NumParallelCells property according to your design.
batteryParallelAssembly = ParallelAssembly(Cell = batteryCell,...
NumParallelCells = 3)
batteryParallelAssembly = ParallelAssembly with properties: NumParallelCells: 3 Cell: [1x1 simscape.battery.builder.Cell] Topology: "SingleStack" Rows: 1 ModelResolution: "Lumped" Show all properties
For more information, see the ParallelAssembly
documentation page.
Create Module Object
A battery module comprises multiple parallel assemblies connected in series. In this example, you create a battery module of 11 parallel assemblies with an intergap between each assembly of 0.005 meters.
To create the Module
object, use the ParallelAssembly
object you created in the previous step and specify the NumSeriesAssemblies and InterParallelAssemblyGap properties.
batteryModule = Module(ParallelAssembly = batteryParallelAssembly,... NumSeriesAssemblies = 11, InterParallelAssemblyGap = simscape.Value(0.005,"m"))
batteryModule = Module with properties: NumSeriesAssemblies: 11 ParallelAssembly: [1x1 simscape.battery.builder.ParallelAssembly] ModelResolution: "Lumped" SeriesGrouping: 11 ParallelGrouping: 1 Show all properties
For more information, see the Module
documentation page.
Create ModuleAssembly Object
A battery module assembly comprises multiple battery modules connected in series or in parallel. In this example, you create a battery module assembly of two identical modules with an intergap between each module equal to 0.1 meters. By default, the ModuleAssembly
object electrically connects the modules in series.
To create the ModuleAssembly
object, use the Module
object you created in the previous step and specify the InterModuleGap property.
batteryModuleAssembly = ModuleAssembly(Module = repmat(batteryModule,1,2),... InterModuleGap = simscape.Value(0.1,"m"))
batteryModuleAssembly = ModuleAssembly with properties: Module: [1x2 simscape.battery.builder.Module] Show all properties
For more information, see the ModuleAssembly
documentation page.
Create Pack Object
You now have all the foundational elements to create your battery pack. A battery pack comprises multiple module assemblies connected in series or in parallel. In this example, you create a battery pack of 5 identical module assemblies with an intergap between each module assembly of 0.01 meters.
To create the Pack
object, use the ModuleAssembly
object you created in the previous step and specify the InterModuleAssemblyGap property.
batteryPack = Pack(ModuleAssembly = repmat(batteryModuleAssembly,1,5),... InterModuleAssemblyGap = simscape.Value(0.01,"m"))
batteryPack = Pack with properties: ModuleAssembly: [1x5 simscape.battery.builder.ModuleAssembly] Show all properties
For more information, see the Pack
documentation page.
Visualize Battery Pack and Check Model Resolution
To obtain the number of Simscape Battery(Table-Based) blocks used for the pack simulation, use the NumModels property of your Pack
object.
disp(batteryPack.NumModels);
10
To visualize the battery pack before you build the system model and to view its model resolution, use the BatteryChart
object.
Then use the BatteryChart
object to visualize the battery pack. To view the model resolution of the module, set the SimulationStrategyVisible property of the BatteryChart
object to "On"
.
batteryPackChart = BatteryChart(Parent = uifigure, Battery = batteryPack, ... SimulationStrategyVisible = "on");
To add default axis labels to the battery plot, use the setDefaultLabels
method of the BatteryChart
object.
For more information, see the BatteryChart
documentation page.
Build Simscape Model for the Battery Pack Object
After you have created your battery objects, you need to convert them into Simscape models to be able to use them in block diagrams. You can then use these models as reference for your system integration and requirement evaluation, cooling system design, control strategy development, hardware-in-the-loop, and much more.
To create a library that contains the Simscape Battery model of the Pack
object you created in this example, use the buildBattery
function.
buildBattery(batteryPack,"LibraryName","packLibrary");
Generating Simulink library 'packLibrary_lib' in the current directory '/tmp/Bdoc22b_2134332_1821819/tpacc0024e/simscapebattery-ex38941777' ...
This function creates the packLibrary_lib
and packLibrary
SLX library files in your working directory. The packLibrary_lib
library contains the Modules and ParallelAssemblies sublibraries.
To access the Simscape models of your Module
and ParallelAssembly
objects, open the packLibrary_lib
. SLX file, double-click the sublibrary, and drag the Simscape blocks in your model.
The packLibrary
library contains the Simscape models of your ModuleAssembly
and Pack
objects.
The Simscape models of your ModuleAssembly
and Pack
objects are subsystems. You can look inside these subsystems by opening the packLibrary
SLX file and double-click the subsystem.
To learn how to include thermal effects in a battery pack, see the Build Model of Battery Module with Thermal Effects example.
To build a more detailed model of a battery pack, see the Build Detailed Model of Battery Pack From Pouch Cells example.
To learn how to model a battery energy storage system (BESS) controller and a battery management system (BMS) with all the necessary functions for the peak shaving, see the Peak Shaving with Battery Energy Storage System example.