From a1cbffe6f5e6017bf1f35921e1976876c3c57939 Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Fri, 18 Aug 2023 23:36:19 -0700 Subject: [PATCH] Increase max speed by 5 for Toyota vehicles on short press Added function to increase the value of the max speed by 5 instead of 1 by taping the "Max" speed icon in the onroad UI. --- cereal/car.capnp | 1 + common/params.cc | 1 + selfdrive/car/toyota/carcontroller.py | 4 ++-- selfdrive/car/toyota/toyotacan.py | 4 ++-- selfdrive/controls/controlsd.py | 6 ++++++ selfdrive/ui/qt/onroad.cc | 24 +++++++++++++++++++++--- selfdrive/ui/qt/onroad.h | 1 + 7 files changed, 34 insertions(+), 7 deletions(-) diff --git a/cereal/car.capnp b/cereal/car.capnp index 6a03e9a4f8039f..69daf1db980eee 100644 --- a/cereal/car.capnp +++ b/cereal/car.capnp @@ -331,6 +331,7 @@ struct CarControl { rightBlinker @16: Bool; # FrogPilot CarControls + reverseCruise @18: Bool; # Any car specific rate limits or quirks applied by # the CarController are reflected in actuatorsOutput diff --git a/common/params.cc b/common/params.cc index 8345921edcaacc..50050805c72d8e 100644 --- a/common/params.cc +++ b/common/params.cc @@ -211,6 +211,7 @@ std::unordered_map keys = { {"RecordFront", PERSISTENT}, {"RecordFrontLock", PERSISTENT}, // for the internal fleet {"ReplayControlsState", CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION}, + {"ReverseCruiseIncrease", PERSISTENT}, {"RoadEdgesWidth", PERSISTENT}, {"RotatingWheel", PERSISTENT}, {"ScreenBrightness", PERSISTENT}, diff --git a/selfdrive/car/toyota/carcontroller.py b/selfdrive/car/toyota/carcontroller.py index d2558b5b29ae0b..f743123f6e1baf 100644 --- a/selfdrive/car/toyota/carcontroller.py +++ b/selfdrive/car/toyota/carcontroller.py @@ -133,10 +133,10 @@ def update(self, CC, CS, now_nanos): if pcm_cancel_cmd and self.CP.carFingerprint in UNSUPPORTED_DSU_CAR: can_sends.append(create_acc_cancel_command(self.packer)) elif self.CP.openpilotLongitudinalControl: - can_sends.append(create_accel_command(self.packer, pcm_accel_cmd, pcm_cancel_cmd, self.standstill_req, lead, CS.acc_type)) + can_sends.append(create_accel_command(self.packer, pcm_accel_cmd, pcm_cancel_cmd, self.standstill_req, lead, CS.acc_type, CC.reverseCruise)) self.accel = pcm_accel_cmd else: - can_sends.append(create_accel_command(self.packer, 0, pcm_cancel_cmd, False, lead, CS.acc_type)) + can_sends.append(create_accel_command(self.packer, 0, pcm_cancel_cmd, False, lead, CS.acc_type, CC.reverseCruise)) if self.frame % 2 == 0 and self.CP.enableGasInterceptor and self.CP.openpilotLongitudinalControl: # send exactly zero if gas cmd is zero. Interceptor will send the max between read value and gas cmd. diff --git a/selfdrive/car/toyota/toyotacan.py b/selfdrive/car/toyota/toyotacan.py index 0c3330efa22f07..4fb8f1ee22de0f 100644 --- a/selfdrive/car/toyota/toyotacan.py +++ b/selfdrive/car/toyota/toyotacan.py @@ -27,7 +27,7 @@ def create_lta_steer_command(packer, steer_angle, steer_req, frame, setme_x64): return packer.make_can_msg("STEERING_LTA", 0, values) -def create_accel_command(packer, accel, pcm_cancel, standstill_req, lead, acc_type): +def create_accel_command(packer, accel, pcm_cancel, standstill_req, lead, acc_type, reverse_cruise): # TODO: find the exact canceling bit that does not create a chime values = { "ACCEL_CMD": accel, @@ -37,7 +37,7 @@ def create_accel_command(packer, accel, pcm_cancel, standstill_req, lead, acc_ty "PERMIT_BRAKING": 1, "RELEASE_STANDSTILL": not standstill_req, "CANCEL_REQ": pcm_cancel, - "ALLOW_LONG_PRESS": 1, + "ALLOW_LONG_PRESS": 2 if reverse_cruise else 1, } return packer.make_can_msg("ACC_CONTROL", 0, values) diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index a3e717ff315904..24c51e9ee2a30c 100644 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -122,6 +122,7 @@ def __init__(self, sm=None, pm=None, can_sock=None, CI=None): # FrogPilot variables frog_theme = self.params.get_bool("FrogTheme") self.frog_sounds = frog_theme and self.params.get_bool("FrogSounds") + self.reverse_cruise_increase = self.params.get_bool("ReverseCruiseIncrease") # detect sound card presence and ensure successful init sounds_available = HARDWARE.get_sound_card_online() @@ -591,6 +592,11 @@ def state_control(self, CS): CC = car.CarControl.new_message() CC.enabled = self.enabled + # Check the value of "reverse_cruise_increase" just in case the user changed its value mid drive + if long_plan.frogpilotTogglesUpdated: + self.reverse_cruise_increase = self.params.get_bool("ReverseCruiseIncrease") + CC.reverseCruise = self.reverse_cruise_increase + # Check which actuators can be enabled standstill = CS.vEgo <= max(self.CP.minSteerSpeed, MIN_LATERAL_CONTROL_SPEED) or CS.standstill CC.latActive = self.active and not CS.steerFaultTemporary and not CS.steerFaultPermanent and \ diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index e2d9477e8d69f9..166bd26d1ebc3e 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -113,19 +113,30 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) { const int x_offset = scene.mute_dm ? 50 : 250; bool rightHandDM = sm["driverMonitoringState"].getDriverMonitoringState().getIsRHD(); + // Change cruise control increments button + const QRect maxSpeedRect(0, 0, 350, 350); + const bool isMaxSpeedClicked = maxSpeedRect.contains(e->pos()) && isToyotaCar; + // Hide speed button const QRect speedRect(rect().center().x() - 175, 50, 350, 350); const bool isSpeedClicked = speedRect.contains(e->pos()); + // Check if the click was within the max speed area + if (isMaxSpeedClicked) { + const bool currentReverseCruiseIncrease = params.getBool("ReverseCruiseIncrease"); + reverseCruiseIncrease = !currentReverseCruiseIncrease; + params.putBool("ReverseCruiseIncrease", reverseCruiseIncrease); + params_memory.putBool("FrogPilotTogglesUpdated", true); + propagateEvent = false; // Check if the click was within the speed text area - if (isSpeedClicked) { + } else if (isSpeedClicked) { const bool currentVisibility = params.getBool("HideSpeed"); speedHidden = !currentVisibility; params.putBool("HideSpeed", speedHidden); propagateEvent = false; } - const bool clickedOnWidget = isSpeedClicked; + const bool clickedOnWidget = isMaxSpeedClicked || isSpeedClicked; #ifdef ENABLE_MAPS if (map != nullptr) { @@ -333,6 +344,9 @@ AnnotatedCameraWidget::AnnotatedCameraWidget(VisionStreamType type, QWidget* par if (params.getBool("HideSpeed")) { speedHidden = true; } + if (params.getBool("ReverseCruiseIncrease")) { + reverseCruiseIncrease = true; + } // FrogPilot images engage_img = loadPixmap("../assets/img_chffr_wheel.png", {img_size, img_size}); @@ -452,7 +466,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 (reverseCruiseIncrease) { + 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/qt/onroad.h b/selfdrive/ui/qt/onroad.h index 9cd2115791124a..868bd9b822211a 100644 --- a/selfdrive/ui/qt/onroad.h +++ b/selfdrive/ui/qt/onroad.h @@ -14,6 +14,7 @@ const int img_size = (btn_size / 4) * 3; // FrogPilot global variables static bool map_open; +static bool reverseCruiseIncrease; static bool speedHidden;