Added toggle for Always On Lateral / No disengage lateral on gas and brake. Lots of credit goes to "pfeiferj"! Couldn't of done it without him! https: //github.com/pfeiferj/openpilot Co-Authored-By: Jacob Pfeifer <jacob@pfeifer.dev>
159 lines
6.9 KiB
C++
159 lines
6.9 KiB
C++
#include "selfdrive/frogpilot/ui/control_settings.h"
|
|
#include "selfdrive/ui/ui.h"
|
|
|
|
FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPilotListWidget(parent) {
|
|
const std::vector<std::tuple<QString, QString, QString, QString>> controlToggles {
|
|
{"AlwaysOnLateral", "Always on Lateral", "Maintain openpilot lateral control when the brake or gas pedals are used.\n\nDeactivation occurs only through the 'Cruise Control' button.", "../frogpilot/assets/toggle_icons/icon_always_on_lateral.png"},
|
|
|
|
{"LateralTune", "Lateral Tuning", "Modify openpilot's steering behavior.", "../frogpilot/assets/toggle_icons/icon_lateral_tune.png"},
|
|
|
|
{"LongitudinalTune", "Longitudinal Tuning", "Modify openpilot's acceleration and braking behavior.", "../frogpilot/assets/toggle_icons/icon_longitudinal_tune.png"},
|
|
{"AccelerationProfile", "Acceleration Profile", "Change the acceleration rate to be either sporty or eco-friendly.", ""},
|
|
{"AggressiveAcceleration", "Aggressive Acceleration With Lead", "Increase acceleration aggressiveness when following a lead vehicle from a stop.", ""},
|
|
};
|
|
|
|
for (const auto &[param, title, desc, icon] : controlToggles) {
|
|
ParamControl *toggle;
|
|
|
|
if (param == "AlwaysOnLateral") {
|
|
std::vector<QString> aolToggles{tr("AlwaysOnLateralMain")};
|
|
std::vector<QString> aolToggleNames{tr("Enable On Cruise Main")};
|
|
toggle = new FrogPilotParamToggleControl(param, title, desc, icon, aolToggles, aolToggleNames);
|
|
|
|
QObject::connect(static_cast<FrogPilotParamToggleControl*>(toggle), &FrogPilotParamToggleControl::buttonClicked, [this](const bool checked) {
|
|
if (checked) {
|
|
FrogPilotConfirmationDialog::toggleAlert("WARNING: This is very experimental and isn't guaranteed to work. If you run into any issues, please report it in the FrogPilot Discord!",
|
|
"I understand the risks.", this);
|
|
}
|
|
if (FrogPilotConfirmationDialog::toggle("Reboot required to take effect.", "Reboot Now", this)) {
|
|
Hardware::reboot();
|
|
}
|
|
});
|
|
|
|
} else if (param == "LateralTune") {
|
|
FrogPilotParamManageControl *lateralTuneToggle = new FrogPilotParamManageControl(param, title, desc, icon, this);
|
|
QObject::connect(lateralTuneToggle, &FrogPilotParamManageControl::manageButtonClicked, this, [this]() {
|
|
parentToggleClicked();
|
|
for (auto &[key, toggle] : toggles) {
|
|
toggle->setVisible(lateralTuneKeys.find(key.c_str()) != lateralTuneKeys.end());
|
|
}
|
|
});
|
|
toggle = lateralTuneToggle;
|
|
|
|
} else if (param == "LongitudinalTune") {
|
|
FrogPilotParamManageControl *longitudinalTuneToggle = new FrogPilotParamManageControl(param, title, desc, icon, this);
|
|
QObject::connect(longitudinalTuneToggle, &FrogPilotParamManageControl::manageButtonClicked, this, [this]() {
|
|
parentToggleClicked();
|
|
for (auto &[key, toggle] : toggles) {
|
|
toggle->setVisible(longitudinalTuneKeys.find(key.c_str()) != longitudinalTuneKeys.end());
|
|
}
|
|
});
|
|
toggle = longitudinalTuneToggle;
|
|
} else if (param == "AccelerationProfile") {
|
|
std::vector<QString> profileOptions{tr("Standard"), tr("Eco"), tr("Sport"), tr("Sport+")};
|
|
FrogPilotButtonParamControl *profileSelection = new FrogPilotButtonParamControl(param, title, desc, icon, profileOptions);
|
|
toggle = profileSelection;
|
|
|
|
QObject::connect(static_cast<FrogPilotButtonParamControl*>(toggle), &FrogPilotButtonParamControl::buttonClicked, [this](int id) {
|
|
if (id == 3) {
|
|
FrogPilotConfirmationDialog::toggleAlert("WARNING: This maxes out openpilot's acceleration from 2.0 m/s to 4.0 m/s and may cause oscillations when accelerating!",
|
|
"I understand the risks.", this);
|
|
}
|
|
});
|
|
|
|
} else {
|
|
toggle = new ParamControl(param, title, desc, icon, this);
|
|
}
|
|
|
|
addItem(toggle);
|
|
toggles[param.toStdString()] = toggle;
|
|
|
|
QObject::connect(toggle, &ToggleControl::toggleFlipped, [this]() {
|
|
updateToggles();
|
|
});
|
|
|
|
QObject::connect(static_cast<FrogPilotParamValueControl*>(toggle), &FrogPilotParamValueControl::buttonPressed, [this]() {
|
|
updateToggles();
|
|
});
|
|
|
|
QObject::connect(toggle, &AbstractControl::showDescriptionEvent, [this]() {
|
|
update();
|
|
});
|
|
|
|
QObject::connect(static_cast<FrogPilotParamManageControl*>(toggle), &FrogPilotParamManageControl::manageButtonClicked, this, [this]() {
|
|
update();
|
|
});
|
|
}
|
|
|
|
std::set<std::string> rebootKeys = {"AlwaysOnLateral"};
|
|
for (const std::string &key : rebootKeys) {
|
|
QObject::connect(toggles[key], &ToggleControl::toggleFlipped, [this]() {
|
|
if (FrogPilotConfirmationDialog::toggle("Reboot required to take effect.", "Reboot Now", this)) {
|
|
Hardware::reboot();
|
|
}
|
|
});
|
|
}
|
|
|
|
conditionalExperimentalKeys = {};
|
|
fireTheBabysitterKeys = {};
|
|
laneChangeKeys = {};
|
|
lateralTuneKeys = {};
|
|
longitudinalTuneKeys = {"AccelerationProfile", "AggressiveAcceleration"};
|
|
speedLimitControllerKeys = {};
|
|
visionTurnControlKeys = {};
|
|
|
|
QObject::connect(device(), &Device::interactiveTimeout, this, &FrogPilotControlsPanel::hideSubToggles);
|
|
QObject::connect(parent, &SettingsWindow::closeParentToggle, this, &FrogPilotControlsPanel::hideSubToggles);
|
|
QObject::connect(parent, &SettingsWindow::updateMetric, this, &FrogPilotControlsPanel::updateMetric);
|
|
|
|
hideSubToggles();
|
|
updateMetric();
|
|
}
|
|
|
|
void FrogPilotControlsPanel::updateToggles() {
|
|
std::thread([this]() {
|
|
paramsMemory.putBool("FrogPilotTogglesUpdated", true);
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
paramsMemory.putBool("FrogPilotTogglesUpdated", false);
|
|
}).detach();
|
|
}
|
|
|
|
void FrogPilotControlsPanel::updateMetric() {
|
|
bool previousIsMetric = isMetric;
|
|
isMetric = params.getBool("IsMetric");
|
|
|
|
if (isMetric != previousIsMetric) {
|
|
double distanceConversion = isMetric ? FOOT_TO_METER : METER_TO_FOOT;
|
|
double speedConversion = isMetric ? MILE_TO_KM : KM_TO_MILE;
|
|
}
|
|
|
|
if (isMetric) {
|
|
} else {
|
|
}
|
|
|
|
previousIsMetric = isMetric;
|
|
}
|
|
|
|
void FrogPilotControlsPanel::parentToggleClicked() {
|
|
this->openParentToggle();
|
|
}
|
|
|
|
void FrogPilotControlsPanel::hideSubToggles() {
|
|
for (auto &[key, toggle] : toggles) {
|
|
const bool subToggles = conditionalExperimentalKeys.find(key.c_str()) != conditionalExperimentalKeys.end() ||
|
|
fireTheBabysitterKeys.find(key.c_str()) != fireTheBabysitterKeys.end() ||
|
|
laneChangeKeys.find(key.c_str()) != laneChangeKeys.end() ||
|
|
lateralTuneKeys.find(key.c_str()) != lateralTuneKeys.end() ||
|
|
longitudinalTuneKeys.find(key.c_str()) != longitudinalTuneKeys.end() ||
|
|
speedLimitControllerKeys.find(key.c_str()) != speedLimitControllerKeys.end() ||
|
|
visionTurnControlKeys.find(key.c_str()) != visionTurnControlKeys.end();
|
|
toggle->setVisible(!subToggles);
|
|
}
|
|
|
|
this->closeParentToggle();
|
|
}
|
|
|
|
void FrogPilotControlsPanel::hideEvent(QHideEvent *event) {
|
|
hideSubToggles();
|
|
}
|