From 853fed447da65765a0ccbf9184ac926ecbe69ce7 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Mon, 12 Aug 2024 18:38:09 -0400 Subject: [PATCH] fix --- selfdrive/controls/controlsd.py | 18 ++++++++++-------- selfdrive/controls/lib/drive_helpers.py | 5 ++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 887dc1f80e..8367cca979 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -20,7 +20,7 @@ from openpilot.common.swaglog import cloudlog from openpilot.selfdrive.car.car_helpers import get_car_interface, get_startup_event from openpilot.selfdrive.controls.lib.alertmanager import AlertManager, set_offroad_alert -from openpilot.selfdrive.controls.lib.drive_helpers import VCruiseHelper, clip_curvature, get_lag_adjusted_curvature +from openpilot.selfdrive.controls.lib.drive_helpers import VCruiseHelper, clip_curvature, get_lag_adjusted_curvature, CRUISE_LONG_PRESS from openpilot.selfdrive.controls.lib.events import Events, ET from openpilot.selfdrive.controls.lib.latcontrol import LatControl, MIN_LATERAL_CONTROL_SPEED from openpilot.selfdrive.controls.lib.latcontrol_pid import LatControlPID @@ -717,18 +717,20 @@ class Controls: cloudlog.error(f"actuators.{p} not finite {actuators.to_dict()}") setattr(actuators, p, 0.0) - # decrement personality on distance button press - if self.CP.openpilotLongitudinalControl: - if any(not be.pressed and be.type == ButtonType.gapAdjustCruise for be in CS.buttonEvents): - self.personality = (self.personality - 1) % 3 - self.params.put_nonblocking('LongitudinalPersonality', str(self.personality)) - # toggle experimental mode once on distance button hold if self.CP.openpilotLongitudinalControl: - if self.v_cruise_helper.experimental_mode_update and self.v_cruise_helper.button_timers[ButtonType.gapAdjustCruise] == 50: + if self.v_cruise_helper.experimental_mode_update and self.v_cruise_helper.button_timers[ButtonType.gapAdjustCruise] == CRUISE_LONG_PRESS: self.experimental_mode = not self.experimental_mode self.params.put_bool_nonblocking("ExperimentalMode", self.experimental_mode) + # decrement personality on distance button press + if self.CP.openpilotLongitudinalControl: + if any(not be.pressed and be.type == ButtonType.gapAdjustCruise for be in CS.buttonEvents) and \ + not self.v_cruise_helper.experimental_mode_update: + self.personality = (self.personality - 1) % 3 + self.params.put_nonblocking('LongitudinalPersonality', str(self.personality)) + self.v_cruise_helper.experimental_mode_update = False + return CC, lac_log def publish_logs(self, CS, start_time, CC, lac_log): diff --git a/selfdrive/controls/lib/drive_helpers.py b/selfdrive/controls/lib/drive_helpers.py index 2b03974222..cc5d19209c 100644 --- a/selfdrive/controls/lib/drive_helpers.py +++ b/selfdrive/controls/lib/drive_helpers.py @@ -113,6 +113,7 @@ class VCruiseHelper: else: self.v_cruise_kph = V_CRUISE_UNSET self.v_cruise_cluster_kph = V_CRUISE_UNSET + self.experimental_mode_update = False def _update_v_cruise_non_pcm(self, CS, enabled, is_metric, reverse_acc): # handle button presses. TODO: this should be in state_control, but a decelCruise press @@ -242,15 +243,13 @@ class VCruiseHelper: self.is_metric_prev = is_metric def _update_experimental_mode(self, CS): - self.experimental_mode_update = False - for b in CS.buttonEvents: if b.type == ButtonType.gapAdjustCruise and not b.pressed: if self.button_timers[ButtonType.gapAdjustCruise] > CRUISE_LONG_PRESS: return # end long press break else: - if self.button_timers[ButtonType.gapAdjustCruise] and self.button_timers[ButtonType.gapAdjustCruise] % CRUISE_LONG_PRESS == 0: + if self.button_timers[ButtonType.gapAdjustCruise] and self.button_timers[ButtonType.gapAdjustCruise] == CRUISE_LONG_PRESS: self.experimental_mode_update = True