Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New GM Pedal Tune #122

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
nworb-cire marked this conversation as resolved.
Show resolved Hide resolved
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])
nworb-cire marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -222,9 +222,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
Loading