From eee41cbf770bc5803ff9ddfc2472e1be084c7f2c Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Sat, 13 Dec 2025 18:41:16 -0600 Subject: [PATCH] Torque Rest of Fleet --- opendbc/gm_global_a_powertrain_generated.dbc | 1 - selfdrive/car/gm/carcontroller.py | 58 ++++++++++++++------ selfdrive/car/gm/gmcan.py | 1 - selfdrive/car/gm/interface.py | 4 +- selfdrive/car/gm/values.py | 11 +--- 5 files changed, 46 insertions(+), 29 deletions(-) diff --git a/opendbc/gm_global_a_powertrain_generated.dbc b/opendbc/gm_global_a_powertrain_generated.dbc index aba27f0df..040e08fc6 100644 --- a/opendbc/gm_global_a_powertrain_generated.dbc +++ b/opendbc/gm_global_a_powertrain_generated.dbc @@ -232,7 +232,6 @@ BO_ 715 ASCMGasRegenCmd: 8 K124_ASCM SG_ GasRegenFullStopActive : 13|1@0+ (1,0) [0|0] "" NEO SG_ GasRegenCmdActive : 0|1@0+ (1,0) [0|0] "" NEO SG_ RollingCounter : 7|2@0+ (1,0) [0|0] "" NEO - SG_ GasRegenAlwaysOne3 : 23|1@0+ (1,0) [0|1] "" NEO SG_ GasRegenCmd : 8|14@0+ (1,0) [0|0] "" NEO BO_ 717 ASCM_2CD: 5 K124_ASCM diff --git a/selfdrive/car/gm/carcontroller.py b/selfdrive/car/gm/carcontroller.py index cf1f68280..e09fed884 100644 --- a/selfdrive/car/gm/carcontroller.py +++ b/selfdrive/car/gm/carcontroller.py @@ -49,12 +49,11 @@ class CarController(CarControllerBase): self.params = CarControllerParams(self.CP) self.is_volt = self.CP.carFingerprint in (CAR.CHEVROLET_VOLT, CAR.CHEVROLET_VOLT_ASCM, CAR.CHEVROLET_VOLT_CAMERA, CAR.CHEVROLET_VOLT_CC) - if self.is_volt: - self.mass = CP.mass - self.tireRadius = 0.075 * CP.wheelbase + 0.1453 - self.frontalArea = 1.05 * CP.wheelbase + 0.0679 - self.coeffDrag = 0.30 - self.airDensity = 1.225 + self.mass = CP.mass + self.tireRadius = 0.075 * CP.wheelbase + 0.1453 + self.frontalArea = 1.05 * CP.wheelbase + 0.0679 + self.coeffDrag = 0.30 + self.airDensity = 1.225 self.params_ = Params() self.packer_pt = CANPacker(DBC[self.CP.carFingerprint]['pt']) @@ -166,21 +165,46 @@ class CarController(CarControllerBase): accel = clip(accel, self.params.ACCEL_MIN, self.params.ACCEL_MAX) brake_accel = clip(brake_accel, self.params.ACCEL_MIN, self.params.ACCEL_MAX) - if self.CP.carFingerprint in EV_CAR: - self.params.update_ev_gas_brake_threshold(CS.out.vEgo) - self.apply_gas = int(round(interp(accel, self.params.EV_GAS_LOOKUP_BP, self.params.GAS_LOOKUP_V))) - self.apply_brake = int(round(interp(brake_accel, self.params.EV_BRAKE_LOOKUP_BP, self.params.BRAKE_LOOKUP_V))) + if self.CP.carFingerprint in EV_CAR: + self.params.update_ev_gas_brake_threshold(CS.out.vEgo) + self.apply_gas = int(round(interp(accel, self.params.EV_GAS_LOOKUP_BP, self.params.GAS_LOOKUP_V))) + self.apply_brake = int(round(interp(brake_accel, self.params.EV_BRAKE_LOOKUP_BP, self.params.BRAKE_LOOKUP_V))) + else: + self.apply_gas = int(round(interp(accel, self.params.GAS_LOOKUP_BP, self.params.GAS_LOOKUP_V))) + self.apply_brake = int(round(interp(brake_accel, self.params.BRAKE_LOOKUP_BP, self.params.BRAKE_LOOKUP_V))) + + # Clamp within message-valid ranges to avoid ASCM faults from overshoot or rounding + self.apply_gas = int(round(clip(self.apply_gas, self.params.MAX_ACC_REGEN, self.params.MAX_GAS))) + self.apply_brake = int(round(clip(self.apply_brake, 0, self.params.MAX_BRAKE))) + + if self.apply_brake > 0: + # Volt should never present positive torque alongside friction braking + self.apply_gas = self.params.INACTIVE_REGEN else: - self.apply_gas = int(round(interp(accel, self.params.GAS_LOOKUP_BP, self.params.GAS_LOOKUP_V))) + if len(CC.orientationNED) == 3 and CS.out.vEgo > self.CP.vEgoStopping: + accel_due_to_pitch = math.sin(CC.orientationNED[1]) * ACCELERATION_DUE_TO_GRAVITY + else: + accel_due_to_pitch = 0.0 + + gas_max = self.params.MAX_GAS + accel_max = self.params.ACCEL_MAX + + accel = clip(actuators.accel + accel_due_to_pitch, self.params.ACCEL_MIN, accel_max) + torque = self.tireRadius * ((self.mass * accel) + (0.5 * self.coeffDrag * self.frontalArea * self.airDensity * CS.out.vEgo ** 2)) + + scaled_torque = torque + self.params.ZERO_GAS + apply_gas_torque = clip(scaled_torque, self.params.MAX_ACC_REGEN, gas_max) + BRAKE_SWITCH = int(round(interp(CS.out.vEgo, self.params.BRAKE_SWITCH_LOOKUP_BP, self.params.BRAKE_SWITCH_LOOKUP_V))) + brake_accel = min((scaled_torque - BRAKE_SWITCH) / (self.tireRadius * self.mass), 0) + self.apply_gas = int(round(apply_gas_torque)) self.apply_brake = int(round(interp(brake_accel, self.params.BRAKE_LOOKUP_BP, self.params.BRAKE_LOOKUP_V))) - # Clamp within message-valid ranges to avoid ASCM faults from overshoot or rounding - self.apply_gas = int(round(clip(self.apply_gas, self.params.MAX_ACC_REGEN, self.params.MAX_GAS))) - self.apply_brake = int(round(clip(self.apply_brake, 0, self.params.MAX_BRAKE))) + # Clamp within message-valid ranges to avoid ASCM faults from overshoot or rounding + self.apply_gas = int(round(clip(self.apply_gas, self.params.MAX_ACC_REGEN, self.params.MAX_GAS))) + self.apply_brake = int(round(clip(self.apply_brake, 0, self.params.MAX_BRAKE))) - if self.is_volt and self.apply_brake > 0: - # Volt should never present positive torque alongside friction braking - self.apply_gas = self.params.INACTIVE_REGEN + if self.apply_brake > 0 and self.apply_gas > self.params.INACTIVE_REGEN: + self.apply_gas = self.params.INACTIVE_REGEN # Don't allow any gas above inactive regen while stopping # FIXME: brakes aren't applied immediately when enabling at a stop if stopping: diff --git a/selfdrive/car/gm/gmcan.py b/selfdrive/car/gm/gmcan.py index f2a87bae4..4594ed128 100644 --- a/selfdrive/car/gm/gmcan.py +++ b/selfdrive/car/gm/gmcan.py @@ -66,7 +66,6 @@ def create_gas_regen_command(packer, bus, throttle, idx, enabled, at_full_stop): "GasRegenFullStopActive": at_full_stop, "GasRegenAlwaysOne": 1, "GasRegenAlwaysOne2": 1, - "GasRegenAlwaysOne3": 1, } dat = packer.make_can_msg("ASCMGasRegenCmd", bus, values)[2] diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index ed505e270..e566946fd 100644 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -148,12 +148,12 @@ class CarInterface(CarInterfaceBase): ret.safetyConfigs[0].safetyParam |= Panda.FLAG_GM_HW_CAM # Tuning for experimental long - ret.longitudinalTuning.kiV = [1.0, 1.0] + ret.longitudinalTuning.kiV = [0.5, 0.5] ret.stoppingDecelRate = 1.0 # reach brake quickly after enabling ret.vEgoStopping = 0.25 ret.vEgoStarting = 0.25 - ret.stopAccel = -0.20 + ret.stopAccel = -0.25 if ret.experimentalLongitudinalAvailable and experimental_long: ret.pcmCruise = False diff --git a/selfdrive/car/gm/values.py b/selfdrive/car/gm/values.py index 2e78cb4da..6626630ca 100644 --- a/selfdrive/car/gm/values.py +++ b/selfdrive/car/gm/values.py @@ -38,9 +38,8 @@ class CarControllerParams: def __init__(self, CP): # Gas/brake lookups - self.ZERO_GAS = 6144 # Coasting + self.ZERO_GAS = 6150 # Coasting self.MAX_BRAKE = 400 # ~ -4.0 m/s^2 with regen - self.BRAKE_SWITCH_MAX = self.ZERO_GAS if CP.carFingerprint in (CAMERA_ACC_CAR | SDGM_CAR) and CP.carFingerprint not in CC_ONLY_CAR and CP.carFingerprint != CAR.CHEVROLET_BOLT_EUV: self.MAX_GAS = 7496 @@ -60,12 +59,8 @@ class CarControllerParams: # lower threshold removes some braking deadzone self.max_regen_acceleration = -1. if CP.carFingerprint in EV_CAR else -0.1 - if CP.carFingerprint in (CAR.CHEVROLET_VOLT, CAR.CHEVROLET_VOLT_ASCM, CAR.CHEVROLET_VOLT_CAMERA, CAR.CHEVROLET_VOLT_CC): - self.ZERO_GAS = 6150 - self.BRAKE_SWITCH_MAX = self.MAX_ACC_REGEN if CP.carFingerprint in EV_CAR else self.ZERO_GAS - self.BRAKE_LOOKUP_BP = [self.ACCEL_MIN, 0.] - else: - self.BRAKE_LOOKUP_BP = [self.ACCEL_MIN, self.max_regen_acceleration] + self.BRAKE_SWITCH_MAX = self.MAX_ACC_REGEN if CP.carFingerprint in EV_CAR else self.ZERO_GAS + self.BRAKE_LOOKUP_BP = [self.ACCEL_MIN, 0.] self.GAS_LOOKUP_BP = [self.max_regen_acceleration, 0., self.ACCEL_MAX] self.GAS_LOOKUP_BP_PLUS = [self.max_regen_acceleration, 0., self.ACCEL_MAX_PLUS]