Main Content

batterySimulationLog

Store logged Simscape simulation data of battery block in Simulink model

Since R2023b

Description

Use batterySimulationLog to construct a battery simulation object that stores the logged Simscape™ simulation data of a specific battery block inside a Simulink® model.

This Simulink model must contain at least one of the Simscape Battery™ blocks that you generate by using the objects and functions in the Battery Pack Model Builder, including ParallelAssembly, Module, ModuleAssembly, and Pack.

Use this object as an input to the BatterySimulationChart object to dynamically visualize the values of a specific variable on top of the 3-D battery simulation chart using a colormap.

Use the BatterySimulationLog object to:

  • Store the dynamic output data of a specific battery block.

  • Specify which block variable to visualize in the BatterySimulationChart object.

  • Specify a commensurate Simscape unit to visualize the selected variable.

Creation

Description

example

battsimlog = batterySimulationLog(Battery,SimLog) creates a BatterySimulationLog object that stores the logged Simscape simulation data Parent of a Simulink model for the battery object specified in the Battery property.

battsimlog = batterySimulationChart(Battery,SimLog,Name=Value) sets further Properties using one or more name-value arguments.

Properties

expand all

Battery object associated with the block in the simulation, specified as a ParallelAssembly, Module, ModuleAssembly, or Pack object.

Logged simulation data of a battery block from the simulation output, specified as a simscape.logging.Node object. To learn how to obtain the logged simulation data, see Enable Simscape Data Logging for the Whole Model.

Name of the variable of the battery block to visualize in the battery simulation chart, specified as a string scalar.

Unit of the variable of the battery block to visualize in the battery simulation chart, specified as a string scalar.

This property is read-only.

List of block variables that you can specify in the SelectedVariable property for the battery block in the Battery property, returned as a string array.

Examples

collapse all

Create the Simscape Battery block.

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);

Create and open the Simulink battery model.

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

Name and add the required blocks to the mode.

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");

Get the handles to the block ports and connect all blocks.

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');

Enable the logged simulation data for your model.

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

Simulate the model.

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

Create a BatterySimulationLog object. Select the variable for visualization, then display the object.

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"]

Version History

Introduced in R2023b