From c6bf6886cf74272d7c8d15b95b565760f684d42b Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 01:01:18 -0400 Subject: [PATCH 01/24] ui: Force offroad from settings when the car is on --- common/params.cc | 1 + selfdrive/controls/lib/alerts_offroad.json | 4 ++ selfdrive/thermald/thermald.py | 3 ++ selfdrive/ui/qt/offroad/settings.cc | 56 +++++++++++++++++++++- selfdrive/ui/qt/offroad/settings.h | 10 ++++ 5 files changed, 73 insertions(+), 1 deletion(-) diff --git a/common/params.cc b/common/params.cc index 9f9a053041..ccfb3a7ae2 100644 --- a/common/params.cc +++ b/common/params.cc @@ -255,6 +255,7 @@ std::unordered_map keys = { {"EnhancedScc", PERSISTENT | BACKUP}, {"FeatureStatus", PERSISTENT | BACKUP}, {"FleetManagerPin", PERSISTENT}, + {"ForceOffroad", CLEAR_ON_MANAGER_START}, {"GmapKey", PERSISTENT | BACKUP}, {"HandsOnWheelMonitoring", PERSISTENT | BACKUP}, {"HideVEgoUi", PERSISTENT | BACKUP}, diff --git a/selfdrive/controls/lib/alerts_offroad.json b/selfdrive/controls/lib/alerts_offroad.json index e08d67f43b..13780b5221 100644 --- a/selfdrive/controls/lib/alerts_offroad.json +++ b/selfdrive/controls/lib/alerts_offroad.json @@ -56,5 +56,9 @@ "Offroad_OSMUpdateRequired": { "text": "OpenStreetMap database is out of date. New maps must be downloaded if you wish to continue using OpenStreetMap data for Enhanced Speed Control and road name display.\n\n%1", "severity": 0 + }, + "Offroad_ForceStatus": { + "text": "sunnypilot is now in Forced Offroad mode. sunnypilot won't start until Forced Offroad mode is disabled. Go to \"Settings\" -> \"Device\" -> \"Unforce Offroad\" to get out of Force Offroad mode.", + "severity": 1 } } diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 37206c2f06..10ab1198a3 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -309,6 +309,9 @@ def thermald_thread(end_event, hw_queue) -> None: # ensure device is fully booted startup_conditions["device_booted"] = startup_conditions.get("device_booted", False) or HARDWARE.booted() + # user-forced status + startup_conditions["not_force_offroad"] = not params.get_bool("ForceOffroad") + # if the temperature enters the danger zone, go offroad to cool down onroad_conditions["device_temp_good"] = thermal_status < ThermalStatus.danger extra_text = f"{offroad_comp_temp:.1f}C" diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index d401102c5d..9d4905c63d 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -403,13 +403,34 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) { connect(uiState(), &UIState::offroadTransition, poweroff_btn, &QPushButton::setVisible); } + addItem(power_layout); + + // TODO: Add Force Onroad/Offroad toggle under power_layout + offroad_btn = new QPushButton(tr("Toggle Onroad/Offroad")); + offroad_btn->setObjectName("offroad_btn"); + QObject::connect(offroad_btn, &QPushButton::clicked, this, &DevicePanel::forceoffroad); + if (!Hardware::PC()) { + connect(uiState(), &UIState::offroadTransition, [=](bool offroad) { + offroad_btn->setVisible(params.getBool("ForceOffroad") && offroad); + }); + } + addItem(offroad_btn); + setStyleSheet(R"( #reboot_btn { height: 120px; border-radius: 15px; background-color: #393939; } #reboot_btn:pressed { background-color: #4a4a4a; } #poweroff_btn { height: 120px; border-radius: 15px; background-color: #E22C2C; } #poweroff_btn:pressed { background-color: #FF2424; } + #offroad_btn { height: 120px; border-radius: 15px; background-color: #393939; } + #offroad_btn:pressed { background-color: #4a4a4a; } )"); - addItem(power_layout); + + connect(uiState(), &UIState::offroadTransition, [=](bool offroad) { + is_onroad = !offroad; + updateLabels(); + }); + + updateLabels(); } void DevicePanel::onPinFileChanged(const QString &file_path) { @@ -484,6 +505,39 @@ void DevicePanel::poweroff() { } } +void DevicePanel::forceoffroad() { + if (!uiState()->engaged()) { + if (is_onroad) { + if (ConfirmationDialog::confirm(tr("Are you sure you want to force offroad?"), tr("Force"), this)) { + if (!uiState()->engaged()) { + params.putBool("ForceOffroad", true); + } + } + } else { + if (ConfirmationDialog::confirm(tr("Are you sure you want to unforce offroad?"), tr("Unforce"), this)) { + if (!uiState()->engaged()) { + params.remove("ForceOFfroad"); + } + } + } + } else { + ConfirmationDialog::alert(tr("Disengage to Force Offroad"), this); + } +} + +void DevicePanel::showEvent(QShowEvent *event) { + updateLabels(); +} + +void DevicePanel::updateLabels() { + if (!isVisible()) { + return; + } + + offroad_btn->setText(is_onroad ? tr("Force Offroad") : tr("Unforce Offroad")); + offroad_btn->setVisible(params.getBool("ForceOffroad") || is_onroad); +} + void SettingsWindow::showEvent(QShowEvent *event) { setCurrentPanel(0); } diff --git a/selfdrive/ui/qt/offroad/settings.h b/selfdrive/ui/qt/offroad/settings.h index 4f12609269..8ea7835b37 100644 --- a/selfdrive/ui/qt/offroad/settings.h +++ b/selfdrive/ui/qt/offroad/settings.h @@ -51,6 +51,8 @@ class DevicePanel : public ListWidget { Q_OBJECT public: explicit DevicePanel(SettingsWindow *parent); +protected: + void showEvent(QShowEvent *event) override; signals: void reviewTrainingGuide(); void showDriverView(); @@ -61,6 +63,9 @@ private slots: void updateCalibDescription(); void onPinFileChanged(const QString &file_path); void refreshPin(); + void forceoffroad(); + + void updateLabels(); private: Params params; @@ -69,6 +74,11 @@ private: QString pin_title = tr("Fleet Manager PIN:") + " "; QString pin = "OFF"; QFileSystemWatcher *fs_watch; + + QPushButton *offroad_btn; + +protected: + bool is_onroad = false; }; class TogglesPanel : public ListWidget { From 153b8b8bff41ac92fef82caf25af80c2862a8d4c Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 12:29:02 -0400 Subject: [PATCH 02/24] Add this check too --- selfdrive/ui/ui.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 9a6f355cc7..e2a1879c39 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -165,6 +165,7 @@ static void update_sockets(UIState *s) { static void update_state(UIState *s) { SubMaster &sm = *(s->sm); UIScene &scene = s->scene; + auto params = Params(); if (sm.updated("liveCalibration")) { auto live_calib = sm["liveCalibration"].getLiveCalibration(); @@ -214,7 +215,7 @@ static void update_state(UIState *s) { float scale = (cam_state.getSensor() == cereal::FrameData::ImageSensor::AR0231) ? 6.0f : 1.0f; scene.light_sensor = std::max(100.0f - scale * cam_state.getExposureValPercent(), 0.0f); } - scene.started = sm["deviceState"].getDeviceState().getStarted() && scene.ignition; + scene.started = sm["deviceState"].getDeviceState().getStarted() && scene.ignition && !params.getBool("ForceOffroad"); scene.world_objects_visible = scene.world_objects_visible || (scene.started && From d2c242b17c591013dd2fe10b6e225b2fee5f324c Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 12:37:57 -0400 Subject: [PATCH 03/24] Impossible condition --- selfdrive/ui/qt/offroad/settings.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 9d4905c63d..37521cee52 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -515,9 +515,7 @@ void DevicePanel::forceoffroad() { } } else { if (ConfirmationDialog::confirm(tr("Are you sure you want to unforce offroad?"), tr("Unforce"), this)) { - if (!uiState()->engaged()) { - params.remove("ForceOFfroad"); - } + params.remove("ForceOFfroad"); } } } else { From 819e5660e81a6fb12fa67e0b4f7935020ba4664d Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 12:41:10 -0400 Subject: [PATCH 04/24] Revert "Impossible condition" This reverts commit d2c242b17c591013dd2fe10b6e225b2fee5f324c. --- selfdrive/ui/qt/offroad/settings.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 37521cee52..9d4905c63d 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -515,7 +515,9 @@ void DevicePanel::forceoffroad() { } } else { if (ConfirmationDialog::confirm(tr("Are you sure you want to unforce offroad?"), tr("Unforce"), this)) { - params.remove("ForceOFfroad"); + if (!uiState()->engaged()) { + params.remove("ForceOFfroad"); + } } } } else { From fef46d3093efc3a1e4f9c56bc014e4657f62ba1c Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 12:41:15 -0400 Subject: [PATCH 05/24] wtf --- selfdrive/ui/qt/offroad/settings.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 9d4905c63d..403880da53 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -516,7 +516,7 @@ void DevicePanel::forceoffroad() { } else { if (ConfirmationDialog::confirm(tr("Are you sure you want to unforce offroad?"), tr("Unforce"), this)) { if (!uiState()->engaged()) { - params.remove("ForceOFfroad"); + params.remove("ForceOffroad"); } } } From 2f4f0a7c16f07922a1f1ceddae275e08db51d2be Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 16:50:34 -0400 Subject: [PATCH 06/24] display message when forced offroad --- common/params.cc | 1 + selfdrive/thermald/thermald.py | 1 + 2 files changed, 2 insertions(+) diff --git a/common/params.cc b/common/params.cc index ccfb3a7ae2..b683609194 100644 --- a/common/params.cc +++ b/common/params.cc @@ -323,6 +323,7 @@ std::unordered_map keys = { {"VisionCurveLaneless", PERSISTENT | BACKUP}, {"VwAccType", PERSISTENT | BACKUP}, {"VwCCOnly", PERSISTENT | BACKUP}, + {"Offroad_ForceStatus", PERSISTENT}, {"Offroad_SupersededUpdate", PERSISTENT}, {"SunnylinkCache_Users", PERSISTENT}, diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 10ab1198a3..0a79b23da8 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -311,6 +311,7 @@ def thermald_thread(end_event, hw_queue) -> None: # user-forced status startup_conditions["not_force_offroad"] = not params.get_bool("ForceOffroad") + set_offroad_alert("Offroad_ForceStatus", True) # if the temperature enters the danger zone, go offroad to cool down onroad_conditions["device_temp_good"] = thermal_status < ThermalStatus.danger From 3071744acda58f877134e71c3723b7c589fcd9e0 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 16:54:46 -0400 Subject: [PATCH 07/24] only display message when forced --- selfdrive/thermald/thermald.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 0a79b23da8..961e7131cc 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -311,7 +311,8 @@ def thermald_thread(end_event, hw_queue) -> None: # user-forced status startup_conditions["not_force_offroad"] = not params.get_bool("ForceOffroad") - set_offroad_alert("Offroad_ForceStatus", True) + if not startup_conditions["not_force_offroad"]: + set_offroad_alert("Offroad_ForceStatus", True) # if the temperature enters the danger zone, go offroad to cool down onroad_conditions["device_temp_good"] = thermal_status < ThermalStatus.danger From 2030196c8c4000e987c71540841f0562ebaa3d7d Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 16:55:55 -0400 Subject: [PATCH 08/24] show button at all times --- selfdrive/ui/qt/offroad/settings.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 403880da53..9332b49248 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -409,11 +409,6 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) { offroad_btn = new QPushButton(tr("Toggle Onroad/Offroad")); offroad_btn->setObjectName("offroad_btn"); QObject::connect(offroad_btn, &QPushButton::clicked, this, &DevicePanel::forceoffroad); - if (!Hardware::PC()) { - connect(uiState(), &UIState::offroadTransition, [=](bool offroad) { - offroad_btn->setVisible(params.getBool("ForceOffroad") && offroad); - }); - } addItem(offroad_btn); setStyleSheet(R"( @@ -535,7 +530,6 @@ void DevicePanel::updateLabels() { } offroad_btn->setText(is_onroad ? tr("Force Offroad") : tr("Unforce Offroad")); - offroad_btn->setVisible(params.getBool("ForceOffroad") || is_onroad); } void SettingsWindow::showEvent(QShowEvent *event) { From 49ab5a1ca294c433f9cb95a2e2a1ff5c8bdc112f Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 16:59:19 -0400 Subject: [PATCH 09/24] change it up --- selfdrive/thermald/thermald.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 961e7131cc..0ab3e0be11 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -312,7 +312,7 @@ def thermald_thread(end_event, hw_queue) -> None: # user-forced status startup_conditions["not_force_offroad"] = not params.get_bool("ForceOffroad") if not startup_conditions["not_force_offroad"]: - set_offroad_alert("Offroad_ForceStatus", True) + set_offroad_alert_if_changed("Offroad_ForceStatus", True) # if the temperature enters the danger zone, go offroad to cool down onroad_conditions["device_temp_good"] = thermal_status < ThermalStatus.danger From 7371b7aad5fb0ecc6c6ce5f661bc03a815bd693c Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 16:59:45 -0400 Subject: [PATCH 10/24] wrong int flag --- common/params.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/params.cc b/common/params.cc index b683609194..5c7a30d012 100644 --- a/common/params.cc +++ b/common/params.cc @@ -323,7 +323,7 @@ std::unordered_map keys = { {"VisionCurveLaneless", PERSISTENT | BACKUP}, {"VwAccType", PERSISTENT | BACKUP}, {"VwCCOnly", PERSISTENT | BACKUP}, - {"Offroad_ForceStatus", PERSISTENT}, + {"Offroad_ForceStatus", CLEAR_ON_MANAGER_START}, {"Offroad_SupersededUpdate", PERSISTENT}, {"SunnylinkCache_Users", PERSISTENT}, From 4abdf85dd13eeda94a43e3b125c1bd30f3e711c4 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 17:01:27 -0400 Subject: [PATCH 11/24] use the param instead --- selfdrive/ui/qt/offroad/settings.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 9332b49248..f43c92d3a0 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -529,7 +529,7 @@ void DevicePanel::updateLabels() { return; } - offroad_btn->setText(is_onroad ? tr("Force Offroad") : tr("Unforce Offroad")); + offroad_btn->setText(params.getBool("ForceOffroad") ? tr("Unforce Offroad") : tr("Force Offroad")); } void SettingsWindow::showEvent(QShowEvent *event) { From c0f46cd44ad2ee61d8471e616597607d7d5cbb51 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 17:06:41 -0400 Subject: [PATCH 12/24] do this instead, and flip the logics --- selfdrive/ui/qt/offroad/settings.cc | 21 +++++++++------------ selfdrive/ui/qt/offroad/settings.h | 3 --- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index f43c92d3a0..7a265cb797 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -420,11 +420,6 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) { #offroad_btn:pressed { background-color: #4a4a4a; } )"); - connect(uiState(), &UIState::offroadTransition, [=](bool offroad) { - is_onroad = !offroad; - updateLabels(); - }); - updateLabels(); } @@ -502,22 +497,24 @@ void DevicePanel::poweroff() { void DevicePanel::forceoffroad() { if (!uiState()->engaged()) { - if (is_onroad) { - if (ConfirmationDialog::confirm(tr("Are you sure you want to force offroad?"), tr("Force"), this)) { - if (!uiState()->engaged()) { - params.putBool("ForceOffroad", true); - } - } - } else { + if (params.getBool("ForceOffroad")) { if (ConfirmationDialog::confirm(tr("Are you sure you want to unforce offroad?"), tr("Unforce"), this)) { if (!uiState()->engaged()) { params.remove("ForceOffroad"); } } + } else { + if (ConfirmationDialog::confirm(tr("Are you sure you want to force offroad?"), tr("Force"), this)) { + if (!uiState()->engaged()) { + params.putBool("ForceOffroad", true); + } + } } } else { ConfirmationDialog::alert(tr("Disengage to Force Offroad"), this); } + + updateLabels(); } void DevicePanel::showEvent(QShowEvent *event) { diff --git a/selfdrive/ui/qt/offroad/settings.h b/selfdrive/ui/qt/offroad/settings.h index 8ea7835b37..a29dda8ffc 100644 --- a/selfdrive/ui/qt/offroad/settings.h +++ b/selfdrive/ui/qt/offroad/settings.h @@ -76,9 +76,6 @@ private: QFileSystemWatcher *fs_watch; QPushButton *offroad_btn; - -protected: - bool is_onroad = false; }; class TogglesPanel : public ListWidget { From 92a0777aa7a38c5eb729b07eae479dedf4ba46fb Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 17:07:38 -0400 Subject: [PATCH 13/24] use this --- selfdrive/thermald/thermald.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 0ab3e0be11..961e7131cc 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -312,7 +312,7 @@ def thermald_thread(end_event, hw_queue) -> None: # user-forced status startup_conditions["not_force_offroad"] = not params.get_bool("ForceOffroad") if not startup_conditions["not_force_offroad"]: - set_offroad_alert_if_changed("Offroad_ForceStatus", True) + set_offroad_alert("Offroad_ForceStatus", True) # if the temperature enters the danger zone, go offroad to cool down onroad_conditions["device_temp_good"] = thermal_status < ThermalStatus.danger From f5cd0b91ed83b842007aab46f2795309b9c24f75 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 17:11:36 -0400 Subject: [PATCH 14/24] do this dynamically --- selfdrive/thermald/thermald.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 961e7131cc..ee6f82883b 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -311,8 +311,7 @@ def thermald_thread(end_event, hw_queue) -> None: # user-forced status startup_conditions["not_force_offroad"] = not params.get_bool("ForceOffroad") - if not startup_conditions["not_force_offroad"]: - set_offroad_alert("Offroad_ForceStatus", True) + set_offroad_alert("Offroad_ForceStatus", not startup_conditions["not_force_offroad"]) # if the temperature enters the danger zone, go offroad to cool down onroad_conditions["device_temp_good"] = thermal_status < ThermalStatus.danger From 5c5cc631bbf59d5442feb9811195ec34cbd15008 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 17:33:33 -0400 Subject: [PATCH 15/24] More professional wording --- selfdrive/controls/lib/alerts_offroad.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/controls/lib/alerts_offroad.json b/selfdrive/controls/lib/alerts_offroad.json index 13780b5221..a9533b86a5 100644 --- a/selfdrive/controls/lib/alerts_offroad.json +++ b/selfdrive/controls/lib/alerts_offroad.json @@ -58,7 +58,7 @@ "severity": 0 }, "Offroad_ForceStatus": { - "text": "sunnypilot is now in Forced Offroad mode. sunnypilot won't start until Forced Offroad mode is disabled. Go to \"Settings\" -> \"Device\" -> \"Unforce Offroad\" to get out of Force Offroad mode.", + "text": "sunnypilot is now in Forced Offroad mode. sunnypilot won't start until Forced Offroad mode is disabled. Go to \"Settings\" -> \"Device\" -> \"Unforce Offroad\" to exit Force Offroad mode.", "severity": 1 } } From f3e450db85b97cbb644bcf203c1fb3a20318c742 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 18 Apr 2024 18:22:26 -0400 Subject: [PATCH 16/24] Update CHANGELOGS.md --- CHANGELOGS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOGS.md b/CHANGELOGS.md index 18c0a9df45..2f59fff64b 100644 --- a/CHANGELOGS.md +++ b/CHANGELOGS.md @@ -16,6 +16,9 @@ sunnypilot - 0.9.7.0 (2024-xx-xx) * GitHub account pairing from device settings scanning QR code * Pairing your account will allow you to access features via our API (still WIP but accessible if you dig a little on our code 😉) * Allow inheritance of your sponsorship status, allowing you to get extra features and early access whenever applicable +* NEW❗: Forced Offroad mode + * Force sunnypilot in the offroad state even when the car is on + * When Forced Offroad mode is on, allows changing offroad-only settings even when the car is turned on * RE-ENABLED: Map-based Turn Speed Control (M-TSC) for supported platforms * openpilot Longitudianl Control available cars * Custom Stock Longitudinal Control available cars From 2bbb420d2844ed69768bae16a3283e2fdb688d43 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Fri, 19 Apr 2024 11:55:32 -0400 Subject: [PATCH 17/24] Transition to offroad --- selfdrive/thermald/thermald.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index ee6f82883b..8ed338b6e9 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -310,7 +310,9 @@ def thermald_thread(end_event, hw_queue) -> None: startup_conditions["device_booted"] = startup_conditions.get("device_booted", False) or HARDWARE.booted() # user-forced status - startup_conditions["not_force_offroad"] = not params.get_bool("ForceOffroad") + force_offroad = params.get_bool("ForceOffroad") + startup_conditions["not_force_offroad"] = not force_offroad + onroad_conditions["not_force_offroad"] = not force_offroad set_offroad_alert("Offroad_ForceStatus", not startup_conditions["not_force_offroad"]) # if the temperature enters the danger zone, go offroad to cool down From 1d19029f19eae448c2cc9d880b9bf6bbd85e9a8f Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Fri, 19 Apr 2024 11:59:58 -0400 Subject: [PATCH 18/24] cleaner --- selfdrive/thermald/thermald.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 8ed338b6e9..9797127908 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -313,7 +313,7 @@ def thermald_thread(end_event, hw_queue) -> None: force_offroad = params.get_bool("ForceOffroad") startup_conditions["not_force_offroad"] = not force_offroad onroad_conditions["not_force_offroad"] = not force_offroad - set_offroad_alert("Offroad_ForceStatus", not startup_conditions["not_force_offroad"]) + set_offroad_alert("Offroad_ForceStatus", force_offroad) # if the temperature enters the danger zone, go offroad to cool down onroad_conditions["device_temp_good"] = thermal_status < ThermalStatus.danger From 71b489a095804a62d0dc26bd74a392674de2bd06 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Sat, 20 Apr 2024 01:35:16 -0400 Subject: [PATCH 19/24] Handle button style properly --- selfdrive/ui/qt/offroad/settings.cc | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 7a265cb797..3551d9ea00 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -403,23 +403,26 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) { connect(uiState(), &UIState::offroadTransition, poweroff_btn, &QPushButton::setVisible); } - addItem(power_layout); - - // TODO: Add Force Onroad/Offroad toggle under power_layout offroad_btn = new QPushButton(tr("Toggle Onroad/Offroad")); offroad_btn->setObjectName("offroad_btn"); QObject::connect(offroad_btn, &QPushButton::clicked, this, &DevicePanel::forceoffroad); - addItem(offroad_btn); + + QVBoxLayout *buttons_layout = new QVBoxLayout(); + buttons_layout->setSpacing(24); + buttons_layout->addLayout(power_layout); + buttons_layout->addWidget(offroad_btn); setStyleSheet(R"( #reboot_btn { height: 120px; border-radius: 15px; background-color: #393939; } #reboot_btn:pressed { background-color: #4a4a4a; } #poweroff_btn { height: 120px; border-radius: 15px; background-color: #E22C2C; } #poweroff_btn:pressed { background-color: #FF2424; } - #offroad_btn { height: 120px; border-radius: 15px; background-color: #393939; } - #offroad_btn:pressed { background-color: #4a4a4a; } + #offroad_btn { height: 120px; border-radius: 15px; background-color: #E22C2C; } + #offroad_btn:pressed { background-color: #FF2424; } )"); + addItem(buttons_layout); + updateLabels(); } @@ -526,7 +529,16 @@ void DevicePanel::updateLabels() { return; } - offroad_btn->setText(params.getBool("ForceOffroad") ? tr("Unforce Offroad") : tr("Force Offroad")); + bool force_offroad_param = params.getBool("ForceOffroad"); + QString offroad_btn_style = force_offroad_param ? "#393939" : "#E22C2C"; + QString offroad_btn_pressed_style = force_offroad_param ? "#4a4a4a" : "#FF2424"; + QString btn_common_style = QString("QPushButton { height: 120px; border-radius: 15px; background-color:%1; }" + "QPushButton:pressed { background-color:%2; }") + .arg(offroad_btn_style, + offroad_btn_pressed_style); + + offroad_btn->setText(force_offroad_param ? tr("Unforce Offroad") : tr("Force Offroad")); + offroad_btn->setStyleSheet(btn_common_style + offroad_btn_style + offroad_btn_pressed_style); } void SettingsWindow::showEvent(QShowEvent *event) { From 1ba739c372a38e6960f80d3d1ccb7bc0230e13c2 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Sat, 20 Apr 2024 01:36:09 -0400 Subject: [PATCH 20/24] less --- selfdrive/ui/qt/offroad/settings.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 3551d9ea00..f1e1e39d86 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -417,8 +417,6 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) { #reboot_btn:pressed { background-color: #4a4a4a; } #poweroff_btn { height: 120px; border-radius: 15px; background-color: #E22C2C; } #poweroff_btn:pressed { background-color: #FF2424; } - #offroad_btn { height: 120px; border-radius: 15px; background-color: #E22C2C; } - #offroad_btn:pressed { background-color: #FF2424; } )"); addItem(buttons_layout); From da14ac9bff0ff36bde4ca6310c996c806605841a Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Sat, 20 Apr 2024 01:37:42 -0400 Subject: [PATCH 21/24] lint --- selfdrive/ui/qt/offroad/settings.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index f1e1e39d86..ae33019ce2 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -418,7 +418,6 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) { #poweroff_btn { height: 120px; border-radius: 15px; background-color: #E22C2C; } #poweroff_btn:pressed { background-color: #FF2424; } )"); - addItem(buttons_layout); updateLabels(); From b8d2e90e6275321d5fac873ba6c1dbeeb3e20479 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Sat, 20 Apr 2024 01:39:05 -0400 Subject: [PATCH 22/24] add same comments --- selfdrive/ui/qt/offroad/settings.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index ae33019ce2..a73ca40de7 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -499,12 +499,14 @@ void DevicePanel::forceoffroad() { if (!uiState()->engaged()) { if (params.getBool("ForceOffroad")) { if (ConfirmationDialog::confirm(tr("Are you sure you want to unforce offroad?"), tr("Unforce"), this)) { + // Check engaged again in case it changed while the dialog was open if (!uiState()->engaged()) { params.remove("ForceOffroad"); } } } else { if (ConfirmationDialog::confirm(tr("Are you sure you want to force offroad?"), tr("Force"), this)) { + // Check engaged again in case it changed while the dialog was open if (!uiState()->engaged()) { params.putBool("ForceOffroad", true); } From 4757364fa9ddf9cb6f1c1e0cb0b61a002aefc958 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Sat, 20 Apr 2024 01:40:06 -0400 Subject: [PATCH 23/24] lint --- selfdrive/ui/qt/offroad/settings.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index a73ca40de7..13c7dc72ec 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -531,8 +531,8 @@ void DevicePanel::updateLabels() { bool force_offroad_param = params.getBool("ForceOffroad"); QString offroad_btn_style = force_offroad_param ? "#393939" : "#E22C2C"; QString offroad_btn_pressed_style = force_offroad_param ? "#4a4a4a" : "#FF2424"; - QString btn_common_style = QString("QPushButton { height: 120px; border-radius: 15px; background-color:%1; }" - "QPushButton:pressed { background-color:%2; }") + QString btn_common_style = QString("QPushButton { height: 120px; border-radius: 15px; background-color: %1; }" + "QPushButton:pressed { background-color: %2; }") .arg(offroad_btn_style, offroad_btn_pressed_style); From 8f3ca7a9b22ed1385e51b4d49b226a74a462c7c7 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Sun, 21 Apr 2024 12:33:59 -0400 Subject: [PATCH 24/24] do we need this to close the relay? --- selfdrive/boardd/boardd.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index b2b59d3752..ed7d7eb815 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -266,7 +266,7 @@ void can_recv_thread(std::vector pandas) { } } -std::optional send_panda_states(PubMaster *pm, const std::vector &pandas, bool spoofing_started) { +std::optional send_panda_states(PubMaster *pm, const std::vector &pandas, bool spoofing_started, Params ¶ms) { bool ignition_local = false; const uint32_t pandas_cnt = pandas.size(); @@ -314,7 +314,7 @@ std::optional send_panda_states(PubMaster *pm, const std::vector health.ignition_line_pkt = 0; } - ignition_local |= ((health.ignition_line_pkt != 0) || (health.ignition_can_pkt != 0)); + ignition_local |= ((health.ignition_line_pkt != 0) || (health.ignition_can_pkt != 0)) && !params.getBool("ForceOffroad"); pandaStates.push_back(health); } @@ -470,7 +470,7 @@ void panda_state_thread(std::vector pandas, bool spoofing_started) { send_peripheral_state(&pm, peripheral_panda); } - auto ignition_opt = send_panda_states(&pm, pandas, spoofing_started); + auto ignition_opt = send_panda_states(&pm, pandas, spoofing_started, params); if (!ignition_opt) { LOGE("Failed to get ignition_opt");