Controls · Simulation
Simulated 48-cell battery management system
A 48-cell lithium-ion (NMC) pack and the battery management system that runs it, both simulated in Python with no hardware.
Working only from noisy bus telemetry up to 0.9 s old, an unscented Kalman filter (UKF) tracked state of charge (SOC) to 0.44% RMSE, and in the validation runs a residual detector diagnosed all four injected fault types with no false flags. Seven of eight phases are done; the results write-up is not.
The problem
A pack controller never sees a cell directly. It gets noisy cell voltages up to 0.9 s old, one pack current and two temperature sensors per eight cells. From that it must estimate each cell's state of charge (SOC) and health, balance the pack and catch faults early.
I built the pack and its controller as one Python simulation, with no hardware.
What I built
Each cell is a second-order Thevenin model of a 2.5 Ah NMC cell with hysteresis, aging and temperature-dependent (Arrhenius) resistances. Forty-eight sit in series on a 6 by 8 thermal grid, with seeded manufacturing spread.
The controller reads only telemetry, with 1.5 mV of noise and 1 mV quantization on each voltage.
One five-state filter per cell estimates SOC, two RC voltages, resistance R0 and capacity. I ran an unscented Kalman filter (UKF) against an extended one (EKF). Each late voltage is paired with the current at its own sample time, and the R0 gain is zeroed at low current.
Every 60 s a linear program (LP) schedules 1 A cell-to-pack converters from those estimates. A residual detector compares each cell with the 48-cell median, and a policy answers each diagnosis with a current limit or an open contactor.
A FastAPI and WebSocket dashboard runs the loop live, with fault injection from the browser.
Results
Phases 1 to 6 each end in a scripted validation suite. All 52 checks pass at the current commit.
The estimation test is a 2 hour synthetic drive cycle on a pre-aged pack. Both filters booted at 50% SOC against a true 95%. The UKF was within 2% after 2 s and the EKF after 58 s. After the first 15 min, the UKF held 0.44% RMSE over all 48 cells and the EKF 0.71%. Coulomb counting (integrating current) from the same wrong start sat at 41.7%.
With the pack at rest, the LP balancer closed a 10.5% SOC spread to under 1% in 808 s and lost 0.95 Wh. A 150 mA passive bleed took 5,667 s and burned 21.74 Wh.
The detector diagnosed all four injected faults on the right cell: an internal short in 9 s, a frozen sensor in 12 s, a 60 mV sensor offset in 54 s and 2,000x accelerated aging in 1,302 s. The five validation runs raised no false flags in 96 cell-hours.
Limits and next steps
The filter and the truth model share one structure, so the tests cover parameter mismatch and bad telemetry only. No cell was measured; parameters are nominal NMC values.
Each fault was validated in one scenario with one seed. The 9 s short was injected near 78% SOC. In the dashboard recording here, near 53% SOC, the onset pushed the shorted cell's SOC estimate up while its true SOC fell. The diagnosis took 125 simulated seconds, with the cell above 100 °C.
A later fix for false aging flags in hour-long dashboard soaks raised the R0 low-current cutoff from 0.5 A to 1.25 A. It also slowed balancing: the same scenario took 473 s before that change.
Phase 8, the results write-up, is not done.
Ask a question about this project
An AI assistant answers from this site's text. It can be wrong; this page is the source.





