From 82dc77df6279f908865e9e23d522268670a79027 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 17:03:18 +0100 Subject: [PATCH] EV-20 SPIKE-06 round: arm the stuck check on the pre-send reading; Solar restarts after its own 0 A under a stuck verdict SPIKE-06 option 2 (PM decision). The stuck check's baseline is the reading before the send, for accepted and refused writes; it clears on any change from it (3a17012's power rules removed), so the race cannot arm it (C10, C11, C13). Frozen power under an accepted write is left to the energy meter and the read-back cap (EV-13 T14/T17/T18 changed). Once Solar's own 0 A stands, a stuck verdict no longer blocks the start rule (C12), at most MAX_TRIES starts per verdict, then CHARGER_REFUSED until Solar is pressed. Rows in test_ev20_rig.py section 6. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w --- .../DECISIONS/EV-20-solar-mode.md | 34 ++-- goodwe_controller/app/carmode.py | 22 +++ goodwe_controller/app/chargers.py | 42 ++--- goodwe_controller/test_ev13.py | 102 +++++++----- goodwe_controller/test_ev20_rig.py | 156 +++++++++++++++++- 5 files changed, 271 insertions(+), 85 deletions(-) diff --git a/goodwe_controller/DECISIONS/EV-20-solar-mode.md b/goodwe_controller/DECISIONS/EV-20-solar-mode.md index 2a13051..8518943 100644 --- a/goodwe_controller/DECISIONS/EV-20-solar-mode.md +++ b/goodwe_controller/DECISIONS/EV-20-solar-mode.md @@ -111,23 +111,25 @@ one small set of facts and derives every path from them: ## 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. +- **The stuck-reading check (chargers.py `CarTracker`), for every writer** + (SPIKE-06 option 2, PM decision; replaces 3a17012's power rules). + - Baseline: the signature (power, read-back) of the latest reading taken + BEFORE the send, kept at `begin_write`; never a reading that arrived + while the write waited (the rig's race, C10/C11, C13). + - Arms: a write that moved the setpoint by `STUCK_MIN_A`. Accepted: at its + send, on the baseline. Refused (EV-13): only with no life in `TOOK_S`, + dated the send, on the baseline. EV-36: the first sample after the send + is not life by itself; life differs from the samples before the send + AND from that first one. + - Clears: any reading whose signature differs from the baseline. - 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. + - A frozen POWER under an accepted write (the read-back moves) is no longer + judged here: the energy meter (EV-18 `contradicted`) and the read-back + cap on the trusted figure judge it. +- **Solar after a stuck verdict (C12):** once Solar's own 0 A stands + (written and taken), a stuck verdict no longer holds the car at 0 A; the + start rule runs. Its write moves the reading (the verdict clears) or is + refused (EV-04's retries, then CHARGER_REFUSED). - **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 diff --git a/goodwe_controller/app/carmode.py b/goodwe_controller/app/carmode.py index 760d309..2996fca 100644 --- a/goodwe_controller/app/carmode.py +++ b/goodwe_controller/app/carmode.py @@ -716,6 +716,7 @@ class SolarWriter(ManualWriter): self.start_owed = False # C1: a start in Off with a 0 A pending self.other_at = None # C6: Manual's latest non-zero write self.on_owed = None # C1: told when an own 0 A is out / back + self.stuck_starts = 0 # SPIKE-06 C12: starts under one stuck verdict def owe_start(self) -> None: """C1: the add-on starts in Off while an exit 0 A of its own was still @@ -757,6 +758,7 @@ class SolarWriter(ManualWriter): held = self.hold or self.mismatch_since is not None super().user_changed() self.gave_up, self.fails, self.fail_at = False, 0, None + self.stuck_starts = 0 if held: self.last_a = None self.sent_a, self.taken = None, True @@ -768,6 +770,8 @@ class SolarWriter(ManualWriter): read-back is never trusted (`live`).""" self.sent_a, self.taken = float(a), False zero = float(a) <= TOL_A + if not zero and tracker is not None and tracker.stuck(now): + self.stuck_starts += 1 # C12: a start under a stuck verdict if zero: self.zero_at = self.zero_sent_at = now self._owed(True) # C1: kept with the mode until back @@ -1036,6 +1040,24 @@ class SolarWriter(ManualWriter): self.would = None fault = ("error" if (r.error or r.state in ("E", "F")) else "stuck" if stuck else None) + if not stuck: + if self.stuck_starts >= MAX_TRIES and self.gave_up: + self.gave_up = False # the reading moved: start afresh + self.stuck_starts = 0 + if fault == "stuck" and self.taken and self.sent_a is not None \ + and self.sent_a <= TOL_A: + # SPIKE-06 C12 (option 2): Solar's own 0 A stands, so a stuck + # verdict no longer holds the car at 0 A; the start rule runs. Its + # write moves the reading (the verdict clears) or is not taken: + # then the 0 A again, and after MAX_TRIES such starts under one + # verdict, CHARGER_REFUSED and the 0 A stands (EV-04's rule). + if self.stuck_starts < MAX_TRIES: + fault = None + elif not self.gave_up: + self.gave_up = True + _LOG.warning("The charger did not take the current, so the " + "add-on stops asking until you press Solar: " + "CHARGER_REFUSED.") if fault is not None: # 0 A while owed, then no write until it clears; then the start # rule. A stuck reading cannot confirm the 0 A. diff --git a/goodwe_controller/app/chargers.py b/goodwe_controller/app/chargers.py index 03c2c49..a2082b0 100644 --- a/goodwe_controller/app/chargers.py +++ b/goodwe_controller/app/chargers.py @@ -76,7 +76,6 @@ 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 @@ -717,10 +716,9 @@ 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`; `armed_pre_w` is its power, kept - # while the check is armed. Empty / None: no write begun or not armed. + # write went out, kept at `begin_write` (the arming baseline). Empty: no + # write begun, and `note_write` uses `sig`. pre_sig: tuple = () - armed_pre_w: float | None = None armed_at: float | None = None armed_sig: tuple | None = None sig: tuple | None = None @@ -790,10 +788,11 @@ 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 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.""" + EV-20 (rig round 1, EV-32; SPIKE-06 option 2): the stuck check's + baseline is the signature kept HERE, before the send. The write waits + for its read-back and the cycle reads the charger meanwhile, so `sig` + can already be the car's answer by `note_write`; armed on that, an + unchanged car was called stuck 60 s later.""" self.mute_until = float("inf") self.pre_sig = (self.sig,) @@ -817,7 +816,9 @@ 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 - pre = self.pre_sig[0] if self.pre_sig else None + # The baseline: the reading before the send (`begin_write`), never one + # that arrived while the write waited (no `begin_write`: `sig`). + base = self.pre_sig[0] if self.pre_sig else self.sig self.pre_sig = () try: moved = was_a is None or abs(float(to_a) - float(was_a)) \ @@ -830,17 +831,13 @@ class CarTracker: return if ok: self._pend = None - 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] + self.armed_at, self.armed_sig = now, base 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": self.sig, "first": None} + self._pend = {"t": now, "pre": pre, "sig": base, "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]): @@ -886,23 +883,12 @@ 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) - # 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)): + if self.armed_at is not None and 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 diff --git a/goodwe_controller/test_ev13.py b/goodwe_controller/test_ev13.py index 932894c..f4b71ae 100644 --- a/goodwe_controller/test_ev13.py +++ b/goodwe_controller/test_ev13.py @@ -609,27 +609,57 @@ for beside, side in SIDES: f"{w.amber()}", w.amber() == ["charger_refused", "charger_stuck"]) +# SPIKE-06 option 2 (PM decision, EV-20): the stuck check is armed on the +# reading before the send, so a frozen POWER under an accepted write (the +# read-back moves) is no longer judged by it. The energy-meter check (EV-18, +# `contradicted`) judges it, and the alarm figure stays capped by the +# read-back. Each row: never stuck; when the meter contradicts the figure. +async def contra_steps(w, n): + """[(t, contradicted, trusted figure, stuck)] one per second.""" + out = [] + for _ in range(n): + await w.step(1) + tk = w.c.car + out.append((w.t, tk.contradicted(w.t), tk.car_w_trusted(w.t), + tk.stuck(w.t))) + return out + + +def contra_report(name, t_w, cs, cap_w): + first = next((t for t, c, _f, _s in cs if c), None) + stuck = [t for t, _c, _f, s in cs if s] + # once the read-back shows the new current (its 3 s lag, +2) + over = [(t, f) for t, _c, f, _s in cs + if f is not None and f > cap_w and t >= t_w + 5] + rel = None if first is None else first - t_w + check(f"{name}: never stuck (the read-back moved), and the trusted " + f"figure never exceeds the read-back's {cap_w:.0f} W (energy meter " + f"contradicts it from the write +{rel} s; stuck {stuck[:1]}, over " + f"{over[:1]})", not stuck and over == []) + return rel + + async def t14(): w = await live_car(beside=True) w.sim.lag_s = 3.0 # the read-back is seen by the cycle w.sim.freeze_power() # the power sticks, the rest is live res = spy_on(w) - await w.act("car_current", 8) - tr = await w.step(100) - return w, res, tr + await w.act("car_current", TO_A) + cs = await contra_steps(w, 200) + return w, res, cs -LOG.rec.clear() -w, res, tr = run(t14()) -t_s = res[0][0] -fs = first_stuck(tr) -check(f"T14 an ACCEPTED write (read-back 3 s late) under a frozen power: " - f"stuck at t_s+60 (+-1), as before ({fs - t_s if fs else None})", - res[0][2] is True and fs is not None and 59 <= fs - t_s <= 61 - and w.c.car.armed_at == t_s) -check("T14 ...the amber row 'charger_stuck' shows, and the car figure is not " - "trusted while stuck (N4)", "charger_stuck" in w.amber() - and w.c.car.car_w_trusted(w.t) is None and w.c.car_alarm_w() is None) +for TO_A in (8, 6): + LOG.rec.clear() + w, res, cs = run(t14()) + rel = contra_report(f"T14 an ACCEPTED 16 -> {TO_A} A write (read-back 3 s " + f"late) under a frozen power", res[0][0], cs, + TO_A * CH.CEILING_V * 3) + check(f"T14 [{TO_A} A] ...the write was accepted", res[0][2] is True) + if TO_A == 6: + check(f"T14 [6 A] the energy meter flags the frozen figure (EV-18) " + f"within 120 s of the write (+{rel})", + rel is not None and rel <= 120) async def t17(): @@ -637,25 +667,22 @@ async def t17(): w.sim.refuse = "ignore" res = spy_on(w) await w.act("car_current", 10) - tr = await w.step(70) # tries at t_s and t_s+60: live + await w.step(70) # tries at t_s and t_s+60: live w.sim.refuse = None w.sim.lag_s = 3.0 w.sim.freeze_power() await w.act("car_current", 12) - tr += await w.step(120) - return w, res, tr + cs = await contra_steps(w, 200) + return w, res, cs LOG.rec.clear() -w, res, tr = run(t17()) -t_s, t_acc = res[0][0], res[-1][0] -fs = first_stuck(tr) -check(f"T17 live refusals (not armed), then an accepted write at t_s+" - f"{t_acc - t_s:.0f}: not armed before it, stuck at ITS +60 (+-1) " - f"({fs - t_acc if fs else None})", - res[-1][2] is True and t_acc - t_s > 61 and fs is not None - and 59 <= fs - t_acc <= 61 - and all(a is None for t, a, _s in tr if t < t_acc)) +w, res, cs = run(t17()) +T17_S = contra_report("T17 live refusals, then an ACCEPTED write to 12 A " + "under a frozen power", res[-1][0], cs, + 12 * CH.CEILING_V * 3) +check("T17 ...the last write was accepted, after the refusals", + res[-1][2] is True and res[0][2] is False) async def t18(): @@ -663,25 +690,22 @@ async def t18(): w.sim.lag_s = 3.0 w.sim.freeze_power() res = spy_on(w) - await w.act("car_current", 12) # accepted: arms - tr = await w.step(19) + await w.act("car_current", 12) # accepted + cs = await contra_steps(w, 19) w.sim.lag_s = 0.0 w.sim.refuse = "ignore" await w.act("car_current", 10) # a live refusal 20 s later - tr += await w.step(100) - return w, res, tr + cs += await contra_steps(w, 180) + return w, res, cs LOG.rec.clear() -w, res, tr = run(t18()) -t0 = res[0][0] -fs = first_stuck(tr) -check(f"T18 an accepted write armed at t0; a live refusal at t0+" - f"{res[1][0] - t0:.0f} neither clears nor delays it: stuck at t0+60 " - f"({fs - t0 if fs else None}), still dated t0", - len(res) >= 2 and res[1][2] is False and fs is not None - and 59 <= fs - t0 <= 61 and tr[-1][1] == t0 - and all(a == t0 for _t, a, _s in tr if a is not None)) +w, res, cs = run(t18()) +T18_S = contra_report("T18 an ACCEPTED write to 12 A under a frozen power, a " + "refusal 20 s later", res[0][0], cs, + 12 * CH.CEILING_V * 3) +check("T18 ...the second write was refused", len(res) >= 2 + and res[1][2] is False) async def t21(beside): diff --git a/goodwe_controller/test_ev20_rig.py b/goodwe_controller/test_ev20_rig.py index 4eb0c2e..eb9940b 100644 --- a/goodwe_controller/test_ev20_rig.py +++ b/goodwe_controller/test_ev20_rig.py @@ -11,6 +11,8 @@ 4. The 6 A hold lasts its full `ev_pause_min` from the spare's drop, 1 and 3 phases (Major); a meter as Home Assistant publishes it (`ha_signed`, on a change only) does not pause the car while it is healthy (Minors). +5. SPIKE-06: the race as the formal replay plays it; C12 (a refusal on a + paused car no longer holds Solar at 0 A); C13 (a capped car is not stuck). Mutating a module this file grades? Read MUTATION.md first (purge __pycache__). """ @@ -23,10 +25,11 @@ sys.path.insert(0, os.path.join(HERE, "tools")) from datetime import datetime, timezone # noqa: E402 -from app import chargers as CH # noqa: E402 +from app import carmode, chargers as CH # noqa: E402 import ev20_sun as S # noqa: E402 from chargersim import SimCharger # noqa: E402 -from ev20_kit import (check, const, cur_writes, nevers, report, # noqa: E402 +from ev20_kit import (LOG, TSim, act, check, const, cur_writes, # noqa: E402 + nevers, report, step_fn) from named_absence import nth, present # noqa: E402 @@ -270,4 +273,153 @@ check(f"ha_signed, the meter silent from 300 s: 0 A at 30 + 300 s (+2), " present(nth(z, 0)) and 629 <= nth(z, 0) <= 633 and [a for t, a, _ in w if 300 <= t < 629] == []) +# =========================================================================== # +print("\n6. SPIKE-06: C12, C13 AND THE RACE AS THE FORMAL REPLAY PLAYS IT") +# =========================================================================== # + + +def race_hook(p, c): + """The race exactly as production interleaves it (SPIKE-06 replay): the + driver's read-back wait runs the next cycle's charger read, so the tracker + files the post-write reading before `note_write`.""" + orig = c.charger._sleep + + async def sleep(s): + await orig(s) + await c._read_charger(p.clock[0]) + c.charger._sleep = sleep + + +def stuck_ts(r): + return [x["t"] for x in r["trace"] if x["fault"] == "stuck"] + + +# C10/C11 replays (ctl A: the charger's power-on 10 A, Solar's D2 0 A; ctl B: +# Solar's 10 A start on a charging car), each with the race. +sim = SimCharger(setpoint_a=10) +sim.lag_s = 1.0 +r = S.drive(const(500.0), const(2900.0), dur=900, first="car", + socs={"a": 100.0, "b": 100.0}, sim=sim, events={0: race_hook}) +w = cur_writes(r) +check(f"race replay ctl A: D2 0 A, then the start at 120 s, never stuck " + f"({w[:3]}, stuck {stuck_ts(r)[:1]}, tracker {r['c'].car.stuck_now})", + present(nth(w, 1)) and nth(w, 0)[1] == 0.0 and nth(w, 1)[1] > 0.0 + and 119 <= nth(w, 1)[0] <= 125 and not stuck_ts(r) + and not r["c"].car.stuck_now) +nevers(r, "race replay ctl A") +sim = SimCharger(setpoint_a=0) +sim.lag_s = 1.0 +r = S.drive(const(500.0), const(2900.0), dur=900, first="car", + socs={"a": 100.0, "b": 100.0}, sim=sim, events={0: race_hook}) +w = cur_writes(r) +check(f"race replay ctl B: one start write, the car charges to the end, " + f"never stuck ({w[:3]}, stuck {stuck_ts(r)[:1]})", + len(w) == 1 and w[0][1] > 0.0 and not stuck_ts(r) + and not r["c"].car.stuck_now and r["sim"].power_w > 2000.0) +nevers(r, "race replay ctl B") + +# C12: a paused (full) car, a live charger ignores Solar's start write once. +# No life (0 W, flat energy), so the refusal arms and is stuck 60 s later; +# Solar's 0 A then stands. Option 2: the stuck verdict no longer holds the +# car at 0 A; the start rule writes again within 2 min, the reading moves. +for race in (False, True): + sim = TSim(setpoint_a=0, windows=[(100.0, 135.0, "ignore")]) + sim.car_full() + if race: + sim.lag_s = 1.0 + r = S.drive(const(500.0), const(2900.0), dur=900, first="car", + socs={"a": 100.0, "b": 100.0}, sim=sim, + events={0: race_hook} if race else None) + w = cur_writes(r) + tr = [x["t"] for x in r["trace"] if x["fault"] == "stuck"] + st = r["c"].car + z = [t for t, a, _ in w if a == 0.0 and t > 125] + nz = [t for t, a, _ in w if a > 0.0 and present(nth(z, 0)) and t > z[0]] + check(f"C12 [race={race}] a live charger ignores one start write on a " + f"paused car: after Solar's 0 A the start rule writes again within " + f"125 s and the stuck verdict clears (writes {w[:6]}, 0 A at " + f"{z[:1]}, again at {nz[:1]}, stuck now {st.stuck_now})", + present(nth(z, 0)) and present(nth(nz, 0)) + and nth(nz, 0) - nth(z, 0) <= 125 and not st.stuck_now + and r["trace"][-1]["fault"] is None) + nevers(r, f"C12 [race={race}]") + +# C12's bound: a charger whose reading is really frozen. Solar's own 0 A +# stands (the frozen read-back shows 0 A), so the start rule runs; each start +# write is not taken and the 0 A follows. At most MAX_TRIES starts under one +# verdict, then ONE CHARGER_REFUSED warning and the 0 A stands (EV-04: until +# Solar is pressed). Here the reading comes back at 1200 s with the very +# values it froze with (0 W, 0 A), so nothing moves; pressing Solar at 1250 s +# starts afresh. +n0 = LOG.mark() +r = S.drive(const(600.0), lambda t: 600.0 + (1000.0 if 200 <= t < 330 + else 2300.0 if t < 200 + else 6000.0), + dur=1500, first="car", socs={"a": 100.0, "b": 100.0}, + opts={"ev_pause_min": 1, "ev_start_min": 1}, + events={300: lambda p, c: p.ch.freeze(), + 1200: lambda p, c: p.ch.freeze(False), + 1250: act("car_mode", "solar")}) +r["_log"] = n0 +w = cur_writes(r) +st = [x["t"] for x in r["trace"] if x["fault"] == "stuck"] +t0 = nth(st, 0) if st else 0.0 +starts = [t for t, a, _ in w if a > 0.0 and t0 <= t < 1200] +warn = [m for m in LOG.since(n0, "WARNING") if "CHARGER_REFUSED" in m] +after = [(t, a) for t, a, _ in w if t >= 1200] +quiet = [(t, a) for t, a in after if t < 1250] +check(f"C12 bound: a frozen charger after Solar's own 0 A: at most 3 starts " + f"under the verdict ({starts}), one CHARGER_REFUSED ({len(warn)}), the " + f"charger at 0 A, nothing written until Solar is pressed, then a start " + f"within the start rule ({after[:2]})", + bool(st) and 1 <= len(starts) <= carmode.MAX_TRIES and len(warn) == 1 + and not quiet and present(nth(after, 0)) and nth(after, 0)[1] > 0.0 + and nth(after, 0)[0] <= 1250 + 75 + and [a for t, a, _ in w if t0 <= t < 1200][-1:] == [0.0]) +nevers(r, "C12 bound") + +# C13: a car that draws less than allowed (an on-board limit of 1380 W, or a +# taper). Tracker level: a raise 6 -> 10 A, the post-write reading filed +# during the wait (race) or not: never stuck. +for race in (True, False): + tr = CH.CarTracker() + tr.observe(rd(power=1380.0, allowed=6.0), TS, UTC, DAY) + tr.begin_write() + if race: + tr.observe(rd(power=1380.0, allowed=10.0), TS + 1, UTC, DAY) + tr.note_write(TS, 6.0, 10.0, True) + tr.end_write(TS + 1.5) + first = None + for i in range(2, 301): + tr.observe(rd(power=1380.0, allowed=10.0), TS + i, UTC, DAY) + if first is None and tr.stuck(TS + i): + first = i + check(f"C13 tracker [race={race}] a capped car (1380 W), raised 6 -> 10 " + f"A: never stuck (first at {first})", first is None) + + +class CapSim(SimCharger): + """A car whose on-board charger draws at most `cap_w`.""" + cap_w = 1380.0 + + def target_w(self): + return min(super().target_w(), self.cap_w) + + +for race in (True, False): + sim = CapSim(setpoint_a=0) + sim.lag_s = 1.0 + r = S.drive(const(500.0), lambda t: 3600.0 if t >= 300 else 2900.0, + dur=900, first="car", socs={"a": 100.0, "b": 100.0}, sim=sim, + events={0: race_hook} if race else None) + w = cur_writes(r) + up = [(t, a) for t, a, _ in w if t >= 300] + check(f"C13 controller [race={race}] a capped car, Solar raises the " + f"current at 300 s: never stuck, no 0 A after it ({w[:5]}, stuck " + f"{stuck_ts(r)[:1]})", + present(nth(up, 0)) and nth(up, 0)[1] > 10.0 and not stuck_ts(r) + and not [a for _, a in up if a == 0.0]) + nevers(r, f"C13 controller [race={race}]") + + report()