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

Note

To use this object, at the MATLAB® Command Window, run this command at least once:

import simscape.battery.builder.*; 

example

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

battsimlog = BatterySimulationLog(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 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.

import simscape.battery.builder.*
batterycell = Cell(Geometry = CylindricalGeometry);
batterycell.CellModelOptions.BlockParameters.thermal_port = "model";
batteryparallelAssembly = ParallelAssembly(Cell=batterycell,...
    NumParallelCells=15,Rows=3);
batterymodule = Module(ParallelAssembly = batteryparallelAssembly, ...
    ModelResolution = "Detailed", ...
    AmbientThermalPath="CellBasedThermalResistance");
libraryname = "Batteries";
buildBattery(batterymodule,"LibraryName",libraryname);

Create 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/", batterymodule.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.

batterySimLog = BatterySimulationLog( batterymodule,  out.simlog.Module1);

Select the variable for visualization, then display the object.

batterySimLog.SelectedVariable = "temperatureCell";
disp(batterySimLog)

Version History

Introduced in R2023b