From bf41202cab54537194cca8b20c110cd45ba7b35c Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Wed, 29 May 2024 08:43:12 -0400 Subject: [PATCH] Auto Lane Change: Add option to disable lane change --- selfdrive/controls/controlsd.py | 2 -- selfdrive/controls/lib/desire_helper.py | 3 ++- .../qt/offroad/sunnypilot/lane_change_settings.cc | 14 ++++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) 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..94d57c5e2c 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"), + 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"));