diff --git a/common/params_keys.h b/common/params_keys.h index 6a0c63098d..32ed3b3afe 100644 --- a/common/params_keys.h +++ b/common/params_keys.h @@ -169,5 +169,9 @@ inline static std::unordered_map keys = { {"DynamicExperimentalControl", PERSISTENT}, // Tuning keys - {"HkgTuningAngleSmoothingFactor", PERSISTENT | BACKUP} + {"HkgTuningAngleSmoothingFactor", PERSISTENT | BACKUP}, + {"HkgTuningAngleMinTorque", PERSISTENT | BACKUP}, + {"HkgTuningAngleMaxTorque", PERSISTENT | BACKUP}, + {"AngleTuning", PERSISTENT | BACKUP} + }; diff --git a/selfdrive/ui/qt/offroad/developer_panel.cc b/selfdrive/ui/qt/offroad/developer_panel.cc index b22ed10dbd..3e9647d2cf 100644 --- a/selfdrive/ui/qt/offroad/developer_panel.cc +++ b/selfdrive/ui/qt/offroad/developer_panel.cc @@ -56,15 +56,6 @@ DeveloperPanel::DeveloperPanel(SettingsWindow *parent) : ListWidget(parent) { }); addItem(errorLogBtn); -#ifdef SUNNYPILOT - hkgAngleSmoothingFactor = new OptionControlSP("HkgTuningAngleSmoothingFactor", tr("HKG Angle Smoothing Factor"), tr("Applies EMA (Exponential Moving Average) to the desired angle steering.
A value closer to 1 means no smoothing.
A value closer to 0 means very smooth (and thus likely too 'soft' steering)."), "../assets/offroad/icon_blank.png", {0, 10}, 1); - connect(hkgAngleSmoothingFactor, &OptionControlSP::updateLabels, hkgAngleSmoothingFactor, [=]() { - this->updateToggles(offroad); - }); - addItem(hkgAngleSmoothingFactor); -#endif - - // Joystick and longitudinal maneuvers should be hidden on release branches is_release = params.getBool("IsReleaseBranch"); @@ -84,9 +75,6 @@ void DeveloperPanel::updateToggles(bool _offroad) { if (btn != experimentalLongitudinalToggle) { btn->setEnabled(_offroad); } - - auto HkgAngleSmoothingFactorValue = QString::fromStdString(params.get("HkgTuningAngleSmoothingFactor")).toDouble(); - hkgAngleSmoothingFactor->setLabel(QString::number(HkgAngleSmoothingFactorValue / 10, 'f', 1)); } // longManeuverToggle and experimentalLongitudinalToggle should not be toggleable if the car does not have longitudinal control diff --git a/selfdrive/ui/qt/offroad/developer_panel.h b/selfdrive/ui/qt/offroad/developer_panel.h index 3406c9956f..ed03e528ab 100644 --- a/selfdrive/ui/qt/offroad/developer_panel.h +++ b/selfdrive/ui/qt/offroad/developer_panel.h @@ -20,9 +20,6 @@ private: ParamControl* longManeuverToggle; ParamControl* experimentalLongitudinalToggle; ParamControl* enableGithubRunner; -#ifdef SUNNYPILOT - OptionControlSP* hkgAngleSmoothingFactor; -#endif bool is_release; bool offroad = false; diff --git a/selfdrive/ui/sunnypilot/SConscript b/selfdrive/ui/sunnypilot/SConscript index d189751843..4572873049 100644 --- a/selfdrive/ui/sunnypilot/SConscript +++ b/selfdrive/ui/sunnypilot/SConscript @@ -40,6 +40,7 @@ qt_src = [ lateral_panel_qt_src = [ "sunnypilot/qt/offroad/settings/lateral/lane_change_settings.cc", "sunnypilot/qt/offroad/settings/lateral/mads_settings.cc", + "sunnypilot/qt/offroad/settings/lateral/angle_tuning_settings.cc", "sunnypilot/qt/offroad/settings/lateral/neural_network_lateral_control.cc", ] diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/angle_tuning_settings.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/angle_tuning_settings.cc new file mode 100644 index 0000000000..beee5d8c6d --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/angle_tuning_settings.cc @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/angle_tuning_settings.h" + +#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h" + +AngleTunningSettings::AngleTunningSettings(QWidget *parent) : QWidget(parent) { + QVBoxLayout *main_layout = new QVBoxLayout(this); + main_layout->setContentsMargins(50, 20, 50, 20); + main_layout->setSpacing(20); + + // Back button + PanelBackButton *back = new PanelBackButton(); + connect(back, &QPushButton::clicked, [=]() { emit backPress(); }); + main_layout->addWidget(back, 0, Qt::AlignLeft); + + auto *list = new ListWidget(this, false); + + hkgAngleSmoothingFactor = new OptionControlSP("HkgTuningAngleSmoothingFactor", tr("HKG Angle Smoothing Factor"), tr("Applies EMA (Exponential Moving Average) to the desired angle steering.
A value closer to 1 means no smoothing.
A value closer to 0 means very smooth (and thus likely too 'soft' steering)."), "../assets/offroad/icon_blank.png", {0, 10}, 1); + connect(hkgAngleSmoothingFactor, &OptionControlSP::updateLabels, hkgAngleSmoothingFactor, [=]() { + this->updateToggles(offroad); + }); + list->addItem(hkgAngleSmoothingFactor); + + + auto hlayout = new QHBoxLayout(); + hkgAngleMinTorque = new OptionControlSP("HkgTuningAngleMinTorque", tr("HKG Angle Min Torque"), tr("Minimum torque to apply to the steering wheel.
Must be smaller than max."), "../assets/offroad/icon_blank.png", {0, 250}, 5); + connect(hkgAngleMinTorque, &OptionControlSP::updateLabels, hkgAngleMinTorque, [=]() { + this->updateToggles(offroad); + }); + hlayout->addWidget(hkgAngleMinTorque); + + hkgAngleMaxTorque = new OptionControlSP("HkgTuningAngleMaxTorque", tr("HKG Angle Max Torque"), tr("Maximum torque to apply to the steering wheel.
Must be bigger than min."), "../assets/offroad/icon_blank.png", {25, 250}, 5); + connect(hkgAngleMaxTorque, &OptionControlSP::updateLabels, hkgAngleMaxTorque, [=]() { + this->updateToggles(offroad); + }); + hlayout->addWidget(hkgAngleMaxTorque); + list->addItem(hlayout); + + QObject::connect(uiState(), &UIState::offroadTransition, this, &AngleTunningSettings::updateToggles); + + main_layout->addWidget(new ScrollViewSP(list, this)); +} + +void AngleTunningSettings::showEvent(QShowEvent *event) { + updateToggles(offroad); +} + +void AngleTunningSettings::updateToggles(bool _offroad) { + auto HkgAngleSmoothingFactorValue = QString::fromStdString(params.get("HkgTuningAngleSmoothingFactor")).toDouble(); + hkgAngleSmoothingFactor->setLabel(QString::number(HkgAngleSmoothingFactorValue / 10, 'f', 1)); + + auto HkgAngleMinTorqueValue = QString::fromStdString(params.get("HkgTuningAngleMinTorque")).toInt(); + hkgAngleMinTorque->setLabel(QString::number(HkgAngleMinTorqueValue)); + + auto HkgAngleMaxTorqueValue = QString::fromStdString(params.get("HkgTuningAngleMaxTorque")).toInt(); + hkgAngleMaxTorque->setLabel(QString::number(HkgAngleMaxTorqueValue)); + + offroad = _offroad; +} diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/angle_tuning_settings.h b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/angle_tuning_settings.h new file mode 100644 index 0000000000..334b1d2b0e --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/angle_tuning_settings.h @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#pragma once + +#include "selfdrive/ui/qt/util.h" +#include "selfdrive/ui/sunnypilot/ui.h" +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/settings.h" +#include "selfdrive/ui/sunnypilot/qt/widgets/controls.h" + +class AngleTunningSettings : public QWidget { + Q_OBJECT + +public: + explicit AngleTunningSettings(QWidget *parent = nullptr); + + void showEvent(QShowEvent *event) override; + +signals: + void backPress(); + +public slots: + void updateToggles(bool _offroad); + +private: + Params params; + bool offroad; + + OptionControlSP* hkgAngleSmoothingFactor; + OptionControlSP* hkgAngleMinTorque; + OptionControlSP* hkgAngleMaxTorque; +}; diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.cc index 0beae6e24f..990b43eeaf 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.cc +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.cc @@ -78,6 +78,36 @@ LateralPanel::LateralPanel(SettingsWindowSP *parent) : QFrame(parent) { nnlcToggle->updateToggle(); }); +#pragma region hkg angle tuning + list->addItem(vertical_space()); + list->addItem(horizontal_line()); + list->addItem(vertical_space()); + + // HKG Angle Tunning + // angleTuningToggle = new ParamControl( + // "AngleTuning", + // tr("Modular Assistive Driving System (MADS)"), + // tr("Enable the beloved MADS feature. Disable toggle to revert back to stock sunnypilot engagement/disengagement."), + // ""); + // angleTuningToggle->setConfirmation(true, false); + // list->addItem(angleTuningToggle); + + angleTuningSettingsButton = new PushButtonSP(tr("Customize ANGLE Tuning")); + angleTuningSettingsButton->setObjectName("angle_btn"); + connect(angleTuningSettingsButton, &QPushButton::clicked, [=]() { + sunnypilotScroller->setLastScrollPosition(); + main_layout->setCurrentWidget(angleTuningWidget); + }); + // QObject::connect(angleTuningToggle, &ToggleControl::toggleFlipped, angleTuningSettingsButton, &PushButtonSP::setEnabled); + + angleTuningWidget = new AngleTunningSettings(this); + connect(angleTuningWidget, &AngleTunningSettings::backPress, [=]() { + sunnypilotScroller->restoreScrollPosition(); + main_layout->setCurrentWidget(sunnypilotScreen); + }); + list->addItem(angleTuningSettingsButton); +#pragma endregion + toggleOffroadOnly = { madsToggle, nnlcToggle, }; @@ -88,6 +118,7 @@ LateralPanel::LateralPanel(SettingsWindowSP *parent) : QFrame(parent) { main_layout->addWidget(sunnypilotScreen); main_layout->addWidget(madsWidget); + main_layout->addWidget(angleTuningWidget); main_layout->addWidget(laneChangeWidget); setStyleSheet(R"( @@ -138,6 +169,7 @@ void LateralPanel::updateToggles(bool _offroad) { } madsSettingsButton->setEnabled(madsToggle->isToggled()); + // angleTuningSettingsButton->setEnabled(angleTuningToggle->isToggled()); offroad = _offroad; } diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.h b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.h index cf003dfaf3..4059fca56e 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.h +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.h @@ -12,6 +12,7 @@ #include "selfdrive/ui/sunnypilot/ui.h" #include "selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/mads_settings.h" +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/angle_tuning_settings.h" #include "selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/neural_network_lateral_control.h" #include "selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/lane_change_settings.h" #include "selfdrive/ui/qt/util.h" @@ -38,8 +39,11 @@ private: bool offroad; ParamControl *madsToggle; + // ParamControl *angleTuningToggle; PushButtonSP *madsSettingsButton; + PushButtonSP *angleTuningSettingsButton; MadsSettings *madsWidget = nullptr; + AngleTunningSettings *angleTuningWidget = nullptr; PushButtonSP *laneChangeSettingsButton; LaneChangeSettings *laneChangeWidget = nullptr; NeuralNetworkLateralControl *nnlcToggle = nullptr; diff --git a/system/manager/manager.py b/system/manager/manager.py index 8eb7ec6348..5bb71300bd 100755 --- a/system/manager/manager.py +++ b/system/manager/manager.py @@ -55,7 +55,9 @@ def manager_init() -> None: ("ModelManager_ModelsCache", ""), ("NeuralNetworkLateralControl", "0"), ("QuietMode", "0"), - ("HkgTuningAngleSmoothingFactor", "6") + ("HkgTuningAngleSmoothingFactor", "6"), + ("HkgTuningAngleMinTorque", "25"), + ("HkgTuningAngleMaxTorque", "250"), ] if params.get_bool("RecordFrontLock"):