From 38d8d6f650523c8741de99f5c4effc51a583e0e1 Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Sat, 27 Apr 2024 12:13:55 -0700 Subject: [PATCH] Increase max speed faster on short presses Added toggle to increase the value of the max speed by 5 instead of 1 for Toyota/Lexus and a custom set value for other makes. --- common/params.cc | 4 +++ selfdrive/car/toyota/toyotacan.py | 2 +- selfdrive/controls/controlsd.py | 5 ++- selfdrive/controls/lib/drive_helpers.py | 11 ++++--- .../ui/qt/offroad/control_settings.cc | 28 ++++++++++++++++ .../ui/qt/offroad/control_settings.h | 2 +- selfdrive/ui/qt/onroad.cc | 32 ++++++++++++++++--- selfdrive/ui/qt/onroad.h | 2 ++ selfdrive/ui/ui.cc | 2 ++ selfdrive/ui/ui.h | 2 ++ 10 files changed, 77 insertions(+), 13 deletions(-) diff --git a/common/params.cc b/common/params.cc index 27fd68255..3390cefad 100644 --- a/common/params.cc +++ b/common/params.cc @@ -245,6 +245,8 @@ std::unordered_map keys = { {"CurrentHolidayTheme", PERSISTENT}, {"CustomAlerts", PERSISTENT}, {"CustomColors", PERSISTENT}, + {"CustomCruise", PERSISTENT}, + {"CustomCruiseLong", PERSISTENT}, {"CustomIcons", PERSISTENT}, {"CustomPaths", PERSISTENT}, {"CustomPersonalities", PERSISTENT}, @@ -309,6 +311,8 @@ std::unordered_map keys = { {"RefuseVolume", PERSISTENT}, {"RelaxedFollow", PERSISTENT}, {"RelaxedJerk", PERSISTENT}, + {"ReverseCruise", PERSISTENT}, + {"ReverseCruiseUI", PERSISTENT}, {"RoadEdgesWidth", PERSISTENT}, {"ShowCPU", PERSISTENT}, {"ShowGPU", PERSISTENT}, diff --git a/selfdrive/car/toyota/toyotacan.py b/selfdrive/car/toyota/toyotacan.py index 4a441d2e5..9544c6fa4 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 246388779..f9eebd067 100644 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -472,7 +472,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 @@ -973,6 +973,9 @@ 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.custom_cruise_increase = self.params.get_int("CustomCruise") if quality_of_life else 1 + self.frogpilot_variables.custom_cruise_increase_long = self.params.get_int("CustomCruiseLong") if quality_of_life else 5 + self.frogpilot_variables.reverse_cruise_increase = quality_of_life and self.params.get_bool("ReverseCruise") def main(): config_realtime_process(4, Priority.CTRL_HIGH) diff --git a/selfdrive/controls/lib/drive_helpers.py b/selfdrive/controls/lib/drive_helpers.py index 3864d28cc..770ba32dd 100644 --- a/selfdrive/controls/lib/drive_helpers.py +++ b/selfdrive/controls/lib/drive_helpers.py @@ -53,13 +53,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: @@ -69,7 +69,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: @@ -105,8 +105,9 @@ class VCruiseHelper: if not self.button_change_states[button_type]["enabled"]: return - v_cruise_delta = v_cruise_delta * (5 if long_press else 1) - if long_press and self.v_cruise_kph % v_cruise_delta != 0: # partial interval + v_cruise_delta_interval = frogpilot_variables.custom_cruise_increase_long if long_press else frogpilot_variables.custom_cruise_increase + v_cruise_delta = v_cruise_delta * v_cruise_delta_interval + if v_cruise_delta_interval % 5 == 0 and self.v_cruise_kph % v_cruise_delta != 0: # partial interval self.v_cruise_kph = CRUISE_NEAREST_FUNC[button_type](self.v_cruise_kph / v_cruise_delta) * v_cruise_delta else: self.v_cruise_kph += v_cruise_delta * CRUISE_INTERVAL_SIGN[button_type] diff --git a/selfdrive/frogpilot/ui/qt/offroad/control_settings.cc b/selfdrive/frogpilot/ui/qt/offroad/control_settings.cc index 1a07b9266..3d3b4202b 100644 --- a/selfdrive/frogpilot/ui/qt/offroad/control_settings.cc +++ b/selfdrive/frogpilot/ui/qt/offroad/control_settings.cc @@ -43,7 +43,10 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil {"AggressiveAcceleration", tr("Increase Acceleration Behind Faster Lead"), tr("Increase aggressiveness when following a faster lead."), ""}, {"QOLControls", tr("Quality of Life"), tr("Miscellaneous quality of life changes to improve your overall openpilot experience."), "../frogpilot/assets/toggle_icons/quality_of_life.png"}, + {"CustomCruise", tr("Cruise Increase Interval"), tr("Set a custom interval to increase the max set speed by."), ""}, + {"CustomCruiseLong", tr("Cruise Increase Interval (Long Press)"), tr("Set a custom interval to increase the max set speed by when holding down the cruise increase button."), ""}, {"DisableOnroadUploads", tr("Disable Onroad Uploads"), tr("Prevent uploads to comma connect unless you're offroad and connected to Wi-Fi."), ""}, + {"ReverseCruise", tr("Reverse Cruise Increase"), tr("Reverses the 'long press' functionality logic to increase the max set speed by 5 instead of 1. Useful to increase the max speed quickly."), ""}, }; for (const auto &[param, title, desc, icon] : controlToggles) { @@ -227,10 +230,25 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil for (auto &[key, toggle] : toggles) { std::set modifiedQolKeys = qolKeys; + if (!hasPCMCruise) { + modifiedQolKeys.erase("ReverseCruise"); + } else { + modifiedQolKeys.erase("CustomCruise"); + modifiedQolKeys.erase("CustomCruiseLong"); + } + toggle->setVisible(modifiedQolKeys.find(key.c_str()) != modifiedQolKeys.end()); } }); toggle = qolToggle; + } else if (param == "CustomCruise") { + toggle = new FrogPilotParamValueControl(param, title, desc, icon, 1, 99, std::map(), this, false, tr(" mph")); + } else if (param == "CustomCruiseLong") { + toggle = new FrogPilotParamValueControl(param, title, desc, icon, 1, 99, std::map(), this, false, tr(" mph")); + } 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); @@ -369,17 +387,27 @@ void FrogPilotControlsPanel::updateMetric() { params.putIntNonBlocking("CESpeed", std::nearbyint(params.getInt("CESpeed") * speedConversion)); params.putIntNonBlocking("CESpeedLead", std::nearbyint(params.getInt("CESpeedLead") * speedConversion)); + params.putIntNonBlocking("CustomCruise", std::nearbyint(params.getInt("CustomCruise") * speedConversion)); + params.putIntNonBlocking("CustomCruiseLong", std::nearbyint(params.getInt("CustomCruiseLong") * speedConversion)); params.putIntNonBlocking("PauseAOLOnBrake", std::nearbyint(params.getInt("PauseAOLOnBrake") * speedConversion)); } + FrogPilotParamValueControl *customCruiseToggle = static_cast(toggles["CustomCruise"]); + FrogPilotParamValueControl *customCruiseLongToggle = static_cast(toggles["CustomCruiseLong"]); FrogPilotParamValueControl *pauseAOLOnBrakeToggle = static_cast(toggles["PauseAOLOnBrake"]); if (isMetric) { + customCruiseToggle->updateControl(1, 150, tr(" kph")); + customCruiseLongToggle->updateControl(1, 150, tr(" kph")); pauseAOLOnBrakeToggle->updateControl(0, 99, tr(" kph")); } else { + customCruiseToggle->updateControl(1, 99, tr(" mph")); + customCruiseLongToggle->updateControl(1, 99, tr(" mph")); pauseAOLOnBrakeToggle->updateControl(0, 99, tr(" mph")); } + customCruiseToggle->refresh(); + customCruiseLongToggle->refresh(); pauseAOLOnBrakeToggle->refresh(); } diff --git a/selfdrive/frogpilot/ui/qt/offroad/control_settings.h b/selfdrive/frogpilot/ui/qt/offroad/control_settings.h index 72f86ee9f..f5279367f 100644 --- a/selfdrive/frogpilot/ui/qt/offroad/control_settings.h +++ b/selfdrive/frogpilot/ui/qt/offroad/control_settings.h @@ -39,7 +39,7 @@ private: std::set lateralTuneKeys = {"ForceAutoTune"}; std::set longitudinalTuneKeys = {"AccelerationProfile", "AggressiveAcceleration", "DecelerationProfile"}; std::set mtscKeys = {}; - std::set qolKeys = {"DisableOnroadUploads"}; + std::set qolKeys = {"CustomCruise", "CustomCruiseLong", "DisableOnroadUploads", "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 a23fb013d..7cb20f74c 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -103,15 +103,33 @@ 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()) && scene.reverse_cruise_ui; + // Hide speed button QRect hideSpeedRect(rect().center().x() - 175, 50, 350, 350); bool isSpeedClicked = hideSpeedRect.contains(e->pos()) && scene.hide_speed_ui; - if (isSpeedClicked) { - bool currentHideSpeed = scene.hide_speed; + if (isMaxSpeedClicked || isSpeedClicked) { + if (isMaxSpeedClicked) { + std::thread([this]() { + bool currentReverseCruise = scene.reverse_cruise; - uiState()->scene.hide_speed = !currentHideSpeed; - params.putBoolNonBlocking("HideSpeed", !currentHideSpeed); + uiState()->scene.reverse_cruise = !currentReverseCruise; + params.putBoolNonBlocking("ReverseCruise", !currentReverseCruise); + + paramsMemory.putBool("FrogPilotTogglesUpdated", true); + std::this_thread::sleep_for(std::chrono::seconds(1)); + paramsMemory.putBool("FrogPilotTogglesUpdated", false); + }).detach(); + + } else if (isSpeedClicked) { + 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" @@ -508,7 +526,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(blueColor(), 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/qt/onroad.h b/selfdrive/ui/qt/onroad.h index c0ae56082..826df7ef8 100644 --- a/selfdrive/ui/qt/onroad.h +++ b/selfdrive/ui/qt/onroad.h @@ -161,6 +161,8 @@ private: QTimer *animationTimer; + inline QColor blueColor(int alpha = 255) { return QColor(0, 150, 255, alpha); } + protected: void paintGL() override; void initializeGL() override; diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index f4248e51e..4a27a95bf 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -331,6 +331,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.big_map = quality_of_life_visuals && params.getBool("BigMap"); diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 9942bb0ae..dec6b04f4 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -197,6 +197,8 @@ typedef struct UIScene { bool map_open; bool model_ui; bool reverse; + bool reverse_cruise; + bool reverse_cruise_ui; bool right_hand_drive; bool show_aol_status_bar; bool show_cem_status_bar;