Skip to content

Saturate unachievable power setpoints at matched-load current#11

Merged
martincornejo merged 1 commit into
mainfrom
fix-battery-eq
May 17, 2026
Merged

Saturate unachievable power setpoints at matched-load current#11
martincornejo merged 1 commit into
mainfrom
fix-battery-eq

Conversation

@martincornejo

Copy link
Copy Markdown
Collaborator

Battery.equilibrium_current raised ValueError from math.sqrt when the requested |P| exceeded the matched-load ceiling OCV²/(4·R) — typical at low SOC with aged R_int. The downstream curtailment in step() already catches this via the voltage/SOC limits, but only after the unguarded sqrt blew up.

Clamp the discriminant at zero so the unachievable setpoint collapses to the matched-load current; step() then curtails normally.

Closes #10

Battery.equilibrium_current raised ValueError from math.sqrt when the
requested |P| exceeded the matched-load ceiling OCV²/(4·R) — typical at
low SOC with aged R_int. The downstream curtailment in step() already
catches this via the voltage/SOC limits, but only after the unguarded
sqrt blew up.

Clamp the discriminant at zero so the unachievable setpoint collapses
to the matched-load current; step() then curtails normally.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@martincornejo martincornejo merged commit 2769f80 into main May 17, 2026
6 checks passed
@martincornejo martincornejo deleted the fix-battery-eq branch May 17, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Battery.equilibrium_current crashes when the discharge setpoint exceeds the battery's max deliverable power

1 participant