EV-60: gate the "car kept drawing" close, reset _cap_end at _advance entry, more checks
- SolarWriter._advance gates the close where the value is asked for (wrapped want_a raising a private _CloseHeld), so the shared zero -> settle fall-through write of "the car kept drawing" passes the same cut gate, the Q5/Q6 wait and the end at 0 A. ManualWriter is unchanged (N7 sha pin). - _cap_end is reset at each Solar _advance entry (no stale flag). - test_ev60: rows S-a, S-b, T12, T15, T22, T25-flag, N4, N6, N11, N12, N13; docstring states the coverage; dead pre_roll line removed; T17 text/asserts. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -840,6 +840,11 @@ class SolarPlan:
|
||||
self.a, self.set_at, self.last_dir = CH.MIN_A, now, -1
|
||||
|
||||
|
||||
class _CloseHeld(Exception):
|
||||
"""EV-60: Solar's cut gate holds the close (raised inside `_advance`'s
|
||||
want-a call, caught in `SolarWriter._advance`; never leaves it)."""
|
||||
|
||||
|
||||
class SolarWriter(ManualWriter):
|
||||
"""What Solar does to the charger, one `step()` per cycle. It shares
|
||||
ManualWriter's write, phase sequence and other-writer watch.
|
||||
@@ -1102,23 +1107,33 @@ class SolarWriter(ManualWriter):
|
||||
it). The sequence's first cut close waits at 0 A until RETRY_S after
|
||||
the last refused cut try (counts nothing, ends nothing); after a cut
|
||||
close of the sequence went, the 5 s spacing of `_advance` rules."""
|
||||
q = self.seq
|
||||
if q["stage"] == "settle" and now - q["t1"] >= SETTLE_S \
|
||||
and callable(want_a):
|
||||
hi = CH.ENTITY_MAX_A if clamp is None else float(clamp)
|
||||
a = min(max(float(want_a(q)), CH.MIN_A), hi)
|
||||
if self._cut_try(a):
|
||||
if self.cut_fails >= MAX_TRIES:
|
||||
self.seq, self.last_a, self.reapply = None, None, True
|
||||
self.rev_applied = None
|
||||
self.plan.end_switch(False)
|
||||
self._cap_end = True
|
||||
return
|
||||
if not q.get("cut_went") and self.cut_fail_at is not None \
|
||||
and now - self.cut_fail_at < RETRY_S:
|
||||
return
|
||||
q["cut_went"] = True
|
||||
await super()._advance(drv, r, cur, now, tracker, want_a, clamp, rev)
|
||||
self._cap_end = False # set again below, read by `step` only
|
||||
if callable(want_a):
|
||||
# The gate runs where `_advance` asks for the close value, just
|
||||
# before it writes: also on the "car kept drawing" path, which
|
||||
# turns zero into settle and closes in the same call.
|
||||
inner, hi = want_a, (CH.ENTITY_MAX_A if clamp is None
|
||||
else float(clamp))
|
||||
|
||||
def want_a(q):
|
||||
v = inner(q)
|
||||
if self._cut_try(min(max(float(v), CH.MIN_A), hi)):
|
||||
if self.cut_fails >= MAX_TRIES:
|
||||
self.seq, self.last_a, self.reapply = None, None, True
|
||||
self.rev_applied = None
|
||||
self.plan.end_switch(False)
|
||||
self._cap_end = True
|
||||
raise _CloseHeld
|
||||
if not q.get("cut_went") and self.cut_fail_at is not None \
|
||||
and now - self.cut_fail_at < RETRY_S:
|
||||
raise _CloseHeld
|
||||
q["cut_went"] = True
|
||||
return v
|
||||
try:
|
||||
await super()._advance(drv, r, cur, now, tracker, want_a, clamp,
|
||||
rev)
|
||||
except _CloseHeld:
|
||||
pass
|
||||
|
||||
def _failed(self, now) -> None:
|
||||
if self.sent_cut:
|
||||
|
||||
Reference in New Issue
Block a user