Skip to content

Battery characterization tool #5536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

kopecdav
Copy link

@kopecdav kopecdav commented Aug 12, 2025

This PR introduces a set of scripts that process captured data from the automatic_battery_tester tool introduced in https://github.com//pull/5212. This tool serves two main purposes:

1) Battery Model Identification

The fuel gauge estimator design requires an identified battery model to predict battery State of Charge (SoC) based on observable variables (terminal voltage, current, temperature). The first purpose of the Battery Characterization Tool is to extract switching and linear waveforms from the dataset and estimate model parameters including:

  • Internal resistance
  • Open-circuit voltage characteristics
  • Thermal relations

The identified model is exported in two formats:

  • .json representation for use with the fuel gauge simulator
  • battery_data header file for embedded firmware fuel gauge library

2) Fuel Gauge Simulator

The second purpose is to use the identified battery model to simulate fuel gauge behavior on captured data and tune filter parameters without time-consuming tests on physical devices. The tool implements three different estimator models:

  • Extended Kalman Filter (EKF) - Primary estimator used in the final application
  • Coulomb Counter - Simple current integration method
  • Dummy Estimator - Direct estimation based on model and actual measurements

While EKF is exclusively used in the final application, the other two estimators provide performance comparison baselines.

Usage

The repository root contains two main scripts:

  • battery_model_identification.py
  • fuel_gauge_simulator.py

Comprehensive usage instructions are provided in the README file.

Dataset and battery model config file

The dataset is not included in the repository due to its size, which may exceed 1GB for a single battery type, but it is available in our internal storage.

The tool is ready to distinguish between battery models by defining the battery model config files in the 'models/battery_models' directory. While there is only one at the moment with only basic vendor name information, we may update the other models and extend the list of the battery model parameters from the specification to propagate them into the battery model header file and potentially use them to automate the settings of other power components in the FW (For instance: cold, cool, warm, hot temperature settings in PMIC).

@kopecdav kopecdav requested review from TychoVrahe and cepetr August 12, 2025 18:46
@kopecdav kopecdav self-assigned this Aug 12, 2025
@kopecdav kopecdav requested a review from obrusvit as a code owner August 12, 2025 18:46
@kopecdav kopecdav added the T3W1 label Aug 12, 2025
@github-project-automation github-project-automation bot moved this to 🔎 Needs review in Firmware Aug 12, 2025
@kopecdav kopecdav requested a review from Copilot August 12, 2025 18:46
Copy link

github-actions bot commented Aug 12, 2025

en main(all)

model device_test click_test persistence_test
T2T1 test(all) main(all) test(all) main(all) test(all) main(all)
T3B1 test(all) main(all) test(all) main(all) test(all) main(all)
T3T1 test(all) main(all) test(all) main(all) test(all) main(all)
T3W1 test(all) main(all) test(all) main(all) test(all) main(all)

Latest CI run: 17103361519

Copilot

This comment was marked as outdated.

@obrusvit obrusvit requested a review from Copilot August 12, 2025 21:07
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a comprehensive battery characterization tool for processing captured data from the automatic battery tester. The tool enables battery model identification and fuel gauge simulation for LiFePO4 batteries.

  • Battery model identification from test data to extract internal resistance and open-circuit voltage characteristics
  • Fuel gauge simulator with multiple estimator implementations (EKF, Coulomb Counter, Dummy)
  • Export functionality for both JSON models and C header files for embedded firmware

Reviewed Changes

Copilot reviewed 19 out of 21 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tools/style.py.exclude Excludes battery characterization tool's virtual environment from style checks
tools/battery_characterization_tool/utils/console_formatter.py Professional console output formatting utilities with ANSI color support
tools/battery_characterization_tool/utils/c_lib_generator.py Generates C header files with battery model data for embedded firmware
tools/battery_characterization_tool/requirements.txt Python package dependencies for the tool
tools/battery_characterization_tool/models/simulator.py Battery simulation engine and result handling
tools/battery_characterization_tool/models/identification.py Battery model parameter identification algorithms and curve fitting
tools/battery_characterization_tool/models/estimators/*.py State-of-charge estimation algorithms (EKF, Coulomb Counter, Dummy)
tools/battery_characterization_tool/models/debug_plots.py Debug visualization utilities for model identification
tools/battery_characterization_tool/models/battery_models/JYHPFL333838.toml Battery model configuration file
tools/battery_characterization_tool/models/battery_model.py Core battery model class with interpolation and curve evaluation
tools/battery_characterization_tool/fuel_gauge_simulator.py Main simulator script for testing fuel gauge algorithms
tools/battery_characterization_tool/dataset/*.py Dataset management and battery profile loading utilities
tools/battery_characterization_tool/battery_model_identification.py Main script for extracting battery model parameters from test data
tools/battery_characterization_tool/README.md Comprehensive documentation and usage instructions
tools/battery_characterization_tool/.gitignore Git ignore rules for generated data and virtual environments
Comments suppressed due to low confidence (2)

tools/battery_characterization_tool/models/identification.py:186

  • Parameter name 'r_int_est' is inconsistent with the function parameter name 'r_int_estim' used in line 198. Consider using consistent naming.
    # make r_int estimation by averaging the values estimation from every transition, consider only half of the

tools/battery_characterization_tool/models/identification.py:359

  • [nitpick] Use unpacking with explicit parameter names rather than positional unpacking to improve code readability and maintainability.
    m, b, a1, b1, c1, a3, b3, c3 = ocv_params

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@kopecdav kopecdav force-pushed the kopecdav/tools/battery_characterization_tool branch from a0e1092 to 3d1bc56 Compare August 13, 2025 07:26
@kopecdav kopecdav force-pushed the kopecdav/tools/battery_characterization_tool branch from 3d1bc56 to c60cd55 Compare August 13, 2025 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🔎 Needs review
Development

Successfully merging this pull request may close these issues.

1 participant