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.
This commit is contained in:
FrogAi
2024-04-27 12:13:55 -07:00
parent 80b2dc8632
commit 38d8d6f650
10 changed files with 77 additions and 13 deletions
+4
View File
@@ -245,6 +245,8 @@ std::unordered_map<std::string, uint32_t> keys = {
{"CurrentHolidayTheme", PERSISTENT},
{"CustomAlerts", PERSISTENT},
{"CustomColors", PERSISTENT},
{"CustomCruise", PERSISTENT},
{"CustomCruiseLong", PERSISTENT},
{"CustomIcons", PERSISTENT},
{"CustomPaths", PERSISTENT},
{"CustomPersonalities", PERSISTENT},
@@ -309,6 +311,8 @@ std::unordered_map<std::string, uint32_t> keys = {
{"RefuseVolume", PERSISTENT},
{"RelaxedFollow", PERSISTENT},
{"RelaxedJerk", PERSISTENT},
{"ReverseCruise", PERSISTENT},
{"ReverseCruiseUI", PERSISTENT},
{"RoadEdgesWidth", PERSISTENT},
{"ShowCPU", PERSISTENT},
{"ShowGPU", PERSISTENT},
+1 -1
View File
@@ -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
}
+4 -1
View File
@@ -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)
+6 -5
View File
@@ -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]
@@ -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<QString> 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<int, QString>(), this, false, tr(" mph"));
} else if (param == "CustomCruiseLong") {
toggle = new FrogPilotParamValueControl(param, title, desc, icon, 1, 99, std::map<int, QString>(), this, false, tr(" mph"));
} else if (param == "ReverseCruise") {
std::vector<QString> reverseCruiseToggles{"ReverseCruiseUI"};
std::vector<QString> 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<FrogPilotParamValueControl*>(toggles["CustomCruise"]);
FrogPilotParamValueControl *customCruiseLongToggle = static_cast<FrogPilotParamValueControl*>(toggles["CustomCruiseLong"]);
FrogPilotParamValueControl *pauseAOLOnBrakeToggle = static_cast<FrogPilotParamValueControl*>(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();
}
@@ -39,7 +39,7 @@ private:
std::set<QString> lateralTuneKeys = {"ForceAutoTune"};
std::set<QString> longitudinalTuneKeys = {"AccelerationProfile", "AggressiveAcceleration", "DecelerationProfile"};
std::set<QString> mtscKeys = {};
std::set<QString> qolKeys = {"DisableOnroadUploads"};
std::set<QString> qolKeys = {"CustomCruise", "CustomCruiseLong", "DisableOnroadUploads", "ReverseCruise"};
std::set<QString> speedLimitControllerKeys = {};
std::set<QString> speedLimitControllerControlsKeys = {};
std::set<QString> speedLimitControllerQOLKeys = {};
+27 -5
View File
@@ -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);
+2
View File
@@ -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;
+2
View File
@@ -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");
+2
View File
@@ -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;