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/ev-start-reads-the-meter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ftw": patch
---

A stopped car starts again once the meter has shown room on every phase for the usual restart wait. The start used to add its new current to the fuse heat left by the car's own earlier charging, and after a stop on a busy phase it waited over a minute and then started low. Now it reads each phase as it is, plus the car's new current. The heat holds a start back only while it is itself over the working limit, after a real overload.
6 changes: 4 additions & 2 deletions docs/safety.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ available battery energy and hardware power capability.
The EV hard limit treats the main fuse as heat, not as one reading. It
low-passes each phase's I² from the site meter with a 60 s time constant.
A phase over the fuse less 1 A cuts the EVs once that filtered current
passes the same limit, and at once above 1.2 × the fuse. A rise or start
reads the higher of the reading and that filtered current. Where the meter
passes the same limit, and at once above 1.2 × the fuse. A running car's
rise reads the higher of the reading and that filtered current. An idle
car's start reads each phase as it is, plus its new current; the filtered
current holds it back only while it is over the limit. Where the meter
reports phase currents, they replace total import as the EVs' fuse check; a
tariff import ceiling still applies.

Expand Down
21 changes: 15 additions & 6 deletions go/internal/control/ev_fuse_budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ func (s *State) offerPhaseA(w float64, phases int) (float64, int) {
// EVFusePhaseRoomA is the current the chargers may still add on the
// busiest phase: below the fuse less its margin, the last reading's
// current or heat, and every charger's offers that reading may not show.
// false when the site meter reports no phase currents.
// For an idle pool the heat counts only over the working limit, as the
// start reads it. false when the site meter reports no phase currents.
func EVFusePhaseRoomA(state *State) (float64, bool) {
if state == nil || !state.evLimit.set || !state.evLimit.phaseRoomKnown {
return 0, false
Expand All @@ -313,7 +314,7 @@ type evMeterLimit struct {
readingAt time.Time // newest site reading seen
roomSince time.Time // first reading of the current run with room to start
offers map[string]chargerOffers // each plugged charger's, by loadpoint
phaseRoomA float64 // below the working limit on the busiest phase at readingAt
phaseRoomA float64 // below the working limit on the busiest phase at readingAt; an idle pool's as a start reads it
phaseRoomKnown bool // the meter reports phase currents
overSince time.Time // first reading of a run over the hour's import limit
fuseOverAt time.Time // first reading of a run with a phase, or the total, over the fuse's working limit
Expand Down Expand Up @@ -399,6 +400,9 @@ func (s *State) stepEVMeterLimit(meter *telemetry.DerReading, gridW float64, poo
lim.phaseRoomA, lim.phaseRoomKnown = 0, r.phaseRoomKnown
if fresh {
lim.phaseRoomA = r.phaseRoomA
if pool.offerW <= 0 {
lim.phaseRoomA = r.startRoomA // The split between idle cars reads the start's room.
}
}
step := evPhaseMarginA * s.SiteFuseVoltage * pool.phases
// The label follows whichever limit leaves less room.
Expand Down Expand Up @@ -496,13 +500,14 @@ func (s *State) stepEVMeterLimit(meter *telemetry.DerReading, gridW float64, poo
func (s *State) stepEVIdleStart(r evMeterRoom, gridW float64, pool evPool, first, gap, fresh bool, at, prevAt time.Time, pending, step float64) {
lim := &s.evLimit
lim.capW = 0
perReadingW := r.fuseW
perReadingW := r.startW
if !r.hourly {
perReadingW = math.Min(perReadingW, r.riseW)
lim.byImport = r.riseW < r.startW
} else {
// The start test below holds an idle car to the start level:
// name it by this reading.
lim.byImport = r.startLevelW-gridW-pending < r.fuseW
lim.byImport = r.startLevelW-gridW-pending < r.startW
}
room := 0.0
if fresh {
Expand Down Expand Up @@ -550,7 +555,7 @@ func EVLimitReason(state *State) string {
// evMeterRoom is the measured room in EV watts. The fuse's part holds on
// every reading. The import ceiling's parts are +Inf while it is off.
type evMeterRoom struct {
fuseW float64 // below the fuse less its margin and the worst phase, read or heat, and what we sent; rises and starts
fuseW float64 // below the fuse less its margin and the worst phase, read or heat, and what we sent; rises
fuseOverW float64 // the fuse's measured overage that cuts now, 0 under it; see fuseHeat
fuseOverA float64 // the same on the worst phase, with perPhase
perPhase bool // the phase currents measure the fuse
Expand All @@ -563,11 +568,13 @@ type evMeterRoom struct {
worstA float64
phaseRoomA float64 // below the working limit on the busiest phase, read or heat
phaseRoomKnown bool // the meter reports phase currents
startW float64 // fuseW for an idle start: the worst phase read, its heat only over the working limit (startLevelA)
startRoomA float64 // phaseRoomA the same way
}

func (s *State) evMeterRoom(meter *telemetry.DerReading, gridW, phases, fuseMaxW float64, sent pendingLoad) evMeterRoom {
inf, totalW := math.Inf(1), math.Max(0, fuseMaxW-s.fuseSafetyMarginW())-gridW
r := evMeterRoom{fuseW: totalW - sent.w, fuseOverW: math.Max(0, -totalW), overLimit: totalW < 0, limitW: inf, riseW: inf, startLevelW: inf}
r := evMeterRoom{fuseW: totalW - sent.w, startW: totalW - sent.w, fuseOverW: math.Max(0, -totalW), overLimit: totalW < 0, limitW: inf, riseW: inf, startLevelW: inf}
if limitW, riseW, ok := s.importHourLimitsW(); ok {
r.limitW, r.riseW = limitW-gridW, riseW-gridW-sent.w
// The ceiling caps the hour's mean, so an idle car may start on the
Expand All @@ -592,6 +599,8 @@ func (s *State) evMeterRoom(meter *telemetry.DerReading, gridW, phases, fuseMaxW
}
r.fuseW = math.Min(r.fuseW, (limitA-s.fuseHeat.levelA(amps, sent.phaseA))*s.SiteFuseVoltage*phases)
r.phaseRoomA, r.phaseRoomKnown = limitA-s.fuseHeat.levelA(amps, [3]float64{}), true
r.startW = math.Min(r.startW, (limitA-s.fuseHeat.startLevelA(amps, sent.phaseA, limitA))*s.SiteFuseVoltage*phases)
r.startRoomA = limitA - s.fuseHeat.startLevelA(amps, [3]float64{}, limitA)
// The phases measure the fuse itself; total import stands in only without them.
r.fuseOverA = s.fuseHeat.overA(amps, limitA, fuseInstantFactor*s.SiteFuseAmps)
r.fuseOverW, r.perPhase, r.overLimit = r.fuseOverA*s.SiteFuseVoltage*phases, true, r.worstA > limitA
Expand Down
78 changes: 78 additions & 0 deletions go/internal/control/ev_fuse_idle_start_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package control

import (
"testing"
"time"

"github.com/srcfl/ftw/go/internal/loadpoint"
)

// firstOfferSince is the first order above 0 W from at on, and when it was
// sent; zero time when none was.
func (s *evMeterSite) firstOfferSince(at time.Time) evTimed {
for _, o := range s.offersSince(at) {
if o.w > 0 {
return o
}
}
return evTimed{}
}

// The home box on 25 Oct 2026: the car ran for minutes at the busy phase's
// working limit (17.9 of 19 A there; 22.9 of 24 A on this 25 A site), then
// stopped. Its next start read the heat its own current had left on top of
// the start it asked for: the cap stayed at 0 for 84 s, then gave 9 A. A
// start reads the phases now plus the car's new current; the heat, under the
// working limit, does not hold it back.
func TestEVIdleStartReadsThePhasesNotTheCarsOwnHeat(t *testing.T) {
s := newEVMeterSite(t, 0, 0)
s.housePhaseA, s.houseW = [3]float64{8.9, 2, 2}, (8.9+2+2)*230
s.run(10 * time.Minute)
if s.offer() != 9660 || s.evW != 9660 {
t.Fatalf("setup: offer %.0f, draw %.0f W, want 14 A on L1's working limit", s.offer(), s.evW)
}
s.ctrl.SetManualHold("garage", loadpoint.ManualHold{PowerW: 0, PhaseMode: "3p", Persistent: true})
s.run(20 * time.Second)
if s.evW != 0 {
t.Fatalf("setup: the car still draws %.0f W after the stop", s.evW)
}
askedAt := s.now
s.ctrl.SetManualHold("garage", loadpoint.ManualHold{PowerW: 10350, PhaseMode: "3p", Persistent: true})
s.run(2 * time.Minute)
start := s.firstOfferSince(askedAt)
if start.at.IsZero() {
t.Fatalf("no start within 2 min, L1 at %.1f A: offers %v", s.phaseA()[0], offerWatts(s.offersSince(askedAt)))
}
// The 35 s restart dwell runs from the car's stop, 15 s before the ask.
if wait := start.at.Sub(askedAt); wait > 25*time.Second || start.w < 8970 {
t.Fatalf("start %.0f W after %v with L1 at 8.9 A and 24 A to the working limit", start.w, wait)
} else {
t.Logf("start %.0f W after %v", start.w, wait)
}
}

// A real overage on the busy phase heats the fuse past the working limit.
// When the house load drops, the start still waits for the heat filter to
// cool under the limit, and only then for the restart dwell.
func TestEVIdleStartWaitsForTheHeatOfARealOverage(t *testing.T) {
s := newEVMeterSite(t, 0, 0)
s.housePhaseA, s.houseW = [3]float64{26, 2, 2}, (26+2+2)*230
s.run(5 * time.Minute)
if s.offer() != 0 {
t.Fatalf("setup: the car started at %.0f W with L1 at 26 A", s.offer())
}
droppedAt := s.now
s.housePhaseA, s.houseW = [3]float64{8, 2, 2}, (8+2+2)*230
s.run(3 * time.Minute)
start := s.firstOfferSince(droppedAt)
if start.at.IsZero() {
t.Fatalf("no start within 3 min of the drop: offers %v", offerWatts(s.offersSince(droppedAt)))
}
// L1's filtered current stays over 24 A for about 11 s after the drop;
// the dwell starts only then.
if wait := start.at.Sub(droppedAt); wait < evRestartDwell+10*time.Second {
t.Fatalf("started %.0f W %v after the drop, before the heat of a 26 A overage had cooled", start.w, wait)
} else {
t.Logf("start %.0f W after %v", start.w, wait)
}
}
22 changes: 20 additions & 2 deletions go/internal/control/fuse_heat.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ func (h *fuseHeat) overA(amps []float64, limitA, instantA float64) float64 {

// levelA is the highest phase current, taking each phase at the higher of
// the reading and its heat, plus what we sent that it may not show yet.
// Rises and starts read it, so a rise never spends heat the last minute has
// already used, nor room an earlier rise will take.
// A running pool's rises read it, so a rise never spends heat the last
// minute has already used, nor room an earlier rise will take. An idle
// start reads startLevelA.
func (h *fuseHeat) levelA(amps []float64, pendingA [3]float64) float64 {
level := 0.0
for i, a := range amps {
Expand All @@ -83,6 +84,23 @@ func (h *fuseHeat) levelA(amps []float64, pendingA [3]float64) float64 {
return level
}

// startLevelA is the highest phase current as an idle start reads it: the
// reading plus what we sent that it may not show yet. A phase's heat counts
// only while it is over limitA, so a car that just stopped is not counted
// twice, in its heat and in the start it asks for, while a real overage
// still blocks the start until the filter has cooled under the limit.
func (h *fuseHeat) startLevelA(amps []float64, pendingA [3]float64, limitA float64) float64 {
level := 0.0
for i, a := range amps {
a += pendingA[i]
if h.sq[i] > limitA*limitA { // As overA reads it.
a = math.Max(a, math.Sqrt(h.sq[i])+pendingA[i])
}
level = math.Max(level, a)
}
return level
}

// worstA is the highest filtered phase current.
func (h *fuseHeat) worstA() float64 {
return math.Sqrt(max(h.sq[0], h.sq[1], h.sq[2]))
Expand Down
30 changes: 30 additions & 0 deletions go/internal/control/fuse_heat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,33 @@ func TestEVHardLimitHoldsWhenTotalImportDisagreesWithPhases(t *testing.T) {
t.Fatalf("without phase currents 19,174 W gave %.1f W, want 10,350 - 2,269 = 8,081 W", capW)
}
}

// An idle start reads each phase as it is, plus our orders the reading may
// not show; a phase's heat counts only while it is over the working limit.
func TestStartLevelReadsHeatOnlyOverTheLimit(t *testing.T) {
const limitA = 24
for _, tc := range []struct {
name string
heatA [3]float64
amps []float64
pending [3]float64
want float64
}{
{"heat under the limit", [3]float64{23.9, 2, 2}, []float64{8, 2, 2}, [3]float64{}, 8},
{"heat under the limit, an order on its way", [3]float64{23.9, 2, 2}, []float64{8, 2, 2}, [3]float64{3, 3, 3}, 11},
{"heat over the limit", [3]float64{24.5, 2, 2}, []float64{8, 2, 2}, [3]float64{}, 24.5},
{"heat over the limit, an order on its way", [3]float64{24.5, 2, 2}, []float64{8, 2, 2}, [3]float64{1, 1, 1}, 25.5},
{"heat over on L2, the reading highest on L1", [3]float64{10, 24.2, 2}, []float64{12, 3, 2}, [3]float64{}, 24.2},
{"one phase", [3]float64{23, 0, 0}, []float64{9}, [3]float64{}, 9},
} {
t.Run(tc.name, func(t *testing.T) {
h := fuseHeat{set: true}
for i, a := range tc.heatA {
h.sq[i] = a * a
}
if got := h.startLevelA(tc.amps, tc.pending, limitA); math.Abs(got-tc.want) > 1e-9 {
t.Fatalf("start level %.3f A, want %.3f A", got, tc.want)
}
})
}
}
19 changes: 10 additions & 9 deletions go/internal/control/sitesim_property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ import (
"slices"
"testing"
"time"

"github.com/srcfl/ftw/go/internal/sitesim"
)

// randomHouseKnown names the seeds that break an invariant on master, by
// kind, and the finding. A listed kind that passes fails the test until its
// line goes. The fuse's own kind is never listed.
var randomHouseKnown = map[uint64]map[string]string{
// 25 A, 40 s charger, no declared response time (Core assumes 180 s). L2
// steps to 30.8 A with the car at 8 A; a cut of 5 A a phase that landed
// 94 s earlier, in the same run over the limit, still counts as on its
// way, so Core cuts to 6 A, not 0, and L2 holds 28.8 A for another 40 s.
2: {failLimit: "netting: a landed cut still covers the next overage, ev_fuse_budget.go:436"},
}
// line goes. The fuse's own kind is never listed. Seed 2 no longer reaches
// the case where a landed cut still covers the next overage; that cost is
// pinned in TestEVFuseLandedCutCoversOnlyItsRun.
var randomHouseKnown = map[uint64]map[string]string{}

// Core keeps a random house under the fuse. For each fixed seed the house
// load on each phase steps at random to anywhere up to the fuse less 2 A,
Expand Down Expand Up @@ -64,8 +62,11 @@ func TestSiteSimRandomHouse(t *testing.T) {
}
damage = max(damage, p.Fuse.Damage[0], p.Fuse.Damage[1], p.Fuse.Damage[2])
if !p.Now.Before(at) {
// Set after this second's control tick, the load flows from
// the next plant second: a start Core sent this second came
// first.
a, at = house(), next()
p.HouseW, s.outsideAt = houseA(a[0], a[1], a[2]), p.Now
p.HouseW, s.outsideAt = houseA(a[0], a[1], a[2]), p.Now.Add(sitesim.Step)
steps++
}
}
Expand Down
1 change: 1 addition & 0 deletions go/internal/control/testdata/sitesim_field_known.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
pr1763/25A/3p/3p-15A/cloud60s/car3p/6-2-2/chargenow+battery own-raise relief
pr1763/25A/3p/3p-15A/cloud60s/car3p/6-2-2/pause+battery own-raise relief
pr1763/25A/3p/3p-15A/easee120s/car3p/6-2-2/chargenow+battery own-raise relief
pr1763/25A/3p/3p-15A/easee120s/car3p/6-2-2/pause+battery own-raise relief
pr1763/25A/3p/3p-15A/easee40s/car3p/6-2-2/chargenow+battery own-raise relief
pr1763/25A/3p/3p-15A/easee40s/car3p/6-2-2/pause+battery own-raise relief
pr1763/25A/3p/3p-15A/fast2s/car3p/6-2-2/pause+battery own-raise relief
Expand Down
Loading