From c2bb32ec932db9e428b33efb505d6752d20c4912 Mon Sep 17 00:00:00 2001 From: ems-agent Date: Fri, 20 Nov 2026 22:13:19 +0100 Subject: [PATCH] EV-19 review round 1: discount a battery rise only while the meter has not moved [Major] The rise discount applied to any rise, also one the meter already shows, so an honest house step answered by one cycle of battery power alarmed one cycle after base (review repro: T6 step + burst, R+6 instead of R+5). Now a reading above both earlier ones is discounted only while the meter's house side (held - car; held alone when a car figure is unknown) moved no more than RISE_STILL_W (50 W) since the last cycle. Tests: the burst shapes (unit, meter in step and one cycle late; controller, step at R+5 and R+30, 3 000 / 4 600 W) at base's second; the "N6 unit" check tightened to the rise cycle; the RISE_STILL_W boundary; a pin on EV-18's `_car_over_now` (mC); T10 restarts at R-1 and R (mE). test_ev19: 144 of 144 here, 52 red on 43b0db7. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w --- .../DECISIONS/EV-04-manual-mode.md | 12 ++- goodwe_controller/app/ctl_car.py | 27 +++++-- goodwe_controller/test_ev19.py | 79 ++++++++++++++++--- goodwe_controller/tools/ev19_reserve.py | 29 ++++++- 4 files changed, 127 insertions(+), 20 deletions(-) diff --git a/goodwe_controller/DECISIONS/EV-04-manual-mode.md b/goodwe_controller/DECISIONS/EV-04-manual-mode.md index 6f0e852..4fb034b 100644 --- a/goodwe_controller/DECISIONS/EV-04-manual-mode.md +++ b/goodwe_controller/DECISIONS/EV-04-manual-mode.md @@ -152,13 +152,17 @@ up to 1.8 kW; the 40 Wh floor fixes that.) whole window and fell short; an unknown reading is no contradiction) grades no alarm to the quarter's end; the guard's input keeps it. After a restart or a gap the car's earlier energy is not known, so it counts as house. -- **A battery rise is house only once a second reading shows it** (EV-19, EV-15 +- **A battery rise the meter has not shown is not house yet** (EV-19, EV-15 rig F-B). At the reserve inverter-b goes on following the house, so its output rises; the reading shows it one cycle before P1 does, and the house figure (meter + battery) counted that power as house. `_car_need_house` - latched and the alarm stood. For the house figure, a reading above both - earlier ones counts only up to the higher of them; the credit stays the lower - of the last two readings. + latched and the alarm stood. Now, while the meter's house side (held - car) + moved no more than `RISE_STILL_W` since the last cycle, a reading above both + earlier ones counts only up to the higher of them. A meter that moved shows + the rise (an honest step with a battery burst alarms at once, as before). A + rise the meter does not move with at all is graded as F-B: the one case the + readings cannot tell apart. The credit stays the lower of the last two + readings; `_car_over_now` is unchanged. - **Our own write is ours until its mute ends** (EV-12). The mute of the tracker's own detector opens before the write and runs 15 s from when it returns, because the read-back reaches the cycle while the write still waits for it. diff --git a/goodwe_controller/app/ctl_car.py b/goodwe_controller/app/ctl_car.py index da37a70..d87d1bc 100644 --- a/goodwe_controller/app/ctl_car.py +++ b/goodwe_controller/app/ctl_car.py @@ -31,6 +31,9 @@ OVER_OFF_HOLD_S = 180.0 OWN_PAUSE_MAX_S = (carmode.ZERO_WAIT_S + carmode.SETTLE_S + carmode.MAX_TRIES * 15.0 + 10.0) OWN_PAUSE_TAIL_S = chargers.CORR_WINDOW_S +# EV-19: the meter's house side (held - car) moved no more than this since the +# last cycle: it has not shown a battery rise the reading already shows. +RISE_STILL_W = 50.0 class CarMixin: @@ -59,6 +62,7 @@ class CarMixin: self._car_over_since = None self._car_over_gone = None self._car_batt_prev = self._car_batt_prev2 = None + self._car_hx_prev = None # EV-19: last cycle's (held, car W) self._car_need_real = self._car_need_excl = False # EV-10 latches self._car_need_house = self._car_over_now = False # EV-18 latches self._car_latch_block = None @@ -416,12 +420,6 @@ class CarMixin: now, prev = self.site_batt_w, self._car_batt_prev prev2, self._car_batt_prev2 = self._car_batt_prev2, prev self._car_batt_prev = now - # EV-19: the reading can show a rise one cycle before the meter does - # (the batteries pick up the house at the reserve), so a reading above - # both earlier ones is not yet counted as house. - seen = now - if now is not None and prev is not None and prev2 is not None: - seen = min(float(now), max(float(prev), float(prev2))) wants = bool(guard is not None and guard.engaged and guard.blind is None and (guard.wanted_w or 0.0) > 0.0) @@ -433,6 +431,23 @@ class CarMixin: if batt is not None and prev is not None: batt = min(float(batt), float(prev)) excl = self.car_exclude_alarm(real_proj, w) + # EV-19: the reading can show a rise one cycle before the meter does + # (the batteries pick up the house at the reserve). While the meter's + # house side (held - car; held alone when a car figure is unknown) has + # not moved, a reading above both earlier ones is not yet counted as + # house; a meter that moved shows it (no discount). + held = float(real_proj.held_w) + hp, self._car_hx_prev = self._car_hx_prev, (held, w) + still = False + if hp is not None: + moved = held - hp[0] + if w is not None and hp[1] is not None: + moved -= float(w) - float(hp[1]) + still = abs(moved) <= RISE_STILL_W + seen = now + if still and now is not None and prev is not None \ + and prev2 is not None: + seen = min(float(now), max(float(prev), float(prev2))) if wants and batt is not None: self._car_need_real = self._car_need_real or \ peakguard.misses_aim(real_proj, batt_w=batt, diff --git a/goodwe_controller/test_ev19.py b/goodwe_controller/test_ev19.py index bf4077c..57ca96e 100644 --- a/goodwe_controller/test_ev19.py +++ b/goodwe_controller/test_ev19.py @@ -147,16 +147,55 @@ u6 = urun(range(-5, 30), meter(AIM + 11.0 + 400.0, lambda t: 400.0, lag=0), check("N6 unit: b at 400 W, the house alone with it at aim + 11 W, one " "reading of 800 W at E+3: not explained in any cycle", not any(run_of(u6, 0, 29))) -# The rise counts as house once a second reading confirms it: b steps to -# 800 W and the meter, one cycle late, shows a house of aim + 811 W (the -# house steps with it), so with b's 800 W the house alone misses by 11 W. +# A house step that comes with a battery rise: b steps to 800 W and the +# meter, one cycle late, shows a house of aim + 811 W, so with b's 800 W the +# house alone misses by 11 W. The meter moved, so nothing is discounted. b8 = rise(5, 0.0, 800.0) u8 = urun(range(0, 30), lambda t: (AIM - 500.0 if t < 5 else AIM + 811.0) + CAR - b8(t - 1), b8) print(f" N6 unit house step with a rise E+4..E+8: {run_of(u8, 4, 8)}") -check("N6 unit: a house step that comes with a battery rise is latched at " - "most one cycle after the rise (E+6), and stays latched", - all(run_of(u8, 0, 4)) and not any(run_of(u8, 6, 29))) +check("N6 unit: a house step that comes with a battery rise is latched in " + "the rise cycle (E+5, as base), and stays latched", + all(run_of(u8, 0, 4)) and not any(run_of(u8, 5, 29))) + +# Review round 1 (Major): an honest house step at E+5 answered by ONE reading +# of battery power, the meter in step (it shows the burst too) or one cycle +# late. Not explained from E+5, the step's own cycle, as base. +for H, burst, lag in ((2000.0, 4600.0, 0), (1900.0, 3000.0, 0), + (5000.0, 4600.0, 0), (2000.0, 4600.0, 1), + (1900.0, 3000.0, 1)): + hs = (lambda t, H=H: AIM - 500.0 if t < 5 else AIM + H) + bb = (lambda t, burst=burst: burst if t == 5 else 0.0) + ub = urun(range(0, 15), lambda t, hs=hs, bb=bb, lag=lag: + hs(t) + CAR - bb(t - lag), bb) + check(f"RB unit: house -> aim + {H:.0f} W at E+5 with one {burst:.0f} W " + f"reading, meter {'in step' if lag == 0 else 'one cycle late'}: " + f"explained to E+4, not from E+5 (base: the same)", + ub.get(4) is True and not any(run_of(ub, 5, 14)) + and len(run_of(ub, 5, 14)) == 10) + +# The discount needs a still meter: the F-B rise (T2 unit) with the house +# side of the meter moving by RISE_STILL_W -/+ 10 W in the rise cycle. +STILL = getattr(ctl_car, "RISE_STILL_W", 50.0) # 43b0db7 has none +for d, want in ((STILL - 10.0, True), (STILL + 10.0, False)): + ud = urun(range(-5, 10), lambda t, d=d: HB + (d if t >= 1 else 0.0) + + CAR - b2(t - 1), b2) + check(f"RISE_STILL_W: the meter's house side moves {d:.0f} W in the rise " + f"cycle: {'still, the rise is not yet house (explained)' if want else 'moved, the rise counts as house (not explained, as base)'}", + ud.get(1) is want and ud.get(0) is True) + +# Review round 1 (mC): EV-18's `_car_over_now` keeps the reading as it is. b +# gives 2 000 W, the house alone with it lands under the aim and the period +# with the car too, so nothing explains; b rises to 4 000 W at E+5 one cycle +# before the meter: the period with the car on the reading as it is lands +# over, so the car explains from E+5. +bc = rise(5, 2000.0, 4000.0) +uc = urun(range(0, 15), lambda t: AIM + 500.0 + CAR - bc(t - 1), bc) +print(f" over_now unit E+3..E+7: {run_of(uc, 3, 7)}") +check("over_now unit: `_car_over_now` grades the undiscounted reading: not " + "explained E+0..E+4, explained from the rise cycle E+5", + not any(run_of(uc, 0, 4)) and all(run_of(uc, 5, 14)) + and len(run_of(uc, 5, 14)) == 10) # =========================================================================== # print("\n2. THE REAL CONTROLLER AT THE RESERVE (N=2, tools/ev19_reserve.py)") @@ -200,6 +239,8 @@ BASE_ALARMS = { "T9(a) T5 b lost at R": [2], "T9(a) T5 b lost at R-1": [2], "T9(b) T5 P1 5 s late at R": [5], "T10 T5 twin": [2], "T10 T5 restart R-2": [2], "T10 T5 restart R+2": [2], + "T10 T5 restart R-1": [2], "T10 T5 restart R+0": [2], + "T10 T2 restart R+0": [1], "T11 T5 R=E-1": [2], "T11 T5 R=E+0": [0, 2], "T11 T5 R=E+1": [0, 2], "T11 T5 R=E+43": [2], "T12 T5 1->3 at R-15": [2], "T12 T5 1->3 at R+5": [2], "T13(a) draws 100 W manual": [0, 857], @@ -370,10 +411,16 @@ for nm in ("T2", "T5"): # --- T10: a restart ------------------------------------------------------------ # for nm in ("T2", "T5"): tw = res(f"T10 {nm} twin") - for k in (-2, 2): + for k in (-2, -1, 0, 2): r = res(f"T10 {nm} restart R{k:+d}") show(f"T10 {nm} restart R{k:+d}") - if nm == "T2": + if nm == "T2" and k == 0: + # the rise cycle R+1 has no reading from two cycles back: nothing + # is discounted (the old behaviour), so the alarm is base's + check("T10 T2 restart at R+0: no reading two cycles back in the " + "rise cycle, so no discount: the alarm as base (R+1)", + as_base("T10 T2 restart R+0")) + elif nm == "T2": check(f"T10 T2 restart at R{k:+d}: no notice, no red sample, as " f"the unrestarted twin", r.quiet(-60, 900) and tw.quiet(-60, 900)) @@ -383,6 +430,18 @@ for nm in ("T2", "T5"): as_base(f"T10 T5 restart R{k:+d}") and as_base("T10 T5 twin") and len(r.red()) == len(tw.red())) +# --- Review round 1 (Major), controller: the T6 step with a one-cycle burst ---- # +for k in (5, 30): + for hi in (1900, 2500): + for burst in ("3000", "4600"): + nm = f"RB step R+{k} aim+{hi} burst {burst} manual" + r = res(nm) + show(nm) + check(f"{nm[:-7]}: P1 and the reading both show the burst: the " + f"notice, the ERROR and the first red sample at the step, " + f"R+{k}, as base", r.rel_alarms() == [k] + and r.errors() == [k] and r.red()[:1] == [k]) + # --- T11: the quarter edge ------------------------------------------------------ # for rr in (-1, 0, 1, 43): r = res(f"T11 T2 R=E{rr:+d}") @@ -551,7 +610,9 @@ BASE_TWO = ["T1 b: energy first step late", "T1 b: energy never steps", "T11 T5 R=E+1 off", "T16 mono1 T11 T5 R=E+0", "T16 mono1 T11 T5 R=E+10", "T16 mono1 T6 off", "T16 x10 T11 T5 R=E+0", "T16 x10 T11 T5 R=E+10", "T16 x10 T6 off", - "T6 step R+0 off", "T6 step R+1 off", "T6 step R+5 off"] + "T6 step R+0 off", "T6 step R+1 off", "T6 step R+5 off"] + [ + f"RB step R+{k} aim+{hi} burst {b} off" for k in (5, 30) + for hi in (1900, 2500) for b in (3000, 4600)] many = sorted(k for k, r in RES.items() if any(v > (2 if k in BASE_TWO and q == 0 else 1) for q, v in r.edges_per_quarter().items())) diff --git a/goodwe_controller/tools/ev19_reserve.py b/goodwe_controller/tools/ev19_reserve.py index 319c5b4..bce4918 100644 --- a/goodwe_controller/tools/ev19_reserve.py +++ b/goodwe_controller/tools/ev19_reserve.py @@ -201,7 +201,7 @@ def run(*, bw=4250.0, traj="t1", rp=180, r_rel=43, order="manual", soc_after = soc_after or {u: 19.0 for u in units} lagb = 10.0 if traj == "t4" else 0.0 cls = type("Plant", (Plant,), { - "force": frc, "batt_lag": lagb, + "force": frc, "batt_lag": lagb, "R": R, "lost": {u: {R + k for k in v} for u, v in (lost or {}).items()}, "p1_lag": 5.0 if traj == "t4r" else 0.0, "p1_from": float(R)}) @@ -477,6 +477,17 @@ def _step_house(k, lo=AIM + 520.0 - CAR, hi=AIM + 1900.0): return lambda t, R: lo if t < R + k else hi +def _burst(k, w): + """Inverter-b: 2 125 W until R+1, then `w` for 0.5 s before the cycle at + R+k (P1, sampled 0.3 s before it, and the reading both show it), else + 0 W.""" + def f(at, plant): + if at < plant.R + 1: + return 4250.0 / 2.0 + return w if plant.R + k - 0.5 <= at <= plant.R + k else 0.0 + return f + + def _ignoring(): """The charger accepts the 6 A write and ignores it: the car stays at 0 A.""" @@ -626,6 +637,22 @@ def jobs(): mode=md) j[f"N2 reports 11 kW at 6 A {md}"] = t5_shape( sim=Draw(CAR, 11000.0, setpoint_a=6), mode=md) + # Review round 1: an honest house step answered by ONE cycle of inverter-b + # power that P1 and the reading both show (the meter in step), after the + # T6 shape (4 250 W until R, then 0 W). + for k in (5, 30): + for hi in (1900, 2500): + for burst in (3000.0, 4600.0): + for md in ("manual", "off"): + j[f"RB step R+{k} aim+{hi} burst {burst:.0f} {md}"] = dict( + bw=4250.0, traj="t1", mode=md, + house_fn=_step_house(k - 0.5, hi=AIM + hi), + force={"b": _burst(k, burst)}) + # T10 (mE): restarts at R-1 and R, so the rise cycle has no reading from + # two cycles back + for nm, sh in (("T2", t2_shape), ("T5", t5_shape)): + for k in (-1, 0): + j[f"T10 {nm} restart R{k:+d}"] = sh(rel=restart(k)) # T20 / N4: the same runs with the car never explaining j["N4 T2 explain off"] = t2_shape(explain_off=True) j["N4 T5 explain off"] = t5_shape(explain_off=True)