EV-21: Solar cuts the car first for the quarter peak
In Solar, when the 15-minute period heads over the aim and the batteries would have to give more, the car is lowered first: floor((car - excess) / (230 x phases)) A, 0 under 6 A. At once without real headroom (saturated, floor-limited, excess beyond what the batteries can add, no battery figure, cover off, last 120 s), else after at most 15 s. One cut per episode from its start, deeper only on a growing excess; restart with the start power under the aim for the start time; none after a 2nd cut in the period. Grading (formal C2): a Solar car Solar cannot cut is graded, banked and left in the guard as in Off. A Solar car is never banked. Grey note and Why "Solar lowered the car for the peak." Manual and Off unchanged. Tests: test_ev21.py, test_ev21_paths.py, test_ev21_same.py; T49 in tools/ev20_day.py; T50 in test_ev20_fuzz.py; test_ev20_guard section 8 moved from "as Manual" to "as Off" where Solar cannot cut (T51). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -486,6 +486,25 @@ def amps_for(car_w, n, clamp=None):
|
||||
return float(max(0, min(a, math.floor(hi))))
|
||||
|
||||
|
||||
def cut_amps(car_w, excess_w, n, now_a=None):
|
||||
"""EV-21: the current a peak cut leaves the car, or None when there is
|
||||
nothing to cut (no excess). `floor((car_w - excess_w) / (230 x n))`,
|
||||
0 when that is under 6 A, never above `now_a` (the setpoint now). An
|
||||
unknown car figure cuts to 0 A (PM OQ2)."""
|
||||
ex = _num(excess_w)
|
||||
if ex is None or ex <= 0.0 or n not in (1, 3):
|
||||
return None
|
||||
w = _num(car_w)
|
||||
a = 0.0 if w is None else float(max(
|
||||
0, math.floor((w - ex) / (VOLTS * n) + 1e-9)))
|
||||
if a < CH.MIN_A:
|
||||
a = 0.0
|
||||
top = _num(now_a)
|
||||
if top is not None:
|
||||
a = min(a, max(0.0, top))
|
||||
return a
|
||||
|
||||
|
||||
def solar_option(opts: dict, key: str) -> float:
|
||||
"""`ev_margin_w`, `ev_pause_min` or `ev_start_min` as a number; the shipped
|
||||
default when it is not one (the validator refuses it anyway)."""
|
||||
@@ -574,16 +593,29 @@ class SolarPlan:
|
||||
self._before
|
||||
self.switch, self._before = False, None
|
||||
|
||||
def _cut(self, cap) -> None:
|
||||
"""EV-21: the peak cut lowers the current to `cap` at once, past the
|
||||
30 s gate and the 6 A hold; under 6 A it is the pause."""
|
||||
if cap < CH.MIN_A:
|
||||
self.pause("peak")
|
||||
return
|
||||
self.a, self.last_dir, self.low_since = float(cap), -1, None
|
||||
|
||||
def step(self, now, *, target_w, n_now, auto, clamp, start_s, pause_s,
|
||||
hold=False, gap_ok=True, unknown_s=0.0, meter_back=False):
|
||||
hold=False, gap_ok=True, unknown_s=0.0, meter_back=False,
|
||||
cap=None):
|
||||
"""`n_now`: the phases the car draws on now (1 for a one-phase car);
|
||||
`auto`: Solar may choose the phases; `gap_ok`: a phase change is
|
||||
allowed now (EV-04's one per `PHASE_GAP_S`); `hold`: readings late
|
||||
under the stale bound, everything stands. `meter_back` (EV-51): the
|
||||
meter's own age is fresh again at this step: the unknown timer that
|
||||
counted its silence starts over."""
|
||||
counted its silence starts over. `cap` (EV-21): a peak cut is due or
|
||||
stands: the current goes no higher than `cap` (lowered at once), no
|
||||
start and no phase change; the plan may still lower."""
|
||||
if meter_back:
|
||||
self.unknown_since = None
|
||||
if cap is not None and self.a > cap + 1e-9:
|
||||
self._cut(cap)
|
||||
if hold:
|
||||
# Readings late under the stale bound: nothing changes, but a
|
||||
# hold or an unknown spare that has run its time still pauses
|
||||
@@ -622,8 +654,10 @@ class SolarPlan:
|
||||
if self.ok_since is None:
|
||||
self.ok_since = now
|
||||
self.why = "start"
|
||||
if now - self.ok_since >= start_s and self._gate(now) \
|
||||
and (n0 == self.n or gap_ok):
|
||||
# EV-21: under a peak cut no start (the restart rule lifts
|
||||
# the cap); the start count goes on.
|
||||
if cap is None and now - self.ok_since >= start_s \
|
||||
and self._gate(now) and (n0 == self.n or gap_ok):
|
||||
a = amps_for(target_w, n0, clamp)
|
||||
if a is not None and a >= CH.MIN_A:
|
||||
self._set(a, now, n0)
|
||||
@@ -637,7 +671,7 @@ class SolarPlan:
|
||||
self.pause()
|
||||
return
|
||||
self.a, self.set_at, self.last_dir = float(hi), now, -1
|
||||
if auto and not self.switch: # auto phases, by dwells
|
||||
if auto and not self.switch and cap is None: # auto phases, by dwells
|
||||
if self.n == 1:
|
||||
self.down_since = None
|
||||
if target_w >= UP_W:
|
||||
@@ -674,6 +708,8 @@ class SolarPlan:
|
||||
# `UP_HYST_W` (no ping-pong on an amp boundary).
|
||||
up = amps_for(target_w - UP_HYST_W, self.n, clamp) or 0.0
|
||||
want = max(self.a, up)
|
||||
if cap is not None:
|
||||
want = min(want, self.a) # EV-21: no raise (C10)
|
||||
if abs(want - self.a) >= SOLAR_STEP_A and self._gate(now):
|
||||
self.last_dir = 1 if want > self.a else -1
|
||||
self.a, self.set_at = want, now
|
||||
@@ -744,6 +780,8 @@ class SolarWriter(ManualWriter):
|
||||
self.stuck_warned = False # ... and its one CHARGER_REFUSED was given
|
||||
self.nz_block = False # C17/C18: this step writes 0 A at most
|
||||
self.held_step = False # C18: a held read: only a NEW 0 A goes out
|
||||
self.cut_a = None # EV-21: the peak cut's cap, set per cycle
|
||||
self.sent_at = None # EV-21: when `sent_a` went out
|
||||
|
||||
def owe_start(self) -> None:
|
||||
"""C1: the add-on starts in Off while an exit 0 A of its own was still
|
||||
@@ -805,6 +843,7 @@ class SolarWriter(ManualWriter):
|
||||
the write goes out, so a write cancelled while it waits for its
|
||||
read-back is never trusted (`live`)."""
|
||||
self.sent_a, self.taken = float(a), False
|
||||
self.sent_at = now # EV-21: a lowering on its way
|
||||
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
|
||||
@@ -866,7 +905,10 @@ class SolarWriter(ManualWriter):
|
||||
self.sent_a = want # it already stands
|
||||
self._adopt(cur)
|
||||
return
|
||||
if want <= TOL_A:
|
||||
cut = (self.cut_a is not None and want <= self.cut_a + TOL_A
|
||||
and self.sent_a is not None and want < self.sent_a - TOL_A)
|
||||
if want <= TOL_A or cut:
|
||||
# A new 0 A, or EV-21's new lower cut value: its own tries, at once.
|
||||
self.fails, self.fail_at, self.gave_up = 0, None, False
|
||||
elif self.gave_up or (self.fail_at is not None
|
||||
and now - self.fail_at < RETRY_S):
|
||||
@@ -947,7 +989,7 @@ class SolarWriter(ManualWriter):
|
||||
auto=sun.auto and not self.single and not self.phases_gave_up,
|
||||
clamp=clamp, start_s=sun.start_s, pause_s=sun.pause_s,
|
||||
gap_ok=gap_ok, unknown_s=getattr(sun, "unknown_s", 0.0),
|
||||
meter_back=getattr(sun, "meter_back", False))
|
||||
meter_back=getattr(sun, "meter_back", False), cap=self.cut_a)
|
||||
|
||||
@staticmethod
|
||||
def _drawing(r) -> bool:
|
||||
@@ -970,9 +1012,12 @@ class SolarWriter(ManualWriter):
|
||||
new phases and for the phases the charger reports, so nothing meant
|
||||
for 1 phase is ever written on 3 (review round 1, Major 1)."""
|
||||
def want(q):
|
||||
if "close_a" in q:
|
||||
return q["close_a"] # one value per sequence, its retries too
|
||||
q["close_a"] = a = self._close_a(q, clamp, n_reported)
|
||||
if "close_a" not in q:
|
||||
q["close_a"] = self._close_a(q, clamp, n_reported)
|
||||
a = q["close_a"] # one value per sequence, its retries too
|
||||
cap = self.cut_a # EV-21: never above a peak cut's cap
|
||||
if cap is not None and cap >= CH.MIN_A and a > cap:
|
||||
q["close_a"] = a = float(cap)
|
||||
return a
|
||||
return want
|
||||
|
||||
|
||||
Reference in New Issue
Block a user