Repository navigation
fix(control): a battery ends fuse relief only as far as the phase can take it #1847
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "ftw": patch | ||
| --- | ||
|
|
||
| A battery that has been relieving the fuse no longer lets go all at once when that would put a phase back over the limit. When a kettle came on while the car charged, the battery discharged to keep the busy phase under the fuse. As soon as the meter showed room, it stopped discharging in one step, and the phase went just over the limit again. Now the battery keeps the part of its discharge that the phase cannot take, counting the car's and its own changes that the meter may not show yet, and lets the rest go as the room shows. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package control | ||
|
|
||
| import ( | ||
| "math" | ||
| "testing" | ||
|
|
||
| "github.com/srcfl/ftw/go/internal/telemetry" | ||
| ) | ||
|
|
||
| // batteryReading gives a battery the SoC its command bounds read. | ||
| func batteryReading(store *telemetry.Store, driver string, w, soc float64) { | ||
| store.Update(driver, telemetry.DerBattery, w, &soc, nil) | ||
| store.RecordDriverSuccess(driver) | ||
| } | ||
|
|
||
| // Field matrix, relief rows (srcfl/ftw#1763's site, 25 A): a kettle on L1, | ||
| // the battery relieving at -3,105 W and L1 reading 19.53 A. Ending that | ||
| // relief is our own raise of 4.5 A on every phase; with the car's unseen | ||
| // 1 A rise it took L1 to 24.03 A, over the 24 A working limit, for more | ||
| // than 3 s. The battery keeps the part of its relief the phase cannot take. | ||
| func TestEVBatteryEndingReliefKeepsWhatThePhaseCannotTake(t *testing.T) { | ||
| for _, tc := range []struct { | ||
| name string | ||
| l1A, carRiseA float64 | ||
| soc float64 | ||
| want float64 | ||
| }{ | ||
| {"the phase takes 3.47 A of the 4.5 A", 19.53, 1, .5, -(3105 - (24-19.53-1)*690)}, | ||
| {"the phase takes it all and some charge", 15, 1, .5, (24-15-1)*690 - 3105}, | ||
| {"a battery at its floor cannot keep it", 19.53, 1, 0.01, 0}, | ||
| } { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| phases := []float64{tc.l1A, tc.l1A - 10, tc.l1A - 10} | ||
| store, state := evSplitFixture(t, (phases[0]+phases[1]+phases[2])*230, phases, 9660+tc.carRiseA*690, "3p") | ||
| sent(state, "ev", 9660, 9660+tc.carRiseA*690) | ||
| sent(state, "first", -3105) | ||
| batteryReading(store, "first", -3105, tc.soc) | ||
| out := clampEVBatteryHeadroom([]DispatchTarget{{Driver: "first", TargetW: 3430}}, store, state, 17250) | ||
| if got := targetW(out, "first"); math.Abs(got-tc.want) > .01 { | ||
| t.Fatalf("battery %.1f W, want %.1f W", got, tc.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // Before our first battery order, after every Core start, the charge cap | ||
| // counts the battery as possibly discharging at its cap. That is no order | ||
| // of ours: it must not become a discharge to keep. The battery keeps its | ||
| // target or less, never a discharge the plan did not ask for. | ||
| func TestEVBatteryWithNoOrderOfOursKeepsNoDischarge(t *testing.T) { | ||
| for _, planW := range []float64{0, 6000} { | ||
| phases := []float64{20.7, 10.7, 10.7} | ||
| store, state := evSplitFixture(t, (phases[0]+phases[1]+phases[2])*230, phases, 4140, "3p") | ||
| batteryReading(store, "first", 0, .5) | ||
| out := clampEVBatteryHeadroom([]DispatchTarget{{Driver: "first", TargetW: planW}}, store, state, 17250) | ||
| if got := targetW(out, "first"); got < 0 { | ||
| t.Fatalf("plan %.0f W with no order logged: battery %.0f W, want no discharge", planW, got) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After startup, an idle battery with no command history can be commanded to discharge here:
clampEVBatteryHeadroomsubstitutes the negative discharge cap for a missing command, and this loop treats that conservative reservation as discharge to preserve. For a 3×25 A site with an active EV, zero pending raises, a 5 kW battery discharge cap, measured export of 9 kW and a worst phase of 23 A, the new clamp changes a validated 0 W target to −4,310 W. An idle battery obeying that command raises export to 13,310 W, exceeding a configured 10 kW export ceiling; the export guard already ran earlier inapplyDispatchSafetyPipeline. Keep the missing-history reservation for optional-charge budgeting, but require an actual prior discharge command before restoring negative power. This avoids issuing a clamp command without the quantified risk required byAGENTS.md.AGENTS.md reference: AGENTS.md:L68-L68
Useful? React with 👍 / 👎.