Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/a4-one-soc-floor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ftw": patch
---

Keep the battery above its minimum level when no plan exists, during fuse protection and under the hourly import limit. The floor is the highest of 5 %, the battery's `soc_min` and the planner's `soc_min` (10 % by default). Below it, the car is the lever for the fuse. The hourly import limit also no longer discharges below a battery-boost reserve.
29 changes: 29 additions & 0 deletions go/cmd/ftw/battery_soc_max_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,32 @@ func TestSoCMaxConfigPrecedenceAndReload(t *testing.T) {
ctrl.DriverLimits = driverLimitsFrom(cfg.ModbusControlDrivers(), cfg.Batteries, cfg.Planner)
check(.5, false) // An explicit zero is not an absent limit.
}

// Dispatch keeps the higher of the battery's and the running planner's
// soc_min. The planner's unset soc_min means its 10 % default.
func TestSoCMinReachesDispatch(t *testing.T) {
f := func(v float64) *float64 { return &v }
for _, tc := range []struct {
name string
battery *float64
planner *config.Planner
want float64
}{
{"no planner, no battery floor", nil, nil, 0},
{"planner off", nil, &config.Planner{SoCMin: 0.2}, 0},
{"planner default", nil, &config.Planner{Enabled: true}, 0.10},
{"planner set", nil, &config.Planner{Enabled: true, SoCMin: 0.15}, 0.15},
{"battery higher", f(0.25), &config.Planner{Enabled: true, SoCMin: 0.15}, 0.25},
{"planner higher", f(0.05), &config.Planner{Enabled: true, SoCMin: 0.15}, 0.15},
{"battery only", f(0.2), nil, 0.2},
} {
t.Run(tc.name, func(t *testing.T) {
cfg := parseBatteryLimitConfig(t, "", " max_charge_w: 5000\n")
cfg.Batteries = map[string]config.Battery{"battery": {SoCMin: tc.battery}}
got := driverLimitsFrom(cfg.ModbusControlDrivers(), cfg.Batteries, tc.planner)["battery"].SoCMin
if got != tc.want {
t.Fatalf("SoCMin = %v, want %v", got, tc.want)
}
})
}
}
13 changes: 13 additions & 0 deletions go/cmd/ftw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3663,11 +3663,20 @@ func driverCapacitiesFrom(drvList []config.Driver, loadpoints []config.Loadpoint

// driverLimitsFrom gives dispatch the same per-driver power limits and charge
// ceilings as the planner. Each battery's soc_max overrides the planner's.
// The SoC floor is the higher of the battery's and the running planner's
// soc_min, with the planner's 10 % default.
func driverLimitsFrom(drivers []config.Driver, batteries map[string]config.Battery, planner *config.Planner) map[string]control.PowerLimits {
ceiling := 1.0
if planner != nil && planner.SoCMax > 0 {
ceiling = planner.SoCMax
}
floor := 0.0
if planner != nil && planner.Enabled {
floor = planner.SoCMin
if floor <= 0 {
floor = 0.10
}
}
out := map[string]control.PowerLimits{}
for _, d := range drivers {
if !d.ObserveOnly {
Expand All @@ -3677,6 +3686,10 @@ func driverLimitsFrom(drivers []config.Driver, batteries map[string]config.Batte
limits.SoCMax = *b.SoCMax
limits.SoCMaxSet = true
}
limits.SoCMin = floor
if b := batteries[d.Name]; b.SoCMin != nil && *b.SoCMin > floor {
limits.SoCMin = *b.SoCMin
}
out[d.Name] = limits
}
}
Expand Down
Loading
Loading