From 0e6884df41e3c83e2831ac3ab9837e17591a50ae Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Fri, 12 Jan 2024 22:39:30 -0700 Subject: [PATCH] User Set Steer Ratio --- common/params.cc | 2 ++ selfdrive/controls/controlsd.py | 5 ++++- selfdrive/frogpilot/ui/control_settings.cc | 19 ++++++++++++++++++- selfdrive/frogpilot/ui/control_settings.h | 2 ++ selfdrive/frogpilot/ui/frogpilot_functions.h | 10 ++++++---- selfdrive/locationd/paramsd.py | 5 +++++ 6 files changed, 37 insertions(+), 6 deletions(-) diff --git a/common/params.cc b/common/params.cc index 622d91a..a5c3f92 100644 --- a/common/params.cc +++ b/common/params.cc @@ -340,6 +340,8 @@ std::unordered_map keys = { {"SpeedLimitController", PERSISTENT}, {"StandardFollow", PERSISTENT}, {"StandardJerk", PERSISTENT}, + {"SteerRatio", PERSISTENT}, + {"SteerRatioStock", PERSISTENT}, {"StoppingDistance", PERSISTENT}, {"TetheringEnabled", PERSISTENT}, {"TSS2Tune", PERSISTENT}, diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 6dbe1d3..6d2b715 100644 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -616,7 +616,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) self.VM.update_params(x, sr) # Update Torque Params @@ -994,6 +994,9 @@ class Controls: self.green_light_alert = self.params.get_bool("GreenLightAlert") + lateral_tune = self.params.get_bool("LateralTune") + self.steer_ratio = self.params.get_int("SteerRatio") / 100 if lateral_tune else self.params.get_int("SteerRatioStock") / 100 + longitudinal_tune = self.params.get_bool("LongitudinalTune") self.sport_plus = self.params.get_int("AccelerationProfile") == 3 and longitudinal_tune diff --git a/selfdrive/frogpilot/ui/control_settings.cc b/selfdrive/frogpilot/ui/control_settings.cc index 807b1bb..234cde4 100644 --- a/selfdrive/frogpilot/ui/control_settings.cc +++ b/selfdrive/frogpilot/ui/control_settings.cc @@ -27,6 +27,7 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil {"LateralTune", "Lateral Tuning", "Modify openpilot's steering behavior.", "../frogpilot/assets/toggle_icons/icon_lateral_tune.png"}, {"AverageCurvature", "Average Desired Curvature", "Use Pfeiferj's distance-based curvature adjustment for improved curve handling.", ""}, {"NNFF", "NNFF - Neural Network Feedforward", "Use Twilsonco's Neural Network Feedforward for enhanced precision in lateral control.", ""}, + {"SteerRatio", steerRatioStock != 0 ? QString("Steer Ratio (Default: " + QString::number(steerRatioStock / 100.0) + ")") : "Steer Ratio", "Set a custom steer ratio for your vehicle controls.", ""}, {"LongitudinalTune", "Longitudinal Tuning", "Modify openpilot's acceleration and braking behavior.", "../frogpilot/assets/toggle_icons/icon_longitudinal_tune.png"}, {"AccelerationProfile", "Acceleration Profile", "Change the acceleration rate to be either sporty or eco-friendly.", ""}, @@ -176,6 +177,8 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil } }); toggle = lateralTuneToggle; + } else if (param == "SteerRatio") { + toggle = new FrogPilotParamValueControl(param, title, desc, icon, steerRatioStock * 0.75, steerRatioStock * 1.25, std::map(), this, false, "", 100); } else if (param == "LongitudinalTune") { FrogPilotParamManageControl *longitudinalTuneToggle = new FrogPilotParamManageControl(param, title, desc, icon, this); @@ -359,11 +362,17 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil conditionalExperimentalKeys = {"CECurves", "CECurvesLead", "CESlowerLead", "CENavigation", "CEStopLights", "CESignal"}; fireTheBabysitterKeys = {"NoLogging", "MuteDM", "MuteDoor", "MuteOverheated", "MuteSeatbelt"}; laneChangeKeys = {"LaneChangeTime", "LaneDetection", "OneLaneChange", "PauseLateralOnSignal"}; - lateralTuneKeys = {"AverageCurvature", "NNFF"}; + lateralTuneKeys = {"AverageCurvature", "NNFF", "SteerRatio"}; longitudinalTuneKeys = {"AccelerationProfile", "AggressiveAcceleration", "SmoothBraking", "StoppingDistance"}; speedLimitControllerKeys = {"Offset1", "Offset2", "Offset3", "Offset4", "SLCFallback", "SLCOverride", "SLCPriority"}; visionTurnControlKeys = {}; + QObject::connect(uiState(), &UIState::offroadTransition, this, [this](bool offroad) { + if (!offroad) { + updateCarToggles(); + } + }); + QObject::connect(device(), &Device::interactiveTimeout, this, &FrogPilotControlsPanel::hideSubToggles); QObject::connect(parent, &SettingsWindow::closeParentToggle, this, &FrogPilotControlsPanel::hideSubToggles); QObject::connect(parent, &SettingsWindow::updateMetric, this, &FrogPilotControlsPanel::updateMetric); @@ -372,6 +381,14 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil updateMetric(); } +void FrogPilotControlsPanel::updateCarToggles() { + FrogPilotParamValueControl *steerRatioToggle = static_cast(toggles["SteerRatio"]); + steerRatioStock = params.getInt("SteerRatioStock"); + steerRatioToggle->setTitle(steerRatioStock != 0 ? QString("Steer Ratio (Default: " + QString::number(steerRatioStock / 100.0) + ")") : QString("Steer Ratio")); + steerRatioToggle->updateControl(steerRatioStock * 0.75, steerRatioStock * 1.25, "", 100); + steerRatioToggle->refresh(); +} + void FrogPilotControlsPanel::updateToggles() { std::thread([this]() { paramsMemory.putBool("FrogPilotTogglesUpdated", true); diff --git a/selfdrive/frogpilot/ui/control_settings.h b/selfdrive/frogpilot/ui/control_settings.h index 0c02ffe..d49f3df 100644 --- a/selfdrive/frogpilot/ui/control_settings.h +++ b/selfdrive/frogpilot/ui/control_settings.h @@ -19,6 +19,7 @@ private: void hideEvent(QHideEvent *event); void hideSubToggles(); void parentToggleClicked(); + void updateCarToggles(); void updateMetric(); void updateToggles(); @@ -46,4 +47,5 @@ private: Params paramsMemory{"/dev/shm/params"}; bool isMetric = params.getBool("IsMetric"); + int steerRatioStock = params.getInt("SteerRatioStock"); }; diff --git a/selfdrive/frogpilot/ui/frogpilot_functions.h b/selfdrive/frogpilot/ui/frogpilot_functions.h index 06d1b49..ac5469c 100644 --- a/selfdrive/frogpilot/ui/frogpilot_functions.h +++ b/selfdrive/frogpilot/ui/frogpilot_functions.h @@ -179,8 +179,8 @@ class FrogPilotParamToggleControl : public ParamControl { Q_OBJECT public: FrogPilotParamToggleControl(const QString ¶m, const QString &title, const QString &desc, - const QString &icon, const std::vector &button_params, - const std::vector &button_texts, QWidget *parent = nullptr, + const QString &icon, const std::vector &button_params, + const std::vector &button_texts, QWidget *parent = nullptr, const int minimum_button_width = 225) : ParamControl(param, title, desc, icon, parent) { @@ -313,10 +313,11 @@ public: valueLabel->setStyleSheet("QLabel { color: #E0E879; }"); } - void updateControl(int newMinValue, int newMaxValue, const QString &newLabel) { + void updateControl(int newMinValue, int newMaxValue, const QString &newLabel, int newDivision = 1) { minValue = newMinValue; maxValue = newMaxValue; labelText = newLabel; + division = newDivision; } void showEvent(QShowEvent *event) override { @@ -492,10 +493,11 @@ public: valueLabel->setStyleSheet("QLabel { color: #E0E879; }"); } - void updateControl(int newMinValue, int newMaxValue, const QString &newLabel) { + void updateControl(int newMinValue, int newMaxValue, const QString &newLabel, int newDivision) { minValue = newMinValue; maxValue = newMaxValue; labelText = newLabel; + division = newDivision; } void showEvent(QShowEvent *event) override { diff --git a/selfdrive/locationd/paramsd.py b/selfdrive/locationd/paramsd.py index becf226..fcf231f 100755 --- a/selfdrive/locationd/paramsd.py +++ b/selfdrive/locationd/paramsd.py @@ -134,6 +134,11 @@ def main(): CP = msg cloudlog.info("paramsd got CarParams") + steer_ratio_stock = params_reader.get_int("SteerRatioStock") + if steer_ratio_stock != CP.steerRatio * 100: + params_reader.put_int("SteerRatio", CP.steerRatio * 100) + params_reader.put_int("SteerRatioStock", CP.steerRatio * 100) + min_sr, max_sr = 0.5 * CP.steerRatio, 2.0 * CP.steerRatio params = params_reader.get("LiveParameters")