From fff3c30ce5c07f2fd6b4168b51ee06c89bf8fec7 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 30 May 2024 02:40:24 +0000 Subject: [PATCH 1/2] `SPOptionControl`: Dim button if the option cannot be adjusted --- selfdrive/ui/qt/widgets/controls.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/selfdrive/ui/qt/widgets/controls.h b/selfdrive/ui/qt/widgets/controls.h index 6b34c8cde1..3466b67f5e 100644 --- a/selfdrive/ui/qt/widgets/controls.h +++ b/selfdrive/ui/qt/widgets/controls.h @@ -483,14 +483,17 @@ public: } button_group->addButton(button, i); - int change_value = (i == 0) ? -per_value_change : per_value_change; - QObject::connect(button, &QPushButton::clicked, [=]() { + int change_value = (i == 0) ? -per_value_change : per_value_change; key = param.toStdString(); value = atoi(params.get(key).c_str()); value += change_value; value = std::clamp(value, range.min_value, range.max_value); params.put(key, QString::number(value).toStdString()); + + button_group->button(0)->setEnabled(!(value <= range.min_value)); + button_group->button(1)->setEnabled(!(value >= range.max_value)); + updateLabels(); if (request_update) { From d8595b63e82720b16bc4d6c6bc195bf0d5e125ff Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 30 May 2024 02:42:11 +0000 Subject: [PATCH 2/2] Auto Lane Change: Add option to disable lane change --- CHANGELOGS.md | 2 ++ selfdrive/controls/controlsd.py | 2 -- selfdrive/controls/lib/desire_helper.py | 3 ++- .../qt/offroad/sunnypilot/lane_change_settings.cc | 14 ++++++++------ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOGS.md b/CHANGELOGS.md index ef4c4827b9..7fb80c26b6 100644 --- a/CHANGELOGS.md +++ b/CHANGELOGS.md @@ -27,6 +27,8 @@ sunnypilot - 0.9.7.0 (2024-05-xx) * 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 +* UPDATED: Auto Lane Change Timer -> Auto Lane Change by Blinker + * NEW❗: New "Off" option to disable lane change by blinker * UPDATED: Hyundai CAN Longitudinal * Auto-enable radar tracks on platforms with applicable Mando radar * UPDATED: Hyundai CAN-FD Camera-based SCC diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index a0da74f930..171daf091b 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -167,7 +167,6 @@ class Controls: self.nn_alert_shown = False self.enable_nnff = self.params.get_bool("NNFF") - self.lane_change_set_timer = int(self.params.get("AutoLaneChangeTimer", encoding="utf8")) self.reverse_acc_change = False self.dynamic_experimental_control = False @@ -935,7 +934,6 @@ class Controls: if self.CP.notCar: self.joystick_mode = self.params.get_bool("JoystickDebugMode") - self.lane_change_set_timer = int(self.params.get("AutoLaneChangeTimer", encoding="utf8")) self.reverse_acc_change = self.params.get_bool("ReverseAccChange") self.dynamic_experimental_control = self.params.get_bool("DynamicExperimentalControl") diff --git a/selfdrive/controls/lib/desire_helper.py b/selfdrive/controls/lib/desire_helper.py index 6cac8a70e2..d6eec9b603 100644 --- a/selfdrive/controls/lib/desire_helper.py +++ b/selfdrive/controls/lib/desire_helper.py @@ -34,6 +34,7 @@ DESIRES = { } AUTO_LANE_CHANGE_TIMER = { + -1: 0.0, 0: 0.0, 1: 0.1, 2: 0.5, @@ -84,7 +85,7 @@ class DesireHelper: if self.model_use_lateral_planner: self.road_edge = get_road_edge(carstate, model_data, self.edge_toggle) - if not carstate.madsEnabled or self.lane_change_timer > LANE_CHANGE_TIME_MAX: + if not carstate.madsEnabled or self.lane_change_timer > LANE_CHANGE_TIME_MAX or self.lane_change_set_timer == -1: self.lane_change_state = LaneChangeState.off self.lane_change_direction = LaneChangeDirection.none self.prev_lane_change = False diff --git a/selfdrive/ui/qt/offroad/sunnypilot/lane_change_settings.cc b/selfdrive/ui/qt/offroad/sunnypilot/lane_change_settings.cc index e24425a6fc..d2cf106bd3 100644 --- a/selfdrive/ui/qt/offroad/sunnypilot/lane_change_settings.cc +++ b/selfdrive/ui/qt/offroad/sunnypilot/lane_change_settings.cc @@ -64,7 +64,7 @@ void LaneChangeSettings::updateToggles() { } auto auto_lane_change_bsm_delay_toggle = toggles["AutoLaneChangeBsmDelay"]; - auto auto_lane_change_timer_param = QString::fromStdString(params.get("AutoLaneChangeTimer")); + auto auto_lane_change_timer_param = std::atoi(params.get("AutoLaneChangeTimer").c_str()); auto cp_bytes = params.get("CarParamsPersistent"); if (!cp_bytes.empty()) { @@ -75,7 +75,7 @@ void LaneChangeSettings::updateToggles() { 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->setEnabled(CP.getEnableBsm() && (auto_lane_change_timer_param > 0)); auto_lane_change_bsm_delay_toggle->refresh(); } else { @@ -86,10 +86,10 @@ void LaneChangeSettings::updateToggles() { // Auto Lane Change Timer (ALCT) AutoLaneChangeTimer::AutoLaneChangeTimer() : SPOptionControl ( "AutoLaneChangeTimer", - tr("Auto Lane Change Timer"), - 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.\nPlease use caution when using this feature. Only use the blinker when traffic and road conditions permit."), + 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.\nPlease use caution when using this feature. Only use the blinker when traffic and road conditions permit."), "../assets/offroad/icon_blank.png", - {0, 5}) { + {-1, 5}) { refresh(); } @@ -97,7 +97,9 @@ AutoLaneChangeTimer::AutoLaneChangeTimer() : SPOptionControl ( void AutoLaneChangeTimer::refresh() { QString option = QString::fromStdString(params.get("AutoLaneChangeTimer")); QString second = tr("s"); - if (option == "0") { + if (option == "-1") { + setLabel(tr("Off")); + } else if (option == "0") { setLabel(tr("Nudge")); } else if (option == "1") { setLabel(tr("Nudgeless"));