EV-20 rig round 2: a short charger read gap keeps the last reading; ha_signed pause timed from the meter age
A charger reading missing for less than stale_input_s keeps the last trusted reading in CarTracker (shared by Solar, Manual and the peak guard): no decision or write in that cycle, no stuck arm or clear. At stale_input_s the safe path is unchanged. This also stops the false PEAK_GUARD_FLOOR_LIMITED after one gap (EV-18 T10(b) updated). On ha_signed Solar's unknown-sun pause comes at meter age meter_max_age_s + ev_pause_min, checked every cycle. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
This commit is contained in:
@@ -502,4 +502,116 @@ for race in (True, False):
|
||||
nevers(r, f"C13 controller [race={race}]")
|
||||
|
||||
|
||||
# =========================================================================== #
|
||||
print("\n7. RIG ROUND 2: A SHORT CHARGER READ GAP; THE ha_signed PAUSE BY AGE")
|
||||
# =========================================================================== #
|
||||
# Full sun, Car first, charging 10 A from 120 s; the charger does not answer
|
||||
# for 1, 2 or 16 cycles at 600 s (Home Assistant shows it unavailable).
|
||||
def gap_run(n, beside=False):
|
||||
sim = SimCharger(setpoint_a=0)
|
||||
if beside:
|
||||
sim.lag_s = 1.0
|
||||
return S.drive(const(500.0), const(2900.0), dur=1100, first="car",
|
||||
socs={"a": 100.0, "b": 100.0}, sim=sim, beside=beside,
|
||||
events={600: lambda p, c: p.ch.go_unavailable(),
|
||||
600 + n: lambda p, c: p.ch.go_unavailable(False)})
|
||||
|
||||
|
||||
for n in (1, 2):
|
||||
for beside in (False, True):
|
||||
r = gap_run(n, beside)
|
||||
w = cur_writes(r)
|
||||
late = [(t, a) for t, a, _ in w if t >= 590]
|
||||
unk = [x["t"] for x in r["trace"] if 590 <= x["t"] < 1100
|
||||
and x["spare"] is None]
|
||||
check(f"read gap of {n} sample(s) at 600 s [beside={beside}]: no "
|
||||
f"write and no pause after it, the spare stays known (writes "
|
||||
f"from 590 s {late}, unknown {unk[:3]})",
|
||||
late == [] and unk == [] and r["sim"].power_w > 2000.0)
|
||||
nevers(r, f"read gap {n} [beside={beside}]")
|
||||
|
||||
# 16 s (>= stale_input_s): the safe path as before. The charger is taken as
|
||||
# gone; on its return Solar writes 0 A first (D2), then the start rule.
|
||||
r = gap_run(16)
|
||||
w = cur_writes(r)
|
||||
late = [(t, a) for t, a, _ in w if t >= 590]
|
||||
check(f"read gap of 16 s: the safe path, 0 A first on the return, then the "
|
||||
f"start rule ({late[:3]})",
|
||||
present(nth(late, 0)) and nth(late, 0)[1] == 0.0
|
||||
and 616 <= nth(late, 0)[0] <= 620 and present(nth(late, 1))
|
||||
and nth(late, 1)[1] > 0.0)
|
||||
|
||||
# The held figure neither arms nor clears the stuck check: a frozen reading
|
||||
# after an accepted write is still stuck, with a 2-sample gap inside the 60 s
|
||||
# (flagged at the first real reading at or after +60 s).
|
||||
tr = CH.CarTracker()
|
||||
for i in range(-5, 1):
|
||||
tr.observe(rd(), TS + i, UTC, DAY)
|
||||
tr.begin_write()
|
||||
tr.end_write(TS + 1)
|
||||
tr.note_write(TS, 10.0, 0.0, True)
|
||||
gone = CH.ChargerReading(why="no answer")
|
||||
st_at = None
|
||||
for i in range(1, 90):
|
||||
if i in (59, 60):
|
||||
tr.observe(gone, TS + i, UTC, DAY)
|
||||
else:
|
||||
tr.observe(rd(), TS + i, UTC, DAY)
|
||||
if st_at is None and tr.stuck(TS + i):
|
||||
st_at = i
|
||||
check(f"frozen reading with a 2-sample gap at +59/+60: still stuck, at the "
|
||||
f"first real reading after +60 (+{st_at})", st_at == 61)
|
||||
tr = CH.CarTracker()
|
||||
for i in range(-5, 1):
|
||||
tr.observe(rd(), TS + i, UTC, DAY)
|
||||
tr.begin_write()
|
||||
tr.end_write(TS + 1)
|
||||
tr.note_write(TS, 10.0, 0.0, True)
|
||||
for i in range(1, 70):
|
||||
tr.observe(rd(), TS + i, UTC, DAY)
|
||||
tr.observe(gone, TS + 70, UTC, DAY)
|
||||
check("a held gap does not clear a stuck verdict (+70 s gap, still stuck)",
|
||||
tr.stuck(TS + 70) and getattr(tr, "held", None) is True)
|
||||
|
||||
# ha_signed: the pause is timed from the meter's age (PM): unknown since the
|
||||
# age passed meter_max_age_s, so 0 A when the age reaches 330 s. A plan
|
||||
# stepped every 10 s (the rig's cycle) that notices the stale meter 7 s late
|
||||
# pauses at the first step at or after age 330 (bound: 330 + one cycle).
|
||||
plan = carmode.SolarPlan()
|
||||
plan.reset(1)
|
||||
kw = dict(n_now=1, auto=False, clamp=16.0, start_s=120.0, pause_s=300.0)
|
||||
t = 0.0
|
||||
while plan.a <= 0.0 and t < 400:
|
||||
plan.step(t, target_w=2900.0, **kw)
|
||||
t += 10.0
|
||||
age0 = t + 3.0 # the meter's last reading; the bound passes at +30
|
||||
paused_at = None
|
||||
while t < age0 + 400:
|
||||
age = t - age0
|
||||
over = max(0.0, age - 30.0)
|
||||
try:
|
||||
plan.step(t, target_w=None if age > 30.0 else 2900.0,
|
||||
unknown_s=over, **kw)
|
||||
except TypeError: # a build without the age rule
|
||||
plan.step(t, target_w=None if age > 30.0 else 2900.0, **kw)
|
||||
if plan.a == 0.0 and paused_at is None:
|
||||
paused_at = age
|
||||
break
|
||||
t += 10.0
|
||||
check(f"ha_signed pause by age, plan stepped every 10 s: 0 A at meter age "
|
||||
f"{paused_at} (330 <= age <= 340)",
|
||||
paused_at is not None and 330.0 <= paused_at <= 340.0)
|
||||
# The controller hands Solar that age: 40 s after the meter went silent at
|
||||
# 300 s, `unknown_s` is 10 (age 40 - 30).
|
||||
seen = {}
|
||||
r = S.drive(const(500.0), const(2900.0), dur=360, first="car",
|
||||
socs={"a": 100.0, "b": 100.0}, opts={"ev_phases": "1"},
|
||||
events={300: lambda p, c: setattr(p, "meter_on", False),
|
||||
340: lambda p, c: seen.update(
|
||||
u=getattr(c.car_sun_inputs(p.clock[0]),
|
||||
"unknown_s", None))})
|
||||
check(f"ha_signed: 40 s after the meter went silent Solar is told the sun "
|
||||
f"has been unknown for 10 s ({seen})",
|
||||
seen.get("u") is not None and 9.0 <= seen["u"] <= 12.0)
|
||||
|
||||
report()
|
||||
|
||||
Reference in New Issue
Block a user