diff --git a/common/params.cc b/common/params.cc index 082015b2d..e50bf754c 100644 --- a/common/params.cc +++ b/common/params.cc @@ -275,6 +275,7 @@ std::unordered_map keys = { {"FrogsGoMoo", PERSISTENT}, {"FrogsGoMooTune", PERSISTENT}, {"FullMap", PERSISTENT}, + {"GasRegenCmd", PERSISTENT}, {"GoatScream", PERSISTENT}, {"HideAOLStatusBar", PERSISTENT}, {"HideCEMStatusBar", PERSISTENT}, diff --git a/opendbc/gm_global_a_powertrain_generated.dbc b/opendbc/gm_global_a_powertrain_generated.dbc index 5d03286d1..3b40d9329 100644 --- a/opendbc/gm_global_a_powertrain_generated.dbc +++ b/opendbc/gm_global_a_powertrain_generated.dbc @@ -214,15 +214,14 @@ BO_ 711 BECMBatteryVoltageCurrent: 6 K17_EBCM SG_ HVBatteryCurrent : 12|13@0- (0.15,0) [-614.4|614.25] "A" NEO BO_ 715 ASCMGasRegenCmd: 8 K124_ASCM - SG_ GasRegenAlwaysOne2 : 9|1@0+ (1,0) [0|1] "" NEO - SG_ GasRegenAlwaysOne : 14|1@0+ (1,0) [0|1] "" NEO - SG_ GasRegenChecksum : 47|24@0+ (1,0) [0|0] "" NEO - SG_ GasRegenCmdActiveInv : 32|1@0+ (1,0) [0|0] "" NEO - 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 : 22|12@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_ GasRegenCmd : 8|14@0+ (1,0) [0|0] "" NEO + SG_ GasRegenAlwaysOne2 : 9|1@0+ (1,0) [0|1] "" NEO + SG_ GasRegenFullStopActive : 13|1@0+ (1,0) [0|0] "" NEO + SG_ GasRegenAlwaysOne : 14|1@0+ (1,0) [0|1] "" NEO + SG_ GasRegenCmdActiveInv : 32|1@0+ (1,0) [0|0] "" NEO + SG_ GasRegenChecksum : 47|24@0+ (1,0) [0|0] "" NEO BO_ 717 ASCM_2CD: 5 K124_ASCM diff --git a/panda/board/safety/safety_gm.h b/panda/board/safety/safety_gm.h index 4ff207a86..f9779c0a3 100644 --- a/panda/board/safety/safety_gm.h +++ b/panda/board/safety/safety_gm.h @@ -18,8 +18,8 @@ const LongitudinalLimits GM_ASCM_LONG_LIMITS = { const LongitudinalLimits GM_ASCM_LONG_LIMITS_SPORT = { .max_gas = 8191, - .min_gas = 1404, - .inactive_gas = 1404, + .min_gas = 5500, + .inactive_gas = 5500, .max_brake = 400, }; @@ -32,8 +32,8 @@ const LongitudinalLimits GM_CAM_LONG_LIMITS = { const LongitudinalLimits GM_CAM_LONG_LIMITS_SPORT = { .max_gas = 8848, - .min_gas = 1514, - .inactive_gas = 1554, + .min_gas = 5610, + .inactive_gas = 5650, .max_brake = 400, }; @@ -202,7 +202,7 @@ static bool gm_tx_hook(const CANPacket_t *to_send) { // GAS/REGEN: safety check if (addr == 0x2CB) { bool apply = GET_BIT(to_send, 0U); - int gas_regen = ((GET_BYTE(to_send, 2) & 0x7FU) << 5) + ((GET_BYTE(to_send, 3) & 0xF8U) >> 3); + int gas_regen = ((GET_BYTE(to_send, 1) & 0x1U) << 13) + ((GET_BYTE(to_send, 2) & 0xFFU) << 5) + ((GET_BYTE(to_send, 3) & 0xF8U) >> 3); bool violation = false; // Allow apply bit in pre-enabled and overriding states diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index 18f8ed1f5..179d8e100 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -8,7 +8,7 @@ from openpilot.common.basedir import BASEDIR from openpilot.common.conversions import Conversions as CV from openpilot.selfdrive.car import create_button_events, get_safety_config from openpilot.selfdrive.car.gm.radar_interface import RADAR_HEADER_MSG -from openpilot.selfdrive.car.gm.values import CAR, CruiseButtons, CarControllerParams, EV_CAR, CAMERA_ACC_CAR, CanBus, GMFlags, CC_ONLY_CAR, SDGM_CAR +from openpilot.selfdrive.car.gm.values import CAR, CruiseButtons, CarControllerParams, EV_CAR, CAMERA_ACC_CAR, CanBus, GMFlags, CC_ONLY_CAR, SDGM_CAR, SLOW_ACC from openpilot.selfdrive.car.interfaces import CarInterfaceBase, TorqueFromLateralAccelCallbackType, FRICTION_THRESHOLD, LatControlInputs, NanoFFModel from openpilot.selfdrive.controls.lib.drive_helpers import get_friction @@ -124,6 +124,10 @@ class CarInterface(CarInterfaceBase): ret.vEgoStopping = 0.25 ret.vEgoStarting = 0.25 + if candidate in SLOW_ACC and params.get_bool("GasRegenCmd"): + ret.longitudinalTuning.kpV = [1.5, 1.125] + ret.stopAccel = -0.25 + if experimental_long: ret.pcmCruise = False ret.openpilotLongitudinalControl = True diff --git a/selfdrive/car/gm/values.py b/selfdrive/car/gm/values.py index bfb8504fc..643beba03 100644 --- a/selfdrive/car/gm/values.py +++ b/selfdrive/car/gm/values.py @@ -36,18 +36,23 @@ class CarControllerParams: def __init__(self, CP): # Gas/brake lookups - self.ZERO_GAS = 2048 # Coasting + self.ZERO_GAS = 6144 # Coasting self.MAX_BRAKE = 400 # ~ -4.0 m/s^2 with regen if CP.carFingerprint in CAMERA_ACC_CAR and CP.carFingerprint not in CC_ONLY_CAR: - self.MAX_GAS = 3400 + self.MAX_GAS = 7496 self.MAX_GAS_PLUS = 8848 - self.MAX_ACC_REGEN = 1514 - self.INACTIVE_REGEN = 1554 + self.MAX_ACC_REGEN = 5610 + self.INACTIVE_REGEN = 5650 # Camera ACC vehicles have no regen while enabled. # Camera transitions to MAX_ACC_REGEN from ZERO_GAS and uses friction brakes instantly max_regen_acceleration = 0. + if CP.carFingerprint in SLOW_ACC and Params().get_bool("GasRegenCmd"): + self.MAX_GAS = 8650 + self.MAX_GAS_PLUS = 8650 # Don't Stack Extra Speed + self.ACCEL_MAX_PLUS = 2 + elif CP.carFingerprint in SDGM_CAR: self.MAX_GAS = 7496 self.MAX_GAS_PLUS = 8848 @@ -56,10 +61,10 @@ class CarControllerParams: max_regen_acceleration = 0. else: - self.MAX_GAS = 3072 # Safety limit, not ACC max. Stock ACC >4096 from standstill. + self.MAX_GAS = 7168 # Safety limit, not ACC max. Stock ACC >8192 from standstill. self.MAX_GAS_PLUS = 8191 # 8292 uses new bit, possible but not tested. Matches Twilsonco tw-main max - self.MAX_ACC_REGEN = 1404 # Max ACC regen is slightly less than max paddle regen - self.INACTIVE_REGEN = 1404 + self.MAX_ACC_REGEN = 5500 # Max ACC regen is slightly less than max paddle regen + self.INACTIVE_REGEN = 5500 # ICE has much less engine braking force compared to regen in EVs, # lower threshold removes some braking deadzone max_regen_acceleration = -1. if CP.carFingerprint in EV_CAR else -0.1 @@ -315,6 +320,9 @@ CC_ONLY_CAR = {CAR.VOLT_CC, CAR.BOLT_CC, CAR.EQUINOX_CC, CAR.SUBURBAN_CC, CAR.YU # We're integrated at the Safety Data Gateway Module on these cars SDGM_CAR = {CAR.XT4, CAR.BABYENCLAVE} +# Slow acceleration cars +SLOW_ACC = {CAR.SILVERADO} + # We're integrated at the camera with VOACC on these cars (instead of ASCM w/ OBD-II harness) CAMERA_ACC_CAR = {CAR.BOLT_EUV, CAR.SILVERADO, CAR.EQUINOX, CAR.TRAILBLAZER} CAMERA_ACC_CAR.update({CAR.VOLT_CC, CAR.BOLT_CC, CAR.EQUINOX_CC, CAR.YUKON_CC, CAR.CT6_CC, CAR.TRAILBLAZER_CC}) diff --git a/selfdrive/frogpilot/ui/qt/offroad/vehicle_settings.cc b/selfdrive/frogpilot/ui/qt/offroad/vehicle_settings.cc index 8539e4e77..fd103115b 100644 --- a/selfdrive/frogpilot/ui/qt/offroad/vehicle_settings.cc +++ b/selfdrive/frogpilot/ui/qt/offroad/vehicle_settings.cc @@ -113,6 +113,7 @@ FrogPilotVehiclesPanel::FrogPilotVehiclesPanel(SettingsWindow *parent) : FrogPil std::vector> vehicleToggles { {"LongPitch", tr("Long Pitch Compensation"), tr("Smoothen out the gas and pedal controls."), ""}, + {"GasRegenCmd", tr("Truck Tune"), tr("Increase the acceleration and smoothen out the brake control when coming to a stop. For use on Silverado/Sierra only."), ""}, {"LongitudinalTune", tr("Longitudinal Tune"), tr("Use a custom Toyota longitudinal tune.\n\nCydia = More focused on TSS-P vehicles but works for all Toyotas\n\nDragonPilot = Focused on TSS2 vehicles\n\nFrogPilot = Takes the best of both worlds with some personal tweaks focused around FrogsGoMoo's 2019 Lexus ES 350"), ""}, }; @@ -154,7 +155,7 @@ FrogPilotVehiclesPanel::FrogPilotVehiclesPanel(SettingsWindow *parent) : FrogPil }); } - std::set rebootKeys = {}; + std::set rebootKeys = {"GasRegenCmd"}; for (const QString &key : rebootKeys) { QObject::connect(toggles[key.toStdString().c_str()], &ToggleControl::toggleFlipped, [this]() { if (started) { @@ -248,9 +249,9 @@ void FrogPilotVehiclesPanel::hideToggles() { bool toyota = carMake == "Lexus" || carMake == "Toyota"; std::set evCarKeys = {}; - std::set gmTruckKeys = {}; + std::set gmTruckKeys = {"GasRegenCmd"}; std::set imprezaKeys = {}; - std::set longitudinalKeys = {"LongitudinalTune", "LongPitch"}; + std::set longitudinalKeys = {"GasRegenCmd", "LongitudinalTune", "LongPitch"}; std::set sngKeys = {}; for (auto &[key, toggle] : toggles) { diff --git a/selfdrive/frogpilot/ui/qt/offroad/vehicle_settings.h b/selfdrive/frogpilot/ui/qt/offroad/vehicle_settings.h index 78ef14933..60e393d8c 100644 --- a/selfdrive/frogpilot/ui/qt/offroad/vehicle_settings.h +++ b/selfdrive/frogpilot/ui/qt/offroad/vehicle_settings.h @@ -29,7 +29,7 @@ private: QString carMake; QStringList models; - std::set gmKeys = {"LongPitch"}; + std::set gmKeys = {"GasRegenCmd", "LongPitch"}; std::set subaruKeys = {}; std::set toyotaKeys = {"LongitudinalTune"};