Main Content

buildBattery

Build custom library blocks from battery objects

Since R2022b

Description

buildBattery(battery,Name=Value) generates one or more custom Simscape™ library files and a MAT file from the battery object battery. You can build a custom Simscape library file from the ParallelAssembly, Module, ModuleAssembly, and Pack objects.

Note

When you generate a library file for the ParallelAssembly and Module objects, the buildBattery function first generates the corresponding Simscape SSC file and then calls the ssc_build function to generate the library file.

The blocks that are generated from ModuleAssembly and Pack objects are Simulink® subsystems that comprise parallel assemblies and module blocks.

example

Examples

collapse all

Create a Pack object by creating a Cell, ParallelAssembly, Module, and ModuleAssembly objects, in this order.

import simscape.battery.builder.*;
batteryCell = Cell(Geometry=CylindricalGeometry);
pSet = ParallelAssembly(Cell=batteryCell,NumParallelCells=48,Topology="Hexagonal",Rows=4);
module = Module(ParallelAssembly=pSet,NumSeriesAssemblies=4);
moduleAssembly = ModuleAssembly(Module=repmat(module,1,2));
pack = Pack(ModuleAssembly=repmat(moduleAssembly,1,4),BalancingStrategy="Passive");
pack = 

  Pack with properties:

    ModuleAssembly: [1×4 simscape.battery.builder.ModuleAssembly]

Use the buildBattery function to build the library file from the Pack object. Provide the name-value arguments to the function to give the library a meaningful name and to specify the output folder.

buildBattery(pack,LibraryName="myBatteries",Directory="C:\Work\BatteryFolder")
Generating Simulink library 'myBatteries_lib' in the current directory 'C:\Work\BatteryFolder' ...

This figure shows the content of the folder after the function finishes generating the library files:

Open the generated library myBatteries_lib SLX file to access the ParallelAssembly and Module objects as Simscape blocks.

Open the generated library myBatteries SLX file to access the ModuleAssembly and Pack objects as Simscape subsystems.

Input Arguments

collapse all

Battery object from which to generate the custom Simscape library blocks, specified as a ParallelAssembly, Module, ModuleAssembly, or Pack object.

Note

When you build a battery object, the buildBattery function also builds all of its subcomponents. For example, if you build a Pack object, this function generates custom Simscape library blocks for the ModuleAssembly, Module, and ParallelAssembly objects that comprise the pack.

Example: buildBattery(batteryPack) builds a block library from a Pack battery object named batteryPack.

Name-Value Arguments

Example: buildBattery(batteryPack,LibraryName="myBatteries",Directory="C:\Work\batteryLibFolder")

Name of the block library and MAT files generated from the battery object, specified as a character vector or a string scalar. The name of the library file generated from a ParallelAssembly or Module object has the suffix _lib.

Example: buildBattery(batteryPack,LibraryName="myBatteries") builds two libraries named myBatteries and myBatteries_lib and generates a MAT file named myBatteries from a Pack battery object named batteryPack.

Name and location of the folder where you want to store the generated block library and MAT files, specified as a character vector or a string scalar.

Example: buildBattery(batteryPack,Directory="C:\Work\batteryLibFolder") builds a library from a Pack battery object named batteryPack in the folder C:\Work\batteryLibFolder.

Option to use default numeric values or variable names for the parameters in each type of module and parallel assembly defined in the Battery property.

If you set this argument to "VariableNamesByType", the function generates a script with one set of all the run-time parameters required for simulation. These parameters are then used inside all instances of the same type of battery object in the generated library. Use this option when you want to change the parameters of all instances of a battery object type at once.

If you want to parameterize each instance of module or parallel assembly inside the generated library separately, set this argument to "VariableNamesByInstance". The function then generates a script that contains a set of parameters for each instances of the same type of battery object. For example if a ModuleAssembly block contains five Module blocks of the same type, the function generates five different sets of parameters for the five module instances in the generated library. (since R2023b)

Option to use default numeric values or variable names for the initial targets in each type of module and parallel assembly defined in the Battery property. If you set this argument to "VariableNamesByInstance", the function generates a script with all the initial conditions required for simulation.

Version History

Introduced in R2022b

expand all