From c49b4ec228acdbd59f22a50d05e0723bc6b5d17a Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Sun, 3 May 2026 23:02:28 -0500 Subject: [PATCH] hurdy gurdy --- .../opendbc/car/honda/tests/test_honda.py | 10 ++++++ opendbc_repo/opendbc/car/interfaces.py | 13 ++++++-- selfdrive/controls/lib/latcontrol_torque.py | 9 +++++ selfdrive/controls/tests/test_latcontrol.py | 33 ++++++++++++++++++- 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/opendbc_repo/opendbc/car/honda/tests/test_honda.py b/opendbc_repo/opendbc/car/honda/tests/test_honda.py index 01aefeeea..a9c88e452 100644 --- a/opendbc_repo/opendbc/car/honda/tests/test_honda.py +++ b/opendbc_repo/opendbc/car/honda/tests/test_honda.py @@ -140,6 +140,16 @@ class TestHondaFingerprint: assert list(CP.lateralTuning.pid.kpV) == pytest.approx([0.8]) assert list(CP.lateralTuning.pid.kiV) == pytest.approx([0.24]) + def test_modified_civic_b_testing_ground_forces_torque(self, monkeypatch): + toggles = SimpleNamespace(force_torque_controller=False, nnff=False, nnff_lite=False) + car_fw = [CarParams.CarFw(ecu=CarParams.Ecu.eps, fwVersion=b'39990-TGG,A020\x00\x00', address=0x18DA30F1, subAddress=0)] + monkeypatch.setattr("openpilot.starpilot.common.testing_grounds.testing_ground.use", lambda slot_id, variant="B": slot_id == "8" and variant == "B") + + CP = CarInterface.get_params(CAR.HONDA_CIVIC_BOSCH, gen_empty_fingerprint(), car_fw, False, False, False, toggles) + + assert CP.flags & HondaFlags.EPS_MODIFIED + assert CP.lateralTuning.which() == "torque" + def test_honda_clarity_supports_pid_and_torque_paths(self): pid_toggles = SimpleNamespace(force_torque_controller=False, nnff=False, nnff_lite=False) car_fw = [CarParams.CarFw(ecu=CarParams.Ecu.eps, fwVersion=b'39990-TRW,A020\x00\x00', address=0x18DA30F1, subAddress=0)] diff --git a/opendbc_repo/opendbc/car/interfaces.py b/opendbc_repo/opendbc/car/interfaces.py index 73f24189d..c6110fb02 100644 --- a/opendbc_repo/opendbc/car/interfaces.py +++ b/opendbc_repo/opendbc/car/interfaces.py @@ -18,7 +18,7 @@ from opendbc.car.common.basedir import BASEDIR from opendbc.car.common.conversions import Conversions as CV from opendbc.car.common.simple_kalman import KF1D, get_kalman_gain from opendbc.car.gm.values import CAR as GM -from opendbc.car.honda.values import CAR as HONDA, HONDA_BOSCH, HONDA_CAMERA_MESSAGE_CARS, HondaSafetyFlags, HondaStarPilotFlags +from opendbc.car.honda.values import CAR as HONDA, HONDA_BOSCH, HONDA_CAMERA_MESSAGE_CARS, HondaFlags, HondaSafetyFlags, HondaStarPilotFlags from opendbc.car.hyundai.hyundaicanfd import CanBus from opendbc.car.hyundai.values import CAR as HYUNDAI, CANFD_CAR, HyundaiFlags, HyundaiStarPilotFlags, HyundaiStarPilotSafetyFlags from opendbc.car.mock.values import CAR as MOCK @@ -26,6 +26,7 @@ from opendbc.car.toyota.values import CAR as TOYOTA, NO_DSU_CAR, TSS2_CAR, UNSUP from opendbc.car.values import PLATFORMS from opendbc.can import CANParser from openpilot.common.params import Params +from openpilot.starpilot.common.testing_grounds import testing_ground GearShifter = structs.CarState.GearShifter ButtonType = structs.CarState.ButtonEvent.Type @@ -182,7 +183,15 @@ class CarInterfaceBase(ABC): ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront, ret.tireStiffnessFactor) toggles_to_check = ("force_torque_controller", "nnff", "nnff_lite") - if ret.steerControlType != structs.CarParams.SteerControlType.angle and any(getattr(starpilot_toggles, toggle, False) for toggle in toggles_to_check): + modified_civic_b_force_torque = ( + candidate == HONDA.HONDA_CIVIC_BOSCH and + bool(ret.flags & HondaFlags.EPS_MODIFIED) and + testing_ground.use("8", "B") + ) + if ret.steerControlType != structs.CarParams.SteerControlType.angle and ( + any(getattr(starpilot_toggles, toggle, False) for toggle in toggles_to_check) or + modified_civic_b_force_torque + ): CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning) return ret diff --git a/selfdrive/controls/lib/latcontrol_torque.py b/selfdrive/controls/lib/latcontrol_torque.py index a334693d8..c3f0d4849 100644 --- a/selfdrive/controls/lib/latcontrol_torque.py +++ b/selfdrive/controls/lib/latcontrol_torque.py @@ -4,6 +4,7 @@ from collections import deque from cereal import log from opendbc.car.gm.values import CAR as GM_CAR +from opendbc.car.honda.values import CAR as HONDA_CAR, HondaFlags from opendbc.car.hyundai.values import CAR as HYUNDAI_CAR from opendbc.car.lateral import get_friction from openpilot.common.constants import ACCELERATION_DUE_TO_GRAVITY, CV @@ -45,6 +46,7 @@ DEADZONE_BOOST_LAT_ACCEL = 0.15 UNWIND_D_DES_THRESHOLD = -1.0 UNWIND_LAT_ACCEL_NEAR_ZERO = 0.3 MIN_LATERAL_CONTROL_SPEED = 0.3 +CIVIC_BOSCH_MODIFIED_B_FIXED_FRICTION_THRESHOLD = 0.30 BOLT_2022_2023_CARS = ( GM_CAR.CHEVROLET_BOLT_ACC_2022_2023, @@ -317,6 +319,10 @@ def get_friction_threshold(v_ego: float) -> float: return float(np.interp(v_ego, [1 * CV.MPH_TO_MS, 20 * CV.MPH_TO_MS, 75 * CV.MPH_TO_MS], [0.16, 0.19, 0.27])) +def civic_bosch_modified_lateral_testing_ground_active() -> bool: + return testing_ground.use("8", "B") + + def bolt_2017_lateral_testing_ground_active() -> bool: return testing_ground.use(BOLT_2017_LATERAL_TESTING_GROUND_ID) @@ -965,6 +971,7 @@ class LatControlTorque(LatControl): self.is_genesis_g90 = CP.carFingerprint in GENESIS_G90_CARS self.is_ioniq_6 = CP.carFingerprint in IONIQ_6_CARS self.is_kia_ev6 = CP.carFingerprint in KIA_EV6_CARS + self.is_civic_bosch_modified = CP.carFingerprint == HONDA_CAR.HONDA_CIVIC_BOSCH and bool(CP.flags & HondaFlags.EPS_MODIFIED) self.is_volt_cc = CP.carFingerprint == GM_CAR.CHEVROLET_VOLT_CC self.is_silverado = CP.carFingerprint == GM_CAR.CHEVROLET_SILVERADO self.use_bolt_ff_scaling = self.is_bolt_2022_2023 or self.is_bolt_2018_2021 or self.is_bolt_2017 @@ -1087,6 +1094,8 @@ class LatControlTorque(LatControl): ff *= get_volt_plexy_ff_scale(setpoint, desired_lateral_jerk, CS.vEgo) friction_threshold = get_volt_plexy_friction_threshold(CS.vEgo, setpoint, desired_lateral_jerk) friction_scale = get_volt_plexy_friction_scale(CS.vEgo, setpoint, desired_lateral_jerk) + elif self.is_civic_bosch_modified and civic_bosch_modified_lateral_testing_ground_active(): + friction_threshold = CIVIC_BOSCH_MODIFIED_B_FIXED_FRICTION_THRESHOLD ff += friction_scale * get_friction(error_with_lsf + JERK_GAIN * desired_lateral_jerk, lateral_accel_deadzone, friction_threshold, self.torque_params) deadzone_boost_active = False if self.torque_deadzone_boost > 0.0 and abs(gravity_adjusted_future_lateral_accel) < DEADZONE_BOOST_LAT_ACCEL: diff --git a/selfdrive/controls/tests/test_latcontrol.py b/selfdrive/controls/tests/test_latcontrol.py index e9f9d4463..8e673fb49 100644 --- a/selfdrive/controls/tests/test_latcontrol.py +++ b/selfdrive/controls/tests/test_latcontrol.py @@ -6,7 +6,7 @@ from cereal import car, custom, log import openpilot.selfdrive.controls.lib.latcontrol_torque as latcontrol_torque import openpilot.selfdrive.controls.lib.latcontrol_pid as latcontrol_pid from opendbc.car.car_helpers import interfaces -from opendbc.car.honda.values import CAR as HONDA +from opendbc.car.honda.values import CAR as HONDA, HondaFlags from opendbc.car.toyota.values import CAR as TOYOTA from opendbc.car.nissan.values import CAR as NISSAN from opendbc.car.gm.values import CAR as GM @@ -377,6 +377,37 @@ class TestLatControl: assert tapered_output == pytest.approx(base_output) + def test_modified_civic_b_torque_path_uses_fixed_friction_threshold(self, monkeypatch): + CarInterface = interfaces[HONDA.HONDA_CIVIC_BOSCH] + CP = CarInterface.get_non_essential_params(HONDA.HONDA_CIVIC_BOSCH) + CP.flags |= int(HondaFlags.EPS_MODIFIED) + CP.lateralTuning.init("torque") + CI = CarInterface(CP, custom.StarPilotCarParams.new_message()) + controller = LatControlTorque(CP.as_reader(), CI, DT_CTRL) + VM = VehicleModel(CP) + + CS = car.CarState.new_message() + CS.vEgo = 12 + CS.steeringPressed = False + CS.steeringAngleDeg = 1.0 + + params = log.LiveParametersData.new_message() + params.steerRatio = CP.steerRatio + params.stiffnessFactor = 1.0 + params.roll = 0.0 + params.angleOffsetDeg = 0.0 + + captured = {} + def fake_get_friction(_error, _deadzone, friction_threshold, _torque_params): + captured["threshold"] = friction_threshold + return 0.0 + + monkeypatch.setattr(latcontrol_torque, "civic_bosch_modified_lateral_testing_ground_active", lambda: True) + monkeypatch.setattr(latcontrol_torque, "get_friction", fake_get_friction) + controller.update(True, CS, VM, params, False, 0.0025, False, 0.2, None, None, SimpleNamespace()) + + assert captured["threshold"] == pytest.approx(0.3) + def test_kia_ev6_testing_ground_update_path(self, monkeypatch): controller, VM, CS, params, starpilot_toggles = self._build_torque_controller(HYUNDAI.KIA_EV6) monkeypatch.setattr(latcontrol_torque, "kia_ev6_lateral_testing_ground_active", lambda: True)