Skip to content

Commit

Permalink
New GM Pedal Tune (#122)
Browse files Browse the repository at this point in the history
Contains changes for the pedal interceptor that fixes oscillation at low speeds. Upload Friendly
  • Loading branch information
firestar5683 authored and nworb-cire committed Dec 31, 2024
1 parent 0f0a2a9 commit dbe4f59
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
14 changes: 6 additions & 8 deletions opendbc_repo/opendbc/car/gm/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion opendbc_repo/opendbc/car/gm/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions opendbc_repo/opendbc/car/gm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion panda/board/safety/safety_gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

1 comment on commit dbe4f59

@geniuth2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, my pedal tune is merged. The acceleration and deceleration profiles are accurately matched with the plot, and it has been verified by many Bolt users in Korea, so it should be usable.

Please sign in to comment.