From d6995513a49732bc716d677393cda36a6967a459 Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Thu, 21 Mar 2024 19:18:09 -0700 Subject: [PATCH] User set steer ratio Add toggle to use a custom set steer ratio as opposed to using comma's auto tune value. --- common/params.cc | 3 +++ selfdrive/controls/controlsd.py | 5 ++++- .../frogpilot/ui/qt/offroad/control_settings.cc | 17 +++++++++++++++++ .../frogpilot/ui/qt/offroad/control_settings.h | 6 +++++- selfdrive/locationd/paramsd.py | 5 +++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/common/params.cc b/common/params.cc index 46848bed9..6fa7bce0d 100644 --- a/common/params.cc +++ b/common/params.cc @@ -377,6 +377,7 @@ std::unordered_map keys = { {"RefuseVolume", PERSISTENT}, {"RelaxedFollow", PERSISTENT}, {"RelaxedJerk", PERSISTENT}, + {"ResetSteerRatio", PERSISTENT}, {"ReverseCruise", PERSISTENT}, {"ReverseCruiseUI", PERSISTENT}, {"RoadEdgesWidth", PERSISTENT}, @@ -426,6 +427,8 @@ std::unordered_map keys = { {"StandardFollow", PERSISTENT}, {"StandardJerk", PERSISTENT}, {"StandbyMode", PERSISTENT}, + {"SteerRatio", PERSISTENT}, + {"SteerRatioStock", PERSISTENT}, {"StockTune", PERSISTENT}, {"StoppingDistance", PERSISTENT}, {"TacoTune", PERSISTENT}, diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index fe20daf2d..b0e3899bb 100644 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -600,7 +600,7 @@ class Controls: # Update VehicleModel lp = self.sm['liveParameters'] x = max(lp.stiffnessFactor, 0.1) - sr = max(lp.steerRatio, 0.1) + sr = max(self.steer_ratio, 0.1) if self.use_custom_steer_ratio else max(lp.steerRatio, 0.1) self.VM.update_params(x, sr) # Update Torque Params @@ -1173,6 +1173,9 @@ class Controls: lateral_tune = self.params.get_bool("LateralTune") self.force_auto_tune = lateral_tune and self.params.get_float("ForceAutoTune") + stock_steer_ratio = self.params.get_float("SteerRatioStock") + self.steer_ratio = self.params.get_float("SteerRatio") if lateral_tune else stock_steer_ratio + self.use_custom_steer_ratio = self.steer_ratio != stock_steer_ratio self.frogpilot_variables.long_pitch = self.params.get_bool("LongPitch") diff --git a/selfdrive/frogpilot/ui/qt/offroad/control_settings.cc b/selfdrive/frogpilot/ui/qt/offroad/control_settings.cc index 28233b9fc..f19495224 100644 --- a/selfdrive/frogpilot/ui/qt/offroad/control_settings.cc +++ b/selfdrive/frogpilot/ui/qt/offroad/control_settings.cc @@ -80,6 +80,7 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil {"ForceAutoTune", tr("Force Auto Tune"), tr("Forces comma's auto lateral tuning for unsupported vehicles."), ""}, {"NNFF", tr("NNFF"), tr("Use Twilsonco's Neural Network Feedforward for enhanced precision in lateral control."), ""}, {"NNFFLite", tr("NNFF-Lite"), tr("Use Twilsonco's Neural Network Feedforward for enhanced precision in lateral control for cars without available NNFF logs."), ""}, + {"SteerRatio", steerRatioStock != 0 ? QString(tr("Steer Ratio (Default: %1)")).arg(QString::number(steerRatioStock, 'f', 2)) : tr("Steer Ratio"), tr("Use a custom steer ratio as opposed to comma's auto tune value."), ""}, {"TacoTune", tr("Taco Tune"), tr("Use comma's 'Taco Tune' designed for handling left and right turns."), ""}, {"TurnDesires", tr("Use Turn Desires"), tr("Use turn desires for greater precision in turns below the minimum lane change speed."), ""}, @@ -317,6 +318,10 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil } }); toggle = lateralTuneToggle; + } else if (param == "SteerRatio") { + std::vector steerRatioToggles{"ResetSteerRatio"}; + std::vector steerRatioToggleNames{"Reset"}; + toggle = new FrogPilotParamValueToggleControl(param, title, desc, icon, steerRatioStock * 0.75, steerRatioStock * 1.25, std::map(), this, false, "", 1, 0.01, steerRatioToggles, steerRatioToggleNames); } else if (param == "LongitudinalTune") { FrogPilotParamManageControl *longitudinalTuneToggle = new FrogPilotParamManageControl(param, title, desc, icon, this); @@ -820,6 +825,7 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil } modelManagerToggle = static_cast(toggles["ModelSelector"]); + steerRatioToggle = static_cast(toggles["SteerRatio"]); QObject::connect(parent, &SettingsWindow::closeParentToggle, this, &FrogPilotControlsPanel::hideToggles); QObject::connect(parent, &SettingsWindow::closeSubParentToggle, this, &FrogPilotControlsPanel::hideSubToggles); @@ -839,6 +845,12 @@ void FrogPilotControlsPanel::updateState(const UIState &s) { started = s.scene.started; + if (params.getBool("ResetSteerRatio")) { + params.putFloat("SteerRatio", steerRatioStock); + params.putBool("ResetSteerRatio", false); + steerRatioToggle->refresh(); + } + downloadModelBtn->setEnabled(s.scene.online); modelManagerToggle->setEnabled(!s.scene.started); } @@ -868,6 +880,11 @@ void FrogPilotControlsPanel::updateCarToggles() { hasOpenpilotLongitudinal = CP.getOpenpilotLongitudinalControl() && !params.getBool("DisableOpenpilotLongitudinal"); hasPCMCruise = CP.getPcmCruise(); isToyota = carName == "toyota"; + steerRatioStock = CP.getSteerRatio(); + + steerRatioToggle->setTitle(QString(tr("Steer Ratio (Default: %1)")).arg(QString::number(steerRatioStock, 'f', 2))); + steerRatioToggle->updateControl(steerRatioStock * 0.75, steerRatioStock * 1.25, "", 0.01); + steerRatioToggle->refresh(); } else { hasAutoTune = false; hasCommaNNFFSupport = false; diff --git a/selfdrive/frogpilot/ui/qt/offroad/control_settings.h b/selfdrive/frogpilot/ui/qt/offroad/control_settings.h index 16e326fa6..2effde49c 100644 --- a/selfdrive/frogpilot/ui/qt/offroad/control_settings.h +++ b/selfdrive/frogpilot/ui/qt/offroad/control_settings.h @@ -39,12 +39,14 @@ private: FrogPilotParamManageControl *modelManagerToggle; + FrogPilotParamValueToggleControl *steerRatioToggle; + std::set aolKeys = {"AlwaysOnLateralMain", "HideAOLStatusBar", "PauseAOLOnBrake"}; std::set conditionalExperimentalKeys = {"CECurves", "CECurvesLead", "CENavigation", "CESignal", "CESlowerLead", "CEStopLights", "HideCEMStatusBar"}; std::set deviceManagementKeys = {"DeviceShutdown", "HigherBitrate", "IncreaseThermalLimits", "LowVoltageShutdown", "NoLogging", "NoUploads", "OfflineMode"}; std::set experimentalModeActivationKeys = {"ExperimentalModeViaDistance", "ExperimentalModeViaLKAS", "ExperimentalModeViaTap"}; std::set laneChangeKeys = {"LaneChangeTime", "LaneDetectionWidth", "OneLaneChange"}; - std::set lateralTuneKeys = {"ForceAutoTune", "NNFF", "NNFFLite", "TacoTune", "TurnDesires"}; + std::set lateralTuneKeys = {"ForceAutoTune", "NNFF", "NNFFLite", "SteerRatio", "TacoTune", "TurnDesires"}; std::set longitudinalTuneKeys = {"AccelerationProfile", "AggressiveAcceleration", "DecelerationProfile", "LeadDetectionThreshold", "SmoothBraking", "StoppingDistance", "TrafficMode"}; std::set mtscKeys = {"DisableMTSCSmoothing", "MTSCAggressiveness", "MTSCCurvatureCheck"}; std::set qolKeys = {"CustomCruise", "CustomCruiseLong", "DisableOnroadUploads", "OnroadDistanceButton", "PauseLateralSpeed", "ReverseCruise", "SetSpeedOffset"}; @@ -69,4 +71,6 @@ private: bool isRelease; bool isToyota; bool started; + + float steerRatioStock; }; diff --git a/selfdrive/locationd/paramsd.py b/selfdrive/locationd/paramsd.py index 52d3dc7fb..de4bbcf76 100755 --- a/selfdrive/locationd/paramsd.py +++ b/selfdrive/locationd/paramsd.py @@ -133,6 +133,11 @@ def main(): CP = msg cloudlog.info("paramsd got CarParams") + steer_ratio_stock = params_reader.get_float("SteerRatioStock") + if steer_ratio_stock != CP.steerRatio: + params_reader.put_float("SteerRatio", CP.steerRatio) + params_reader.put_float("SteerRatioStock", CP.steerRatio) + min_sr, max_sr = 0.5 * CP.steerRatio, 2.0 * CP.steerRatio params = params_reader.get("LiveParameters")