diff --git a/.changeset/c6-idle-one-phase-start.md b/.changeset/c6-idle-one-phase-start.md new file mode 100644 index 000000000..226e1249e --- /dev/null +++ b/.changeset/c6-idle-one-phase-start.md @@ -0,0 +1,5 @@ +--- +"ftw": patch +--- + +Start Charge now on one phase once there is room for 6 A on that phase. An idle charger set to `1p` or `auto` on a three-phase site waited for room for the three-phase minimum (4,140 W) on a single phase, so it never started on a 16 A fuse and rarely on 25 A. It now waits for room for its own least order, 1,380 W. diff --git a/go/internal/control/ev_fuse_one_phase_start_test.go b/go/internal/control/ev_fuse_one_phase_start_test.go new file mode 100644 index 000000000..49a39ab6b --- /dev/null +++ b/go/internal/control/ev_fuse_one_phase_start_test.go @@ -0,0 +1,123 @@ +package control + +import ( + "testing" + "time" + + "github.com/srcfl/ftw/go/internal/loadpoint" +) + +// C6 (rig seeds 207534, 207536, 207537, 207531): an idle pool whose order +// lands on one phase needs room for 6 A on that phase, not for the +// configured three-phase minimum of 4,140 W. Without that, Charge now on 1p +// or auto never starts on a 16 A fuse ("below minimum step … fuse_cap_w=0 +// min_step_w=1380"). +func TestIdleOnePhasePoolStartsOnSixAmpsOfRoom(t *testing.T) { + steps := []float64{0, 1380, 1610, 1840, 2070, 2300, 2530, 2760, 2990, 3220, 3450, 3680, + 4140, 4830, 5520, 6210, 6900, 7590, 8280, 8970, 9660, 10350, 11040} + for _, tc := range []struct { + name string + fuseA float64 + houseA float64 + mode string + holdW float64 + }{ + {"16A 1p", 16, 4.5, "1p", 3680}, + {"25A 1p", 25, 13.7, "1p", 3680}, + {"16A auto", 16, 4.5, "auto", 3680}, + {"25A auto", 25, 13.7, "auto", 3680}, + } { + t.Run(tc.name, func(t *testing.T) { + cfg := loadpoint.Config{ID: "garage", DriverName: "easee", MinChargeW: 4140, MaxChargeW: 11040, + PhaseMode: "auto", AllowedStepsW: steps} + s := newPhaseSite(t, cfg, tc.houseA) + fuseW := tc.fuseA * 230 * 3 + s.state.SiteFuseAmps = tc.fuseA + s.ctrl.SetSiteFuse(loadpoint.SiteFuse{MaxAmps: tc.fuseA, Voltage: 230, PhaseCnt: 3}) + s.ctrl.SetFuseEVMax(func() (float64, bool) { + return EVFuseBudget(s.store, s.state, s.mgr.States(), s.ctrl.FuseConfigs(), fuseW) + }) + s.ctrl.SetManualHold(cfg.ID, loadpoint.ManualHold{PowerW: tc.holdW, PhaseMode: tc.mode, Persistent: true}) + start := s.now + deadline := start.Add(evRestartDwell + 5*time.Second) // the dwell plus one 5 s tick + for s.now.Before(deadline) && s.offerW < 1380 { + s.tick() + } + st, _ := s.mgr.State(cfg.ID) + if s.offerW < 1380 { + t.Fatalf("after %s: offer %.0f W, EV cap %.0f W, reason %q; want at least 1380 W", + s.now.Sub(start), s.offerW, s.state.evLimit.capW, st.CommandedReason) + } + t.Logf("started after %s at %.0f W on one phase", s.now.Sub(start), s.offerW) + if !s.offer1p { + t.Fatalf("offer %.0f W runs on three phases; want one", s.offerW) + } + for i := 0; i < 12; i++ { + s.tick() + if s.worstA() > tc.fuseA { + t.Fatalf("offer %.0f W puts %.1f A on a %.0f A fuse", s.offerW, s.worstA(), tc.fuseA) + } + } + }) + } +} + +// The start point is exact: on a 16 A fuse an idle 1p or auto pool starts at +// 1,380 W, its least order, once the worst phase leaves 6 A of room under the +// working line, and waits while it leaves 5.7 A. A hidden margin on the +// one-phase minimum would move the start and fail here. The cases are set +// from the working line as EVFuseBudget reports it, not from the constant +// that sets it, so they follow the line if it moves. +func TestIdleOnePhasePoolStartBoundary(t *testing.T) { + steps := []float64{0, 1380, 1610, 1840, 2070, 2300, 2530, 2760, 2990, 3220, 3450, 3680, + 4140, 4830, 5520, 6210, 6900, 7590, 8280, 8970, 9660, 10350, 11040} + const fuseA = 16.0 + site := func(t *testing.T, houseA float64, mode string) *phaseSite { + cfg := loadpoint.Config{ID: "garage", DriverName: "easee", MinChargeW: 4140, MaxChargeW: 11040, + PhaseMode: "auto", AllowedStepsW: steps} + s := newPhaseSite(t, cfg, houseA) + s.state.SiteFuseAmps = fuseA + s.ctrl.SetSiteFuse(loadpoint.SiteFuse{MaxAmps: fuseA, Voltage: 230, PhaseCnt: 3}) + s.ctrl.SetFuseEVMax(func() (float64, bool) { + return EVFuseBudget(s.store, s.state, s.mgr.States(), s.ctrl.FuseConfigs(), fuseA*230*3) + }) + s.ctrl.SetManualHold(cfg.ID, loadpoint.ManualHold{PowerW: 3680, PhaseMode: mode, Persistent: true}) + return s + } + // With no house load, an idle pool's room on its busiest phase is the + // whole working line. + probe := site(t, 0, "1p") + probe.tick() + lineA := probe.state.evLimit.phaseRoomA + if !probe.state.evLimit.phaseRoomKnown || lineA <= 6 || lineA > fuseA { + t.Fatalf("working line %.2f A (known %v) on a %.0f A fuse", lineA, probe.state.evLimit.phaseRoomKnown, fuseA) + } + for _, mode := range []string{"1p", "auto"} { + t.Run(mode+" 6.0 A of room starts", func(t *testing.T) { + s := site(t, lineA-6, mode) + start := s.now + for s.now.Sub(start) < evRestartDwell+5*time.Second && s.offerW == 0 { + s.tick() + } + if s.offerW != 1380 || !s.offer1p { + t.Fatalf("worst phase %.1f A: offer %.0f W, one phase %v; want 1380 W on one phase", + lineA-6, s.offerW, s.offer1p) + } + for i := 0; i < 60; i++ { + s.tick() + if s.worstA() > fuseA { + t.Fatalf("tick %d: %.2f A on a %.0f A fuse", i, s.worstA(), fuseA) + } + } + }) + t.Run(mode+" 5.7 A of room waits", func(t *testing.T) { + s := site(t, lineA-5.7, mode) + for i := 0; i < 40; i++ { + s.tick() + if s.offerW != 0 { + t.Fatalf("tick %d: offer %.0f W with 5.7 A of room; want 0", i, s.offerW) + } + } + }) + } +} diff --git a/go/internal/loadpoint/controller_fuse_budget.go b/go/internal/loadpoint/controller_fuse_budget.go index 9648db10c..477cc13f5 100644 --- a/go/internal/loadpoint/controller_fuse_budget.go +++ b/go/internal/loadpoint/controller_fuse_budget.go @@ -221,13 +221,16 @@ func (c *Controller) phaseRoomCapW(id, mode string, wantW, split, roomA float64) } // FuseConfigs returns the loadpoints with the phase mode each command names -// this tick. control.EVFuseBudget measures room on those phases, so an auto -// or 1p offer never gets three phases of room. Outside a tick, and for a -// loadpoint that gets no command, the configured mode stands. +// this tick, and the least each can order on those phases. +// control.EVFuseBudget measures room on those phases, so an auto or 1p offer +// never gets three phases of room, and an idle pool waits for room for that +// least order, not the configured three-phase minimum. Outside a tick, and +// for a loadpoint that gets no command, the configured mode stands. func (c *Controller) FuseConfigs() []Config { configs := c.manager.Configs() for i := range configs { if mode := c.tickChoices[configs[i].ID].phaseMode; mode != "" { + configs[i] = c.fuseConfig(configs[i], mode) configs[i].PhaseMode = mode } }