EV-20 rig round 1: stuck check clears on the car's answer or a paused car; EV-36 first-sample rule
An accepted write keeps the car's power from the reading before the send (begin_write); a later reading whose power differs from it, or that shows a paused car (not charging, under PAUSED_W), clears the armed check. A refused write's first sample after the send is not life by itself (EV-36). EV-13 T7/T8 and the refusal-window row get two-change variants so mutant M3 stays killed. DECISIONS records the arming rule. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
This commit is contained in:
@@ -108,3 +108,32 @@ one small set of facts and derives every path from them:
|
||||
bookkeeping (a 0 A not read back counts) or by the read-back showing a value
|
||||
it sent, confirmed, tried or saw at a refused try.
|
||||
- **C3** is T43-T45; **C7** is EV-22's.
|
||||
|
||||
## Rig round 1 (rig FAIL on cc8c0dc), with EV-32 and EV-36
|
||||
|
||||
- **The stuck-reading check (chargers.py `CarTracker`), for every writer.**
|
||||
- Arms: an accepted write that moved the setpoint by `STUCK_MIN_A` arms at
|
||||
its send (`armed_at`), on the signature (power, read-back) the tracker
|
||||
holds at `note_write`, as before (EV-04). It also keeps
|
||||
`armed_pre_w`: the car's power in the latest reading taken BEFORE the
|
||||
send (`begin_write`).
|
||||
- Clears: any later reading whose signature differs from the armed one; or
|
||||
(new) whose power differs from `armed_pre_w` (the car answered the write,
|
||||
even when that reading came while the write waited, which was the rig's
|
||||
race); or (new) that shows a paused car (not charging, under
|
||||
`PAUSED_W` 100 W), where constant values are expected.
|
||||
- Stuck: armed and not cleared for `STUCK_S` (60 s).
|
||||
- A refused write (EV-13) arms only with no life in `TOOK_S` after the
|
||||
send. EV-36: the first sample after the send is not life by itself (it may
|
||||
be a value newer than the cycle's last read and frozen since); life is a
|
||||
later sample that differs from the samples before the send AND from that
|
||||
first one.
|
||||
- **No amp ping-pong:** after a step down, a step back up needs
|
||||
`UP_HYST_W` (100 W) past the amp boundary.
|
||||
- **The meter's age:** Solar's own `stale_input_s` gate applies where the age
|
||||
measures arrival (HomeWizard local, MQTT, DSMR). On `ha_signed` the age is
|
||||
the time since the value changed (Home Assistant publishes changes only), so
|
||||
a healthy meter at a flat load would read as stale; there the source's own
|
||||
`meter_max_age_s` is the bound (a silent meter: 0 A at
|
||||
`meter_max_age_s` + `ev_pause_min`).
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ TOOK_S = 10.0 # a write is "taken" when the read-back follows by t
|
||||
TOOK_TOL_A = 0.5 # ... to within this
|
||||
STUCK_S = 60.0 # EV-04: power and read-back unchanged after a write
|
||||
STUCK_MIN_A = 1.0 # ... that moved the setpoint by at least this
|
||||
PAUSED_W = 100.0 # EV-20: a car not charging, under this, is paused
|
||||
LIFE_KEEP_S = 40.0 # EV-13: samples kept to date a refused write's life
|
||||
OWN_WRITE_MUTE_S = 15.0 # the tracker's two-writer detector ignores our own
|
||||
# Volts used to bound a car figure by what the read-back allows (a physical
|
||||
@@ -716,9 +717,10 @@ class CarTracker:
|
||||
# EV-04: our own writes, and the stuck-reading rule (SAFETY-37's shape)
|
||||
mute_until: float = 0.0
|
||||
# EV-20 rig round 1: the signature of the latest reading taken BEFORE our
|
||||
# write went out, kept at `begin_write` (the arming baseline). The empty
|
||||
# tuple means "no write begun", and `note_write` then uses `sig`.
|
||||
# write went out, kept at `begin_write`; `armed_pre_w` is its power, kept
|
||||
# while the check is armed. Empty / None: no write begun or not armed.
|
||||
pre_sig: tuple = ()
|
||||
armed_pre_w: float | None = None
|
||||
armed_at: float | None = None
|
||||
armed_sig: tuple | None = None
|
||||
sig: tuple | None = None
|
||||
@@ -788,11 +790,10 @@ class CarTracker:
|
||||
tracker before `note_write` runs (the write waits for it), so the mute
|
||||
is open until `end_write`.
|
||||
|
||||
EV-20 (rig round 1, EV-32): the stuck check's baseline is taken HERE,
|
||||
before the send. The write waits for its read-back and the cycle reads
|
||||
the charger meanwhile, so by `note_write` `sig` can already be the
|
||||
reading AFTER the write; armed on that, a car that then stays paused
|
||||
(constant power and read-back) was called stuck 60 s later."""
|
||||
EV-20 (rig round 1, EV-32): the power of the reading before the send is
|
||||
kept HERE. The write waits for its read-back and the cycle reads the
|
||||
charger meanwhile, so the reading the check is armed on can already
|
||||
show the car's answer; the power before the send tells it."""
|
||||
self.mute_until = float("inf")
|
||||
self.pre_sig = (self.sig,)
|
||||
|
||||
@@ -816,9 +817,7 @@ class CarTracker:
|
||||
plainly alive is not a stuck reading. `polls` are the samples the
|
||||
write itself saw while it waited, `[(time, ChargerReading)]`."""
|
||||
self.mute_until = now + OWN_WRITE_MUTE_S
|
||||
# The baseline: the reading before the send (`begin_write`), never one
|
||||
# that arrived while the write waited.
|
||||
base = self.pre_sig[0] if self.pre_sig else self.sig
|
||||
pre = self.pre_sig[0] if self.pre_sig else None
|
||||
self.pre_sig = ()
|
||||
try:
|
||||
moved = was_a is None or abs(float(to_a) - float(was_a)) \
|
||||
@@ -831,13 +830,17 @@ class CarTracker:
|
||||
return
|
||||
if ok:
|
||||
self._pend = None
|
||||
self.armed_at, self.armed_sig = now, base
|
||||
self.armed_at, self.armed_sig = now, self.sig
|
||||
# EV-20 rig round 1: the car's power before the send. A power
|
||||
# that has moved from it is the car's answer (alive), however
|
||||
# early that reading came (it may be the one `sig` holds).
|
||||
self.armed_pre_w = None if pre is None else pre[0]
|
||||
return
|
||||
if self._pend is not None:
|
||||
return # an earlier refusal's window
|
||||
before = [x for x in self._ring if x[0] <= now]
|
||||
pre = [max(before, key=lambda x: x[0])[1]] if before else []
|
||||
self._pend = {"t": now, "pre": pre, "sig": base, "post0": False}
|
||||
self._pend = {"t": now, "pre": pre, "sig": self.sig, "first": None}
|
||||
later = [(t, _life_vals(r)) for t, r in polls]
|
||||
later += [(t, v) for t, v in self._ring if t > now]
|
||||
for t, v in sorted(later, key=lambda x: x[0]):
|
||||
@@ -859,13 +862,13 @@ class CarTracker:
|
||||
return
|
||||
if t <= p["t"]:
|
||||
p["pre"] = (p["pre"] + [vals])[-8:] # taken before the send
|
||||
elif not p.get("post0", True):
|
||||
elif p.get("first") is None:
|
||||
# EV-36 (SPIKE-05 C4): the first sample after the send may carry a
|
||||
# value newer than the cycle's last read but frozen since; it is
|
||||
# the baseline, and life must show in a sample after it.
|
||||
p["post0"] = True
|
||||
p["pre"] = (p["pre"] + [vals])[-8:]
|
||||
elif t <= p["t"] + TOOK_S and _alive(vals, p["pre"]):
|
||||
# not life by itself, and life must differ from it as well.
|
||||
p["first"] = vals
|
||||
elif t <= p["t"] + TOOK_S and _alive(vals, p["pre"]) \
|
||||
and _alive(vals, [p["first"]]):
|
||||
self._pend = None # life: nothing to arm
|
||||
return
|
||||
if max(t, arrival) > p["t"] + TOOK_S:
|
||||
@@ -883,12 +886,23 @@ class CarTracker:
|
||||
p, self._pend = self._pend, None
|
||||
if p is not None and self.armed_at is None:
|
||||
self.armed_at, self.armed_sig = p["t"], p["sig"]
|
||||
self.armed_pre_w = None # a refusal: no answer to look for
|
||||
|
||||
def _sig(self, r, now: float) -> None:
|
||||
sig = (r.power_w, r.allowed_a)
|
||||
if self.armed_at is not None and self.armed_sig is not None \
|
||||
and sig != self.armed_sig:
|
||||
# EV-20 rig round 1: after an accepted write the car's power moved
|
||||
# from its value before the send (the car answered), or the car is
|
||||
# paused (not charging, under QUIET_W): constant values are expected
|
||||
# then, so neither is a stuck reading.
|
||||
answered = (self.armed_pre_w is not None and r.power_w is not None
|
||||
and r.power_w != self.armed_pre_w)
|
||||
paused = (self.armed_pre_w is not None and r.charging is False
|
||||
and r.power_w is not None and r.power_w < PAUSED_W)
|
||||
if self.armed_at is not None and (
|
||||
answered or paused or (self.armed_sig is not None
|
||||
and sig != self.armed_sig)):
|
||||
self.armed_at = self.armed_sig = None # it moved: alive
|
||||
self.armed_pre_w = None
|
||||
self.stuck_now = False
|
||||
elif self.armed_at is not None and self.armed_sig is None:
|
||||
self.armed_sig = sig
|
||||
|
||||
@@ -205,6 +205,19 @@ for what, e in (("the same values", 1.000), ("changed values", 1.010)):
|
||||
tl = [(TS + s, rd(e=e, taken=TS - 1.0)) for s in range(1, 131)]
|
||||
armed(f"T7 stale sample ({what}, taken-at TS-1 again and again)", tl)
|
||||
|
||||
# EV-20 rig round 1 (EV-36): one changed sample after the send is not life by
|
||||
# itself, so these variants change twice. Every sample is still TAKEN before
|
||||
# the send (TS-1), so the correct tracker sees no life and arms; one that dates
|
||||
# samples by arrival (mutant M3) sees life.
|
||||
tl2 = [(TS + s, rd(e=1.010 if s < 3 else 1.020, taken=TS - 1.0))
|
||||
for s in range(1, 131)]
|
||||
armed("T7 stale samples, two changed values (taken-at TS-1 again and again)",
|
||||
tl2)
|
||||
late2 = [(TS + s, rd(e=1.010 if s < 3 else 1.020, taken=TS - 1.0)
|
||||
if s <= 3 else rd(e=1.020)) for s in range(2, 131)]
|
||||
armed("T8 samples taken at TS-1 (+10, then +20 Wh) arrive at TS+2 and TS+3, "
|
||||
"nothing changes after them", late2, pre_end=-3)
|
||||
|
||||
# T8: the late pre-write sample (EV-12 ordering): taken TS-1, arrives TS+2
|
||||
late = [(TS + s, rd(e=1.010, taken=TS - 1.0) if s == 2 else rd(e=1.010))
|
||||
for s in range(2, 131)]
|
||||
@@ -265,8 +278,11 @@ tr = CH.CarTracker()
|
||||
for i in range(-5, 1):
|
||||
tr.observe(rd(), TS + i, UTC, DAY)
|
||||
tr.note_write(TS, 16, 10, False)
|
||||
# EV-36 (SPIKE-05 C4): life shows after the first sample past the send (one
|
||||
# changed sample that then stands may be a frozen newer value), so the energy
|
||||
# moves twice here.
|
||||
for i in range(1, 5):
|
||||
tr.observe(rd(e=1.010), TS + i, UTC, DAY)
|
||||
tr.observe(rd(e=1.010 if i < 3 else 1.020), TS + i, UTC, DAY)
|
||||
tr.note_write(TS + 20, 10, 8, False)
|
||||
check("a refusal that showed life leaves no window; a later refusal gets "
|
||||
"its own", pend(tr) is not None and pend(tr)["t"] == TS + 20
|
||||
|
||||
@@ -134,6 +134,12 @@ print("\n3. THE REAL CONTROLLER IN THE RIG'S INTERLEAVE (beside)")
|
||||
# =========================================================================== #
|
||||
|
||||
|
||||
def jit(f):
|
||||
"""A few watts of noise on a plant figure, as the rig's plant had, so a
|
||||
meter published on change does change (every 7 s here)."""
|
||||
return lambda t: f(t) + (2.0 if int(t // 7) % 2 else -2.0)
|
||||
|
||||
|
||||
def rig_run(**kw):
|
||||
sim = kw.pop("sim", None) or SimCharger(setpoint_a=kw.pop("setpoint", 0))
|
||||
sim.lag_s = 1.0
|
||||
@@ -146,7 +152,8 @@ def rig_run(**kw):
|
||||
# scenario 2): 0 A first (D2), then the start rule, then charging to the end.
|
||||
for mc in (False, True):
|
||||
tag = "meter on change" if mc else "meter every second"
|
||||
r = rig_run(house=const(900.0), sun=const(7900.0), dur=1800, first="car",
|
||||
r = rig_run(house=jit(const(900.0)), sun=const(7900.0), dur=1800,
|
||||
first="car",
|
||||
socs={"a": 71.0, "b": 100.0},
|
||||
sim=SimCharger(setpoint_a=10), meter_change=mc)
|
||||
w = cur_writes(r)
|
||||
@@ -188,11 +195,11 @@ for ph, sun_w, amps in ((1, 2900.0, 10.0), (3, 600.0 + 6900.0, 10.0)):
|
||||
f"({changes} changes: {w[:6]})", present(nth(w, 0)) and changes <= 1)
|
||||
nevers(r, f"ping-pong [{ph} phase]")
|
||||
# A real rise after a step down still raises the current.
|
||||
r = S.drive(const(500.0), step_fn((300, 2890.0), (600, 3200.0), base=2900.0),
|
||||
r = S.drive(const(500.0), step_fn((300, 2890.0), (600, 3300.0), base=2900.0),
|
||||
dur=900, first="car", socs={"a": 100.0, "b": 100.0},
|
||||
opts={"ev_phases": "1"})
|
||||
w = [(t, a) for t, a, _ in cur_writes(r)]
|
||||
check(f"guard: 10 A, down to 9 A on a 10 W dip, then a real rise to 11 A "
|
||||
check(f"guard: 10 A, down to 9 A on a 10 W dip, then a real rise to 11.3 A "
|
||||
f"worth: 11 A is written ({w})",
|
||||
[a for _, a in w] == [10.0, 9.0, 11.0])
|
||||
|
||||
@@ -206,7 +213,7 @@ for mode, kw in (("every second", {}), ("rig interleave, meter on change",
|
||||
if kw.get("beside"):
|
||||
sim.lag_s = 1.0
|
||||
# 1 phase: a 290 s cloud never pauses; a 400 s one pauses at 300 s.
|
||||
r = S.drive(const(500.0), lambda t: 900.0 if 400 <= t < 690
|
||||
r = S.drive(jit(const(500.0)), lambda t: 900.0 if 400 <= t < 690
|
||||
or 1200 <= t < 1600 else 2900.0, dur=1800, first="car",
|
||||
socs={"a": 100.0, "b": 100.0}, opts={"ev_phases": "1"},
|
||||
sim=sim, **kw)
|
||||
@@ -223,8 +230,8 @@ for mode, kw in (("every second", {}), ("rig interleave, meter on change",
|
||||
sim.lag_s = 1.0
|
||||
# 3 phases: 7 A, then the spare under 6 A worth from 600 s: 6 A, 0 A at
|
||||
# 900 s (+2), not before.
|
||||
r = S.drive(const(500.0), step_fn((600, 600.0 + 2500.0),
|
||||
base=600.0 + 6000.0),
|
||||
r = S.drive(jit(const(500.0)), step_fn((600, 600.0 + 2500.0),
|
||||
base=600.0 + 6000.0),
|
||||
dur=1100, first="car", socs={"a": 100.0, "b": 100.0},
|
||||
opts={"ev_phases": "3"}, phases=3, sim=sim, **kw)
|
||||
w = [(t, a) for t, a, _ in cur_writes(r)]
|
||||
@@ -236,17 +243,21 @@ for mode, kw in (("every second", {}), ("rig interleave, meter on change",
|
||||
nevers(r, f"hold [3 phases, {mode}]")
|
||||
|
||||
# A healthy meter on ha_signed: Home Assistant publishes it only on a change,
|
||||
# so at a flat load the value may stand 20-40 s; the car is not paused.
|
||||
r = S.drive(const(500.0), lambda t: 2900.0 + (15.0 if int(t // 40) % 2
|
||||
# so at a flat load the value may stand longer than stale_input_s (15 s); here
|
||||
# 25 s at a time, under the source's meter_max_age_s (30 s). The spare stays
|
||||
# known and the car is not paused.
|
||||
r = S.drive(const(500.0), lambda t: 2900.0 + (15.0 if int(t // 25) % 2
|
||||
else 0.0),
|
||||
dur=1200, first="car", socs={"a": 100.0, "b": 100.0},
|
||||
opts={"ev_phases": "1"}, meter_change=True)
|
||||
w = cur_writes(r)
|
||||
unk = [x["t"] for x in r["trace"] if x["spare"] is None and x["t"] > 5]
|
||||
check(f"ha_signed, a healthy meter whose value stands 40 s at a time: the "
|
||||
f"spare stays known and the car is never paused ({w}, unknown "
|
||||
f"{unk[:3]})", not [x for x in w if x[1] == 0.0 and x[0] > 5]
|
||||
and not unk)
|
||||
check(f"ha_signed, a healthy meter whose value stands 25 s at a time: the "
|
||||
f"spare stays known, the car starts by the start rule and is never "
|
||||
f"paused ({w}, unknown {unk[:3]})",
|
||||
not [x for x in w if x[1] == 0.0 and x[0] > 5] and not unk
|
||||
and present(nth(w, 0)) and nth(w, 0)[1] > 0.0
|
||||
and nth(w, 0)[0] <= 125)
|
||||
# A silent meter on ha_signed: unknown from the source's own meter_max_age_s
|
||||
# (30 s), then 0 A after ev_pause_min (300 s).
|
||||
r = S.drive(const(500.0), const(2900.0), dur=900, first="car",
|
||||
|
||||
Reference in New Issue
Block a user