From 74e1c1b4dde950ee2c307c38db6524c48175ab01 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Fri, 12 Dec 2025 01:17:12 -0600 Subject: [PATCH] EV vs Gas tuning --- common/params.cc | 1 + frogpilot/common/frogpilot_variables.py | 12 ++++++++- .../controls/lib/frogpilot_acceleration.py | 25 +++++++++++-------- .../ui/qt/offroad/longitudinal_settings.cc | 5 ++++ .../ui/qt/offroad/longitudinal_settings.h | 2 +- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/common/params.cc b/common/params.cc index 838fb45a8..d3ad9edb9 100644 --- a/common/params.cc +++ b/common/params.cc @@ -322,6 +322,7 @@ std::unordered_map keys = { {"DynamicPedalsOnUI", PERSISTENT}, {"EngageVolume", PERSISTENT}, {"ExperimentalGMTune", PERSISTENT}, + {"EVTuning", PERSISTENT}, {"Fahrenheit", PERSISTENT}, {"FavoriteDestinations", PERSISTENT | DONT_LOG}, {"FlashPanda", CLEAR_ON_MANAGER_START}, diff --git a/frogpilot/common/frogpilot_variables.py b/frogpilot/common/frogpilot_variables.py index 9f700f263..2d949a0b6 100644 --- a/frogpilot/common/frogpilot_variables.py +++ b/frogpilot/common/frogpilot_variables.py @@ -13,7 +13,8 @@ from openpilot.common.conversions import Conversions as CV from openpilot.common.params import Params from openpilot.selfdrive.car import gen_empty_fingerprint from openpilot.selfdrive.car.car_helpers import interfaces -from openpilot.selfdrive.car.gm.values import GMFlags +from openpilot.selfdrive.car.gm.values import EV_CAR as GM_EV_CAR, GMFlags +from openpilot.selfdrive.car.hyundai.values import EV_CAR as HYUNDAI_EV_CAR from openpilot.selfdrive.car.interfaces import CarInterfaceBase from openpilot.selfdrive.car.mock.interface import CarInterface from openpilot.selfdrive.car.mock.values import CAR as MOCK @@ -32,6 +33,7 @@ params_memory = Params("/dev/shm/params") GearShifter = car.CarState.GearShifter SafetyModel = car.CarParams.SafetyModel +TransmissionType = car.CarParams.TransmissionType CITY_SPEED_LIMIT = 25 # 55mph is typically the minimum speed for highways CRUISING_SPEED = 5 # Roughly the speed cars go when not touching the gas while in drive @@ -128,6 +130,7 @@ frogpilot_default_params: list[tuple[str, str | bytes, int, str]] = [ ("AdvancedCustomUI", "0", 2, "0"), ("AdvancedLateralTune", "0", 2, "0"), ("AdvancedLongitudinalTune", "0", 3, "0"), + ("EVTuning", "", 3, "0"), ("AggressiveFollow", "1.25", 2, "1.25"), ("AggressiveFollowHigh", "1.25", 2, "1.25"), ("AggressiveJerkAcceleration", "50", 3, "50"), @@ -617,6 +620,13 @@ class FrogPilotVariables: toggle.use_custom_steerRatio = bool(round(toggle.steerRatio, 2) != round(steerRatio, 2)) and not toggle.force_auto_tune or toggle.force_auto_tune_off advanced_longitudinal_tuning = params.get_bool("AdvancedLongitudinalTune") if tuning_level >= level["AdvancedLongitudinalTune"] else default.get_bool("AdvancedLongitudinalTune") + ev_vehicle = toggle.car_make == "gm" and toggle.car_model != "CHEVROLET_VOLT" and CP.carFingerprint in GM_EV_CAR or toggle.car_make == "hyundai" and CP.carFingerprint in HYUNDAI_EV_CAR + ev_vehicle |= CP.transmissionType == TransmissionType.direct + + if params.get("EVTuning") == b"": + params.put_bool("EVTuning", ev_vehicle) + + toggle.ev_tuning = params.get_bool("EVTuning") if advanced_longitudinal_tuning and tuning_level >= level["EVTuning"] else ev_vehicle toggle.longitudinalActuatorDelay = np.clip(params.get_float("LongitudinalActuatorDelay"), 0, 1) if advanced_longitudinal_tuning and tuning_level >= level["LongitudinalActuatorDelay"] else longitudinalActuatorDelay toggle.startAccel = np.clip(params.get_float("StartAccel"), 0, 4) if advanced_longitudinal_tuning and tuning_level >= level["StartAccel"] else startAccel toggle.stopAccel = np.clip(params.get_float("StopAccel"), -4, 0) if advanced_longitudinal_tuning and tuning_level >= level["StopAccel"] else stopAccel diff --git a/frogpilot/controls/lib/frogpilot_acceleration.py b/frogpilot/controls/lib/frogpilot_acceleration.py index 1a6e4179a..2c6beccd5 100644 --- a/frogpilot/controls/lib/frogpilot_acceleration.py +++ b/frogpilot/controls/lib/frogpilot_acceleration.py @@ -53,14 +53,18 @@ A_CRUISE_MIN_SPORT = A_CRUISE_MIN * 2 # MPH = [0.0, 11, 22, 34, 45, 56, 89] A_CRUISE_MAX_BP_CUSTOM = [0.0, 5., 10., 15., 20., 25., 40.] -A_CRUISE_MAX_VALS_ECO = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] -A_CRUISE_MAX_VALS_SPORT = [1.25, 1.25, 1.25, 1.25, 1.5, 1.5, 2.0] +A_CRUISE_MAX_VALS_ECO_EV = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] +A_CRUISE_MAX_VALS_SPORT_EV = [1.25, 1.25, 1.25, 1.25, 1.5, 1.5, 2.0] +A_CRUISE_MAX_VALS_ECO_GAS = [2.0, 1.5, 1.0, 0.8, 0.6, 0.4, 0.2] +A_CRUISE_MAX_VALS_SPORT_GAS = [3.0, 2.5, 2.0, 1.5, 1.0, 0.8, 0.6] -def get_max_accel_eco(v_ego): - return float(akima_interp(v_ego, A_CRUISE_MAX_BP_CUSTOM, A_CRUISE_MAX_VALS_ECO)) +def get_max_accel_eco(v_ego, ev_tuning=True): + cruise_vals = A_CRUISE_MAX_VALS_ECO_EV if ev_tuning else A_CRUISE_MAX_VALS_ECO_GAS + return float(akima_interp(v_ego, A_CRUISE_MAX_BP_CUSTOM, cruise_vals)) -def get_max_accel_sport(v_ego): - return float(akima_interp(v_ego, A_CRUISE_MAX_BP_CUSTOM, A_CRUISE_MAX_VALS_SPORT)) +def get_max_accel_sport(v_ego, ev_tuning=True): + cruise_vals = A_CRUISE_MAX_VALS_SPORT_EV if ev_tuning else A_CRUISE_MAX_VALS_SPORT_GAS + return float(akima_interp(v_ego, A_CRUISE_MAX_BP_CUSTOM, cruise_vals)) def get_max_accel_low_speeds(max_accel, v_cruise): return float(akima_interp(v_cruise, [0., CITY_SPEED_LIMIT / 2, CITY_SPEED_LIMIT], [max_accel / 4, max_accel / 2, max_accel])) @@ -81,22 +85,23 @@ class FrogPilotAcceleration: def update(self, v_ego, sm, frogpilot_toggles): eco_gear = sm["frogpilotCarState"].ecoGear sport_gear = sm["frogpilotCarState"].sportGear + ev_tuning = frogpilot_toggles.ev_tuning if sm["frogpilotCarState"].trafficModeEnabled: self.max_accel = get_max_accel(v_ego) elif frogpilot_toggles.map_acceleration and (eco_gear or sport_gear): if eco_gear: - self.max_accel = get_max_accel_eco(v_ego) + self.max_accel = get_max_accel_eco(v_ego, ev_tuning) else: if frogpilot_toggles.acceleration_profile == 2: - self.max_accel = get_max_accel_sport(v_ego) + self.max_accel = get_max_accel_sport(v_ego, ev_tuning) else: self.max_accel = get_max_allowed_accel(v_ego) else: if frogpilot_toggles.acceleration_profile == 1: - self.max_accel = get_max_accel_eco(v_ego) + self.max_accel = get_max_accel_eco(v_ego, ev_tuning) elif frogpilot_toggles.acceleration_profile == 2: - self.max_accel = get_max_accel_sport(v_ego) + self.max_accel = get_max_accel_sport(v_ego, ev_tuning) elif frogpilot_toggles.acceleration_profile == 3: self.max_accel = get_max_allowed_accel(v_ego) else: diff --git a/frogpilot/ui/qt/offroad/longitudinal_settings.cc b/frogpilot/ui/qt/offroad/longitudinal_settings.cc index 90716e2fe..c22ea10fa 100644 --- a/frogpilot/ui/qt/offroad/longitudinal_settings.cc +++ b/frogpilot/ui/qt/offroad/longitudinal_settings.cc @@ -98,6 +98,11 @@ FrogPilotLongitudinalPanel::FrogPilotLongitudinalPanel( "fine-tune how openpilot drives."), "../../frogpilot/assets/toggle_icons/" "icon_advanced_longitudinal_tune.png"}, + {"EVTuning", tr("EV Tuning"), + tr("Use acceleration profiles tuned for EVs. Defaults to the " + "vehicle's detected powertrain type but can be overridden if the " + "automatic choice doesn't match."), + ""}, {"LongitudinalActuatorDelay", longitudinalActuatorDelay != 0 ? QString(tr("Actuator Delay (Default: %1)")) diff --git a/frogpilot/ui/qt/offroad/longitudinal_settings.h b/frogpilot/ui/qt/offroad/longitudinal_settings.h index fb5ebf31a..e6f9122ab 100644 --- a/frogpilot/ui/qt/offroad/longitudinal_settings.h +++ b/frogpilot/ui/qt/offroad/longitudinal_settings.h @@ -40,7 +40,7 @@ private: std::map toggles; - QSet advancedLongitudinalTuneKeys = {"LongitudinalActuatorDelay", "StartAccel", "StopAccel", "StoppingDecelRate", "VEgoStarting", "VEgoStopping"}; + QSet advancedLongitudinalTuneKeys = {"EVTuning", "LongitudinalActuatorDelay", "StartAccel", "StopAccel", "StoppingDecelRate", "VEgoStarting", "VEgoStopping"}; QSet aggressivePersonalityKeys = {"AggressiveFollow", "AggressiveFollowHigh", "AggressiveJerkAcceleration", "AggressiveJerkDeceleration", "AggressiveJerkDanger", "AggressiveJerkSpeed", "AggressiveJerkSpeedDecrease", "ResetAggressivePersonality"}; QSet conditionalExperimentalKeys = {"CESpeed", "CESpeedLead", "CECurves", "CELead", "CEModelStopTime", "CENavigation", "CESignalSpeed", "ShowCEMStatus"}; QSet curveSpeedKeys = {"CalibratedLateralAcceleration", "CalibrationProgress", "ResetCurveData", "ShowCSCStatus"};