From dbe4f591dc0885bf9b5cbfb48526514b8aaac948 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Mon, 30 Dec 2024 18:38:23 -0600 Subject: [PATCH] New GM Pedal Tune (#122) Contains changes for the pedal interceptor that fixes oscillation at low speeds. Upload Friendly --- opendbc_repo/opendbc/car/gm/carcontroller.py | 14 ++++++-------- opendbc_repo/opendbc/car/gm/carstate.py | 2 +- opendbc_repo/opendbc/car/gm/interface.py | 8 ++++---- panda/board/safety/safety_gm.h | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/opendbc_repo/opendbc/car/gm/carcontroller.py b/opendbc_repo/opendbc/car/gm/carcontroller.py index 6712b9368fb690..e481258792e6f2 100644 --- a/opendbc_repo/opendbc/car/gm/carcontroller.py +++ b/opendbc_repo/opendbc/car/gm/carcontroller.py @@ -41,16 +41,14 @@ def __init__(self, dbc_names, CP): self.packer_ch = CANPacker(DBC[self.CP.carFingerprint][Bus.chassis]) @staticmethod - def calc_pedal_command(accel: float, long_active: bool) -> float: + def calc_pedal_command(accel: float, long_active: bool, car_velocity) -> float: if not long_active: return 0. - zero = 0.15625 # 40/256 - if accel > 0.: - # Scales the accel from 0-1 to 0.156-1 - pedal_gas = clip(((1 - zero) * accel + zero), 0., 1.) + if accel < -0.5: + pedal_gas = 0 else: - # if accel is negative, -0.1 -> 0.015625 - pedal_gas = clip(zero + accel, 0., zero) # Make brake the same size as gas, but clip to regen + pedaloffset = interp(car_velocity, [0., 3, 6, 30], [0.10, 0.175, 0.240, 0.240]) + pedal_gas = clip((pedaloffset + accel * 0.6), 0.0, 1.0) return pedal_gas @@ -128,7 +126,7 @@ def update(self, CC, CS, now_nanos): self.apply_gas = self.params.INACTIVE_REGEN if self.CP.carFingerprint in CC_ONLY_CAR: # gas interceptor only used for full long control on cars without ACC - interceptor_gas_cmd = self.calc_pedal_command(actuators.accel, CC.longActive) + interceptor_gas_cmd = self.calc_pedal_command(actuators.accel, CC.longActive, CS.out.vEgo) if self.CP.enableGasInterceptorDEPRECATED and self.apply_gas > self.params.INACTIVE_REGEN and CS.out.cruiseState.standstill: # "Tap" the accelerator pedal to re-engage ACC diff --git a/opendbc_repo/opendbc/car/gm/carstate.py b/opendbc_repo/opendbc/car/gm/carstate.py index 468dd96c7aba3d..df03d769fea55f 100644 --- a/opendbc_repo/opendbc/car/gm/carstate.py +++ b/opendbc_repo/opendbc/car/gm/carstate.py @@ -97,7 +97,7 @@ def update(self, can_parsers) -> structs.CarState: if self.CP.enableGasInterceptorDEPRECATED: ret.gas = (pt_cp.vl["GAS_SENSOR"]["INTERCEPTOR_GAS"] + pt_cp.vl["GAS_SENSOR"]["INTERCEPTOR_GAS2"]) / 2. - threshold = 15 if self.CP.carFingerprint in CAMERA_ACC_CAR else 4 + threshold = 20 if self.CP.carFingerprint in CAMERA_ACC_CAR else 4 ret.gasPressed = ret.gas > threshold else: ret.gas = pt_cp.vl["AcceleratorPedal2"]["AcceleratorPedal2"] / 254. diff --git a/opendbc_repo/opendbc/car/gm/interface.py b/opendbc_repo/opendbc/car/gm/interface.py index 12d4438603af3e..646df28fffda72 100755 --- a/opendbc_repo/opendbc/car/gm/interface.py +++ b/opendbc_repo/opendbc/car/gm/interface.py @@ -90,7 +90,7 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime else: ret.transmissionType = TransmissionType.automatic - ret.longitudinalTuning.kiBP = [5., 35.] + ret.longitudinalTuning.kiBP = [5., 35., 60.] if candidate in (CAMERA_ACC_CAR | SDGM_CAR): ret.experimentalLongitudinalAvailable = candidate not in SDGM_CAR @@ -232,9 +232,9 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime ret.flags |= GMFlags.PEDAL_LONG.value ret.safetyConfigs[0].safetyParam |= Panda.FLAG_GM_PEDAL_LONG # Note: Low speed, stop and go not tested. Should be fairly smooth on highway - ret.longitudinalTuning.kiBP = [0.0, 5., 35.] - ret.longitudinalTuning.kiV = [0.0, 0.35, 0.5] - ret.longitudinalTuning.kf = 0.15 + ret.longitudinalTuning.kiBP = [0., 3., 6., 35.] + ret.longitudinalTuning.kiV = [0.125, 0.175, 0.225, 0.33] + ret.longitudinalTuning.kf = 0.25 ret.stoppingDecelRate = 0.8 else: # Pedal used for SNG, ACC for longitudinal control otherwise ret.safetyConfigs[0].safetyParam |= Panda.FLAG_GM_HW_CAM_LONG diff --git a/panda/board/safety/safety_gm.h b/panda/board/safety/safety_gm.h index a4a2ae4493b5a2..4fb74b107a0b19 100644 --- a/panda/board/safety/safety_gm.h +++ b/panda/board/safety/safety_gm.h @@ -30,7 +30,7 @@ static void gm_rx_hook(const CANPacket_t *to_push) { const int GM_STANDSTILL_THRSLD = 10; // 0.311kph // panda interceptor threshold needs to be equivalent to openpilot threshold to avoid controls mismatches // If thresholds are mismatched then it is possible for panda to see the gas fall and rise while openpilot is in the pre-enabled state - const int GM_GAS_INTERCEPTOR_THRESHOLD = 515; // (675 + 355) / 2 ratio between offset and gain from dbc file + const int GM_GAS_INTERCEPTOR_THRESHOLD = 550; // (675 + 355) / 2 ratio between offset and gain from dbc file #define GM_GET_INTERCEPTOR(msg) (((GET_BYTE((msg), 0) << 8) + GET_BYTE((msg), 1) + (GET_BYTE((msg), 2) << 8) + GET_BYTE((msg), 3)) / 2U) // avg between 2 tracks