From 2f09579c2e59e85c603de27f0348e930c55f038d Mon Sep 17 00:00:00 2001 From: rav4kumar Date: Sat, 22 Mar 2025 17:42:31 -0700 Subject: [PATCH] ui --- selfdrive/ui/sunnypilot/SConscript | 1 + .../settings/lateral/lane_change_settings.cc | 174 ++++++++++++++++++ .../settings/lateral/lane_change_settings.h | 68 +++++++ .../qt/offroad/settings/lateral_panel.cc | 19 ++ .../qt/offroad/settings/lateral_panel.h | 7 + 5 files changed, 269 insertions(+) create mode 100644 selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/lane_change_settings.cc create mode 100644 selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/lane_change_settings.h diff --git a/selfdrive/ui/sunnypilot/SConscript b/selfdrive/ui/sunnypilot/SConscript index 24c98c9868..dd522fd500 100644 --- a/selfdrive/ui/sunnypilot/SConscript +++ b/selfdrive/ui/sunnypilot/SConscript @@ -37,6 +37,7 @@ qt_src = [ lateral_panel_qt_src = [ "sunnypilot/qt/offroad/settings/lateral/mads_settings.cc", "sunnypilot/qt/offroad/settings/lateral/neural_network_lateral_control.cc", + "sunnypilot/qt/offroad/settings/lateral/lane_change_settings.cc", ] network_src = [ diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/lane_change_settings.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/lane_change_settings.cc new file mode 100644 index 0000000000..18bbef7916 --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/lane_change_settings.cc @@ -0,0 +1,174 @@ +// +// Created by kumar on 3/10/25. +// +/** + * 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/lane_change_settings.h" + +#include +#include +#include +#include + +LaneChangeSettings::LaneChangeSettings(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(tr("Back")); + connect(back, &QPushButton::clicked, [=]() { emit backPress(); }); + main_layout->addWidget(back, 0, Qt::AlignLeft); + + ListWidgetSP *list = new ListWidgetSP(this, false); + // param, title, desc, icon + std::vector> toggle_defs{ + /*** + { + "BelowSpeedPause", + tr("Pause Lateral Below Speed with Blinker"), + tr("Enable this toggle to pause lateral actuation with blinker when traveling below the desired speed selected below."), + "../assets/offroad/icon_blank.png", + }, + ***/ + { + "AutoLaneChangeBsmDelay", + tr("Auto Lane Change: Delay with Blind Spot"), + tr("Toggle to enable a delay timer for seamless lane changes when blind spot monitoring (BSM) detects a obstructing vehicle, ensuring safe maneuvering."), + "../assets/offroad/icon_blank.png", + }, + /*** + { + "RoadEdge", + tr("Block Lane Change: Road Edge Detection"), + tr("Enable this toggle to block lane change when road edge is detected on the stalk actuated side."), + "../assets/offroad/icon_blank.png", + } + ***/ + }; + + // Controls: Auto Lane Change Timer + auto_lane_change_timer = new AutoLaneChangeTimer(); + auto_lane_change_timer->setUpdateOtherToggles(true); + auto_lane_change_timer->showDescription(); + connect(auto_lane_change_timer, &OptionControlSP::updateLabels, auto_lane_change_timer, &AutoLaneChangeTimer::refresh); + connect(auto_lane_change_timer, &AutoLaneChangeTimer::updateOtherToggles, this, &LaneChangeSettings::updateToggles); + list->addItem(auto_lane_change_timer); + + // Pause Lateral Below Speed w/ Blinker + /*** + pause_lateral_speed = new PauseLateralSpeed(); + pause_lateral_speed->showDescription(); + connect(pause_lateral_speed, &OptionControlSP::updateLabels, pause_lateral_speed, &PauseLateralSpeed::refresh); + + for (auto &[param, title, desc, icon] : toggle_defs) { + auto toggle = new ParamControlSP(param, title, desc, icon, this); + + list->addItem(toggle); + toggles[param.toStdString()] = toggle; + + if (param == "BelowSpeedPause") { + list->addItem(pause_lateral_speed); + } + } + + connect(toggles["BelowSpeedPause"], &ToggleControlSP::toggleFlipped, [=](bool state) { + pause_lateral_speed->setEnabled(state); + pause_lateral_speed->setVisible(state); + }); + pause_lateral_speed->setEnabled(toggles["BelowSpeedPause"]->isToggled()); + pause_lateral_speed->setVisible(toggles["BelowSpeedPause"]->isToggled()); + + main_layout->addWidget(new ScrollViewSP(list, this)); + ***/ +} + +void LaneChangeSettings::showEvent(QShowEvent *event) { + updateToggles(); +} + +void LaneChangeSettings::updateToggles() { + if (!isVisible()) { + return; + } + + auto auto_lane_change_bsm_delay_toggle = toggles["AutoLaneChangeBsmDelay"]; + auto auto_lane_change_timer_param = std::atoi(params.get("AutoLaneChangeTimer").c_str()); + + auto cp_bytes = params.get("CarParamsPersistent"); + if (!cp_bytes.empty()) { + AlignedBuffer aligned_buf; + capnp::FlatArrayMessageReader cmsg(aligned_buf.align(cp_bytes.data(), cp_bytes.size())); + cereal::CarParams::Reader CP = cmsg.getRoot(); + + if (!CP.getEnableBsm()) { + params.remove("AutoLaneChangeBsmDelay"); + } + auto_lane_change_bsm_delay_toggle->setEnabled(CP.getEnableBsm() && (auto_lane_change_timer_param > 0)); + + auto_lane_change_bsm_delay_toggle->refresh(); + } else { + auto_lane_change_bsm_delay_toggle->setEnabled(false); + } +} + +// Auto Lane Change Timer (ALCT) +AutoLaneChangeTimer::AutoLaneChangeTimer() : OptionControlSP( + "AutoLaneChangeTimer", + tr("Auto Lane Change by Blinker"), + tr("Set a timer to delay the auto lane change operation when the blinker is used. " + "No nudge on the steering wheel is required to auto lane change if a timer is set. Default is Nudge.\n" + "Please use caution when using this feature. Only use the blinker when traffic and road conditions permit."), + "../assets/offroad/icon_blank.png", + {-1, 5}) { + + refresh(); +} + +void AutoLaneChangeTimer::refresh() { + QString option = QString::fromStdString(params.get("AutoLaneChangeTimer")); + QString second = tr("s"); + if (option == "-1") { + setLabel(tr("Off")); + } else if (option == "0") { + setLabel(tr("Nudge")); + } else if (option == "1") { + setLabel(tr("Nudgeless")); + } else if (option == "2") { + setLabel("0.5 " + second); + } else if (option == "3") { + setLabel("1 " + second); + } else if (option == "4") { + setLabel("1.5 " + second); + } else { + setLabel("2 " + second); + } +} +/*** +PauseLateralSpeed::PauseLateralSpeed() : OptionControlSP( + "PauseLateralSpeed", + "", + tr("Pause lateral actuation with blinker when traveling below the desired speed selected. Default is 20 MPH or 32 km/h."), + "../assets/offroad/icon_blank.png", + {0, 255}, + 5) { + + refresh(); +} + +void PauseLateralSpeed::refresh() { + QString option = QString:: fromStdString(params.get("PauseLateralSpeed")); + bool is_metric = params.getBool("IsMetric"); + + if (option == "0") { + setLabel(tr("Default")); + } else { + setLabel(option + " " + (is_metric ? tr("km/h") : tr("mph"))); + } +} +***/ diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/lane_change_settings.h b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/lane_change_settings.h new file mode 100644 index 0000000000..00e05e2b62 --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/lane_change_settings.h @@ -0,0 +1,68 @@ +/** +* 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 +#include + +#include "selfdrive/ui/sunnypilot/ui.h" +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/settings.h" +#include "selfdrive/ui/sunnypilot/qt/widgets/controls.h" + +class AutoLaneChangeTimer : public OptionControlSP { + Q_OBJECT + +public: + AutoLaneChangeTimer(); + + void refresh(); + +signals: + void toggleUpdated(); + +private: + Params params; +}; + +/*** +class PauseLateralSpeed : public OptionControlSP { + Q_OBJECT + +public: + PauseLateralSpeed(); + + void refresh(); + + signals: + void ToggleUpdated(); + +private: + Params params; +}; +***/ + +class LaneChangeSettings : public QWidget { + Q_OBJECT + +public: + explicit LaneChangeSettings(QWidget* parent = nullptr); + void showEvent(QShowEvent *event) override; + +signals: + void backPress(); + +public slots: + void updateToggles(); + +private: + Params params; + std::map toggles; + + AutoLaneChangeTimer *auto_lane_change_timer; + //PauseLateralSpeed *pause_lateral_speed; +}; diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.cc index aaf3201f2a..fe9f2022b7 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.cc +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.cc @@ -42,6 +42,24 @@ LateralPanel::LateralPanel(SettingsWindowSP *parent) : QFrame(parent) { }); list->addItem(madsSettingsButton); + // Lane Change Settings + laneChangeSettingsButton = new PushButtonSP(tr("Customize Lane Change")); + laneChangeSettingsButton->setObjectName("lane_change_btn"); + connect(laneChangeSettingsButton, &QPushButton::clicked, [=]() { + sunnypilotScroller->setLastScrollPosition(); + main_layout->setCurrentWidget(lane_change_settings); + }); + + lane_change_settings = new LaneChangeSettings(this); + connect(lane_change_settings, &LaneChangeSettings::backPress, [=]() { + sunnypilotScroller->restoreScrollPosition(); + main_layout->setCurrentWidget(sunnypilotScreen); + }); + list->addItem(laneChangeSettingsButton); + + + + // nnlc nnlcToggle = new NeuralNetworkLateralControl(); list->addItem(nnlcToggle); @@ -65,6 +83,7 @@ LateralPanel::LateralPanel(SettingsWindowSP *parent) : QFrame(parent) { main_layout->addWidget(sunnypilotScreen); main_layout->addWidget(madsWidget); + main_layout->addWidget(lane_change_settings); setStyleSheet(R"( #back_btn { diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.h b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.h index 0857e6ebd5..8b9927094b 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.h +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/lateral_panel.h @@ -13,6 +13,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/neural_network_lateral_control.h" +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/lateral/lane_change_settings.h" #include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/sunnypilot/qt/offroad/settings/settings.h" #include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h" @@ -38,5 +39,11 @@ private: ParamControl *madsToggle; PushButtonSP *madsSettingsButton; MadsSettings *madsWidget = nullptr; + + PushButtonSP *laneChangeSettingsButton; + LaneChangeSettings *lane_change_settings = nullptr; + + + NeuralNetworkLateralControl *nnlcToggle = nullptr; };