From 4f155e7f655fd029e0b4437df7a44c4a2b159e08 Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:34:47 -0700 Subject: [PATCH] Increase max speed by 5 on short press Added toggle to increase the value of the max speed by 5 instead of 1 and an additional function to enable/disable it by taping the "Max" speed icon in the onroad UI. --- common/params.cc | 2 ++ selfdrive/car/toyota/toyotacan.py | 2 +- selfdrive/controls/controlsd.py | 3 ++- selfdrive/controls/lib/drive_helpers.py | 10 ++++++--- selfdrive/frogpilot/ui/control_settings.cc | 5 +++++ selfdrive/frogpilot/ui/control_settings.h | 2 +- selfdrive/ui/qt/onroad.cc | 26 +++++++++++++++++----- selfdrive/ui/ui.cc | 2 ++ selfdrive/ui/ui.h | 2 ++ 9 files changed, 43 insertions(+), 11 deletions(-) diff --git a/common/params.cc b/common/params.cc index 3a93907b1..fee8d0061 100644 --- a/common/params.cc +++ b/common/params.cc @@ -292,6 +292,8 @@ std::unordered_map keys = { {"RefuseVolume", PERSISTENT}, {"RelaxedFollow", PERSISTENT}, {"RelaxedJerk", PERSISTENT}, + {"ReverseCruise", PERSISTENT}, + {"ReverseCruiseUI", PERSISTENT}, {"RoadEdgesWidth", PERSISTENT}, {"SilentMode", PERSISTENT}, {"ShowCPU", PERSISTENT}, diff --git a/selfdrive/car/toyota/toyotacan.py b/selfdrive/car/toyota/toyotacan.py index ab2579714..6d74e75a5 100644 --- a/selfdrive/car/toyota/toyotacan.py +++ b/selfdrive/car/toyota/toyotacan.py @@ -43,7 +43,7 @@ def create_accel_command(packer, accel, accel_raw, pcm_cancel, standstill_req, l "PERMIT_BRAKING": 1, "RELEASE_STANDSTILL": not standstill_req, "CANCEL_REQ": pcm_cancel, - "ALLOW_LONG_PRESS": 1, + "ALLOW_LONG_PRESS": 2 if frogpilot_variables.reverse_cruise_increase else 1, "ACC_CUT_IN": fcw_alert, # only shown when ACC enabled "ACCEL_CMD_ALT": accel_raw, # raw accel command, pcm uses this to calculate a compensatory force } diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 4d6259505..3a689d6ec 100644 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -603,7 +603,7 @@ class Controls: def state_transition(self, CS): """Compute conditional state transitions and execute actions on state transitions""" - self.v_cruise_helper.update_v_cruise(CS, self.enabled, self.is_metric) + self.v_cruise_helper.update_v_cruise(CS, self.enabled, self.is_metric, self.frogpilot_variables) # decrement the soft disable timer at every step, as it's reset on # entrance in SOFT_DISABLING state @@ -1057,6 +1057,7 @@ class Controls: self.frogpilot_variables.sport_plus = longitudinal_tune and self.params.get_int("AccelerationProfile") == 3 quality_of_life = self.params.get_bool("QOLControls") + self.frogpilot_variables.reverse_cruise_increase = quality_of_life and self.params.get_bool("ReverseCruise") def main(): controls = Controls() diff --git a/selfdrive/controls/lib/drive_helpers.py b/selfdrive/controls/lib/drive_helpers.py index 732437319..ac967f21c 100644 --- a/selfdrive/controls/lib/drive_helpers.py +++ b/selfdrive/controls/lib/drive_helpers.py @@ -52,13 +52,13 @@ class VCruiseHelper: def v_cruise_initialized(self): return self.v_cruise_kph != V_CRUISE_UNSET - def update_v_cruise(self, CS, enabled, is_metric): + def update_v_cruise(self, CS, enabled, is_metric, frogpilot_variables): self.v_cruise_kph_last = self.v_cruise_kph if CS.cruiseState.available: if not self.CP.pcmCruise: # if stock cruise is completely disabled, then we can use our own set speed logic - self._update_v_cruise_non_pcm(CS, enabled, is_metric) + self._update_v_cruise_non_pcm(CS, enabled, is_metric, frogpilot_variables) self.v_cruise_cluster_kph = self.v_cruise_kph self.update_button_timers(CS, enabled) else: @@ -68,7 +68,7 @@ class VCruiseHelper: self.v_cruise_kph = V_CRUISE_UNSET self.v_cruise_cluster_kph = V_CRUISE_UNSET - def _update_v_cruise_non_pcm(self, CS, enabled, is_metric): + def _update_v_cruise_non_pcm(self, CS, enabled, is_metric, frogpilot_variables): # handle button presses. TODO: this should be in state_control, but a decelCruise press # would have the effect of both enabling and changing speed is checked after the state transition if not enabled: @@ -92,6 +92,10 @@ class VCruiseHelper: long_press = True break + # Reverse the long press value for reverse cruise increase + if frogpilot_variables.reverse_cruise_increase: + long_press = not long_press + if button_type is None: return diff --git a/selfdrive/frogpilot/ui/control_settings.cc b/selfdrive/frogpilot/ui/control_settings.cc index 53e833264..3e5d32083 100644 --- a/selfdrive/frogpilot/ui/control_settings.cc +++ b/selfdrive/frogpilot/ui/control_settings.cc @@ -31,6 +31,7 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil {"QOLControls", "Quality of Life", "Miscellaneous quality of life changes to improve your overall openpilot experience.", "../frogpilot/assets/toggle_icons/quality_of_life.png"}, {"DisableOnroadUploads", "Disable Onroad Uploads", "Prevent large data uploads when onroad.", ""}, {"HigherBitrate", "Higher Bitrate Recording", "Increases the quality of the footage uploaded to comma connect.", ""}, + {"ReverseCruise", "Reverse Cruise Increase", "Reverses the 'long press' functionality when increasing the max set speed. Useful to increase the max speed quickly.", ""}, }; for (const auto &[param, title, desc, icon] : controlToggles) { @@ -209,6 +210,10 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil } }); toggle = qolToggle; + } else if (param == "ReverseCruise") { + std::vector reverseCruiseToggles{"ReverseCruiseUI"}; + std::vector reverseCruiseNames{tr("Control Via UI")}; + toggle = new FrogPilotParamToggleControl(param, title, desc, icon, reverseCruiseToggles, reverseCruiseNames); } else { toggle = new ParamControl(param, title, desc, icon, this); diff --git a/selfdrive/frogpilot/ui/control_settings.h b/selfdrive/frogpilot/ui/control_settings.h index 5cf006ba6..bd9a10557 100644 --- a/selfdrive/frogpilot/ui/control_settings.h +++ b/selfdrive/frogpilot/ui/control_settings.h @@ -41,7 +41,7 @@ private: std::set lateralTuneKeys = {"ForceAutoTune"}; std::set longitudinalTuneKeys = {"AccelerationProfile", "DecelerationProfile", "AggressiveAcceleration"}; std::set mtscKeys = {}; - std::set qolKeys = {"DisableOnroadUploads", "HigherBitrate"}; + std::set qolKeys = {"DisableOnroadUploads", "HigherBitrate", "ReverseCruise"}; std::set speedLimitControllerKeys = {}; std::set speedLimitControllerControlsKeys = {}; std::set speedLimitControllerQOLKeys = {}; diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index 2bf3e550f..3c3756c38 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -105,15 +105,27 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) { // FrogPilot clickable widgets bool widgetClicked = false; + // Change cruise control increments button + QRect maxSpeedRect(7, 25, 225, 225); + bool isMaxSpeedClicked = maxSpeedRect.contains(e->pos()); + // Hide speed button QRect hideSpeedRect(rect().center().x() - 175, 50, 350, 350); bool isSpeedClicked = hideSpeedRect.contains(e->pos()); - if (isSpeedClicked && scene.hide_speed_ui) { - bool currentHideSpeed = scene.hide_speed; + if (isMaxSpeedClicked || isSpeedClicked) { + if (isMaxSpeedClicked && scene.reverse_cruise_ui) { + bool currentReverseCruise = scene.reverse_cruise; - uiState()->scene.hide_speed = !currentHideSpeed; - params.putBoolNonBlocking("HideSpeed", !currentHideSpeed); + uiState()->scene.reverse_cruise = !currentReverseCruise; + params.putBoolNonBlocking("ReverseCruise", !currentReverseCruise); + + } else if (isSpeedClicked && scene.hide_speed_ui) { + bool currentHideSpeed = scene.hide_speed; + + uiState()->scene.hide_speed = !currentHideSpeed; + params.putBoolNonBlocking("HideSpeed", !currentHideSpeed); + } widgetClicked = true; // If the click wasn't for anything specific, change the value of "ExperimentalMode" @@ -482,7 +494,11 @@ void AnnotatedCameraWidget::drawHud(QPainter &p) { int bottom_radius = has_eu_speed_limit ? 100 : 32; QRect set_speed_rect(QPoint(60 + (default_size.width() - set_speed_size.width()) / 2, 45), set_speed_size); - p.setPen(QPen(whiteColor(75), 6)); + if (scene.reverse_cruise) { + p.setPen(QPen(QColor(0, 150, 255), 6)); + } else { + p.setPen(QPen(whiteColor(75), 6)); + } p.setBrush(blackColor(166)); drawRoundedRect(p, set_speed_rect, top_radius, top_radius, bottom_radius, bottom_radius); diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index fbe567395..81b84d8f3 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -318,6 +318,8 @@ void ui_update_frogpilot_params(UIState *s) { scene.unlimited_road_ui_length = scene.model_ui && params.getBool("UnlimitedLength"); bool quality_of_life_controls = params.getBool("QOLControls"); + scene.reverse_cruise = quality_of_life_controls && params.getBool("ReverseCruise"); + scene.reverse_cruise_ui = scene.reverse_cruise && params.getBool("ReverseCruiseUI"); bool quality_of_life_visuals = params.getBool("QOLVisuals"); scene.full_map = quality_of_life_visuals && params.getBool("FullMap"); diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 5aee36cd1..85600d607 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -190,6 +190,8 @@ typedef struct UIScene { bool lead_info; bool map_open; bool model_ui; + bool reverse_cruise; + bool reverse_cruise_ui; bool show_driver_camera; bool turn_signal_left; bool turn_signal_right;