A Python simulation of battery management for scooters, retrofitted cars and buses, plus a NASA battery-data cleaning notebook and a validation suite for six Kaggle datasets. The built-in validation runs on synthetic stand-ins; this post says so plainly. Simulation only, not engineering design.
Open-Source Tools · How-To · Engineering sims
How to use ev-battery-management-sim: simulate EV battery packs and test the model on battery datasets
Revised
· v1.0.0 · what changed
Code: github.com/herrrickshaw/ev-battery-management-sim
Watch the walkthrough
Watch on YouTube: youtu.be/e5MgJPizoEo
Why it is useful
- Who benefits: students, e-mobility analysts and engineers who want a runnable reference of a battery management system (charge estimate, ageing, balancing, thermal limits, fault handling).
- What it replaces: stitching together a cell model, a Kalman filter and a wear model from scratch. The vehicle comparison, degradation, cold-weather and 10-year projection runs are one command each.
- Evidence from the run: 112 tests passed in 4.2 seconds, and the dataset validation printed a five-part report in about 8 seconds on a laptop.
- It also ships a cleaning notebook that turns the NASA battery .mat files into CSVs, which is useful if you download the NASA data yourself.
What it is for
The bms package models a lithium or lead-acid pack: a two-RC equivalent-circuit cell, an Extended Kalman Filter for state of charge, capacity and resistance fade for state of health, passive balancing, thermal control, power limits and a supervisor that opens the contactor on faults. Run python -m bms.simulation with a flag to see each part.
It is a teaching and prototyping tool. It is simulation only, not engineering design: do not use it to size or certify a real pack.
Who it is for
- Students and engineers learning how a BMS works
- EV and e-mobility analysts who want a runnable reference
- Non-programmers who want an AI assistant to explain each algorithm
- Running or certifying a real battery pack. This is a conceptual simulation, not firmware and not an engineering design.
- Claiming real-world accuracy from the validation numbers. They come from synthetic data generated to match the schemas of the Kaggle files.
- Predicting the life of a specific real cell.
What you need
| Requirement | Why | How to get it |
|---|---|---|
| Python 3 with numpy, pandas, pytest | the library and tests | pip install numpy pandas pytest. The repo has no requirements.txt, so these were installed by hand |
| scipy, matplotlib | scipy for the NASA notebook, matplotlib for --plot and notebook charts | pip install scipy matplotlib |
| Kaggle account and API token (optional) | download the six real datasets for the NASA notebook and real validation | kaggle.com, Account, API token into ~/.kaggle/ then scripts/fetch_kaggle_data.sh. I did not do this. |
| Not needed | no GPU, no hardware | runs on a laptop |
Get the code and an AI assistant
You do not have to be a programmer. Get the repository, give it to an AI assistant, and ask in plain language. Any of these routes works:
| Tool | What you need | Best for |
|---|---|---|
| GitHub | Free account to fork or star; git to clone, or the green Code button, then Download ZIP, or open in Codespaces | Getting the code and keeping up with updates |
| Claude Code | Claude subscription or API key; run claude inside the cloned folder | Letting the AI read and run the whole repo |
| Gemini CLI | Google account; run gemini inside the cloned folder | The same hands-on workflow with Gemini |
| Claude.ai, Gemini or ChatGPT in the browser | A chat account; upload README.md and the files you care about (or paste the output of git ls-files) | Understanding the project and asking questions without installing anything |
| Other tools (Copilot Chat, Cursor, Codex CLI) | Open the cloned folder in the tool and point it at README.md first | Editing and extending the code |
git clone https://github.com/herrrickshaw/ev-battery-management-sim.git
cd ev-battery-management-sim
claude # or: gemini
Install
- Get the code
git clone https://github.com/herrrickshaw/ev-battery-management-sim.git cd ev-battery-management-sim - Create an environment and install
python3 -m venv .venv && source .venv/bin/activate pip install numpy pandas pytest scipy matplotlib
Quick start: commands and what you should see
Run the tests
python -m pytest -q
112 passed.
Compare the vehicle classes
python -m bms.simulation --vehicle 2W
A comparison table of the four vehicle classes, then the scooter run.
Run the degradation simulation
python -m bms.simulation --degradation
Cycle-by-cycle table of capacity and resistance fade for a scooter and a bus.
Run the dataset validation (synthetic)
python -m bms.simulation --datasets
Six synthetic datasets are generated and a five-part validation report is printed.
Sample outputs
Real output from a run on the date shown in the sources line; trimmed to fit.
Vehicle comparison table
python -m bms.simulation
2-Wheeler (Scooter) LFP 15S1P 48V 1.4 kWh 1.5 kW CC-CV
4W Retrofit (PbA) Lead-Acid 36S1P 72V 9.4 kWh 10 kW CC-CV-Float
4W Modern LFP LFP 32S1P 102V 6.1 kWh 30 kW CC-CV
Electric Bus LFP 128S2P 409V 163.8 kWh 150 kW CC-CV
Trimmed columns.
Degradation run, 48 V scooter pack (accelerated model)
python -m bms.simulation --degradation
Cycle SOH-Q% Cap(Ah) SOH-R% R0(mOhm) Status
100 90.0 90.0 90.9 2.20 OK
200 80.0 80.0 83.3 2.40 OK
250 75.0 75.0 80.0 2.50 WARNING
300 70.0 70.0 76.9 2.60 WARNING
EOL at SOH=80.0% : ~200 cycles
A straight-line fade of 0.1% per cycle; the script itself labels it an accelerated model.
Validation report (synthetic data matching Kaggle schemas)
python -m bms.simulation --datasets
1. EKF SOC estimation RMSE 0.117 % MAE 0.113 % PASS (target < 3 %)
2. Capacity fade SOH RMSE 0.0504 % fitted fade 0.1001 %/cycle EOL cycle 199
3. 2-RC voltage model RMSE 1.07 mV MAPE 0.027 % PASS (target < 20 mV)
4. RUL estimation RMSE 4.2 cycles MAPE 4.28 %
5. Multi-module health degraded module [3], avg SOH 85.0 % vs 97.3 %
NOTE: Results above use synthetic data matching Kaggle dataset schemas.
Run on 19 October 2026.
NASA battery-life notebook
nasa-battery-life-prediction-dataset-cleaning.ipynb
Not run. The notebook reads .mat files from /kaggle/input/nasa-battery-dataset, which needs a Kaggle login and download.
Its cells convert each NASA cycle into a CSV plus a metadata.csv; I read them but did not execute them.
Ways to use it
| Method | How it works |
|---|---|
| Command line | Flags: --vehicle, --degradation, --cold, --driving, --manufacturers, --datasets, --plot. |
| Python import | Import the bms modules to build your own pack or driving profile. |
| Real data | Download the Kaggle sets with scripts/fetch_kaggle_data.sh and swap them in via bms/datasets/loaders.py. |
| Ask an AI assistant | Have it explain the EKF, or add a new chemistry in bms/chemistries.py. |
Sample prompts for your AI assistant
Copy, paste and edit the parts in [brackets].
- Claude: Read bms/soc_estimator.py and explain in plain language how the Kalman filter estimates state of charge.
- Gemini: Run python -m bms.simulation --cold and describe at what temperature the first fault appears.
- ChatGPT: I uploaded the output of --datasets. Which of the five checks are circular because the data were generated by the same model?
- GitHub (Copilot Chat): Add a requirements.txt listing numpy, pandas, scipy, matplotlib and pytest, and check the tests still pass.
- Claude: Walk me through the NASA cleaning notebook cell by cell and list what files it produces.
Limits and honest caveats
- The six 'Kaggle validation' checks run on synthetic data generated to match the Kaggle file layouts, and the script prints this itself. They are not evidence of accuracy on real cells. Because the fitted fade rate (0.1001 %/cycle) matches the rate used to generate the data, check 2 is partly circular.
- The NASA notebook and real-data validation need Kaggle downloads and credentials; not run here. data/kaggle/ is gitignored.
- No requirements.txt: numpy, pandas, scipy, matplotlib and pytest had to be installed by hand.
- Quirk found: in the distributed-BMS check, module 3 is detected as degraded (SOH 85 % versus 97.3 %) yet 'Degraded alerts' is 0, so the alert path did not fire for that module.
- Degradation is a linear, accelerated model; the script's own label says 0.1 % per cycle is not a real LFP rate.
- This is a conceptual simulation, not engineering design, firmware or a safety case.
Sources: Ran pytest and python -m bms.simulation (default, --degradation, --datasets) from a fresh clone of github.com/herrrickshaw/ev-battery-management-sim (commit b6d37cd) in a throwaway virtualenv on 19 October 2026. The NASA notebook and Kaggle downloads were not run.
- v1.0.0 — 23 October 2026 — first published.
About this article: Researched, written and edited by Umashankar Triplicane Dwarakanathan, with AI research assistance; every figure is meant to trace to the primary source cited. See the Editorial Policy for how sourcing, AI use and corrections work.