From cb85aae9c07c5a113afcaec900d994cd36830447 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Sat, 28 Nov 2026 15:24:07 -0600 Subject: [PATCH] Preserve Immediate End to End Speed Reductions --- .../selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py | 4 ++-- openpilot/selfdrive/controls/lib/longitudinal_planner.py | 2 +- openpilot/starpilot/longitudinal/tests/test_encouragement.py | 1 + .../starpilot/longitudinal/tests/test_highlander_cruise.py | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py b/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py index d9803b1cf7..47c23c8c90 100755 --- a/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py +++ b/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py @@ -234,8 +234,8 @@ class ModelLeadHistory: lead = model.leadsV3[index] if any(len(getattr(lead, field)) != len(LEAD_T_IDXS_MODEL) for field in ('x', 'y', 'v', 't')): return - leads.append(LeadHorizon(float(lead.prob), *(tuple(float(v) for v in getattr(lead, field)) for field in ('x', 'y', 'v', 't')), - tuple(float(v) for v in lead.a))) + leads.append(LeadHorizon(prob=float(lead.prob), x=tuple(map(float, lead.x)), y=tuple(map(float, lead.y)), + v=tuple(map(float, lead.v)), t=tuple(map(float, lead.t)), a=tuple(map(float, lead.a)))) self.frames[stamp] = ModelHorizon(stamp, receipt, int(model.timestampEof), HorizonVelocity((float(model.velocity.x[0]),)), tuple(leads)) while len(self.frames) > 4: diff --git a/openpilot/selfdrive/controls/lib/longitudinal_planner.py b/openpilot/selfdrive/controls/lib/longitudinal_planner.py index 9c9e941b31..19f3e03d3b 100755 --- a/openpilot/selfdrive/controls/lib/longitudinal_planner.py +++ b/openpilot/selfdrive/controls/lib/longitudinal_planner.py @@ -117,7 +117,7 @@ def get_cruise_accel(e2e, v_cruise, v_ego, a_cruise_prev, angle_steers, CP, dt, speed_error /= np.interp(speed_error, [.5, 1.5], [CRUISE_ACCEL_RESPONSE_TIME, 1.0]) elif ease_slc_braking and speed_error < 0.: speed_error /= CRUISE_ACCEL_RESPONSE_TIME # correct an SLC overshoot as gradually as an approach - if e2e and not (faster_takeoffs or speed_step or ease_slc_braking or gentle_settle or downhill_error is not None): + if e2e and speed_error > 0. and not (faster_takeoffs or speed_step or ease_slc_braking or gentle_settle or downhill_error is not None): speed_error = smooth_value(speed_error, a_cruise_prev, tau=1.0, dt=dt) target_accel = np.clip(speed_error, cruise_min, max_accel) j_cruise = np.interp(v_ego, A_CRUISE_MAX_BP, J_CRUISE_VALS) diff --git a/openpilot/starpilot/longitudinal/tests/test_encouragement.py b/openpilot/starpilot/longitudinal/tests/test_encouragement.py index 146bc9a64c..5ef4e6f229 100644 --- a/openpilot/starpilot/longitudinal/tests/test_encouragement.py +++ b/openpilot/starpilot/longitudinal/tests/test_encouragement.py @@ -29,6 +29,7 @@ def frame(tick): now = NOW + tick * 50_000_000 sm.logMonoTime = dict.fromkeys(sm, now - 5_000_000) sm['selfdriveState'].experimentalMode = True + sm['selfdriveState'].personality = "relaxed" sm['modelV2'].action.desiredAcceleration = 0. sm['modelV2'].action.shouldStop = False sm['radarState'].leadOne.present = sm['radarState'].leadTwo.present = False diff --git a/openpilot/starpilot/longitudinal/tests/test_highlander_cruise.py b/openpilot/starpilot/longitudinal/tests/test_highlander_cruise.py index 81a629c1fb..42de80b920 100644 --- a/openpilot/starpilot/longitudinal/tests/test_highlander_cruise.py +++ b/openpilot/starpilot/longitudinal/tests/test_highlander_cruise.py @@ -180,7 +180,7 @@ def test_optional_solver_failure_withdraws_to_existing_cruise_path(monkeypatch): assert owner.output_a_target == pytest.approx(owner.a_cruise) -def test_native_run_exposes_failure_while_preserving_existing_reset(): +def test_native_run_exposes_failure_while_preserving_existing_reset(monkeypatch): from openpilot.selfdrive.controls.lib.longitudinal_mpc_lib.long_mpc import LongitudinalMpc native = LongitudinalMpc() original = native.solver @@ -190,7 +190,7 @@ def test_native_run_exposes_failure_while_preserving_existing_reset(): def solve(self): original.solve() return 1 - native.solver = FailedSolve() + monkeypatch.setattr(native, "solver", FailedSolve()) assert native.run() == 1 assert native.solution_status == 0 assert np.all(native.a_solution == 0.)