User Set Steer Ratio

This commit is contained in:
FrogAi
2024-01-12 22:39:30 -07:00
parent 5e77c2dea0
commit 0e6884df41
6 changed files with 37 additions and 6 deletions

View File

@@ -340,6 +340,8 @@ std::unordered_map<std::string, uint32_t> keys = {
{"SpeedLimitController", PERSISTENT}, {"SpeedLimitController", PERSISTENT},
{"StandardFollow", PERSISTENT}, {"StandardFollow", PERSISTENT},
{"StandardJerk", PERSISTENT}, {"StandardJerk", PERSISTENT},
{"SteerRatio", PERSISTENT},
{"SteerRatioStock", PERSISTENT},
{"StoppingDistance", PERSISTENT}, {"StoppingDistance", PERSISTENT},
{"TetheringEnabled", PERSISTENT}, {"TetheringEnabled", PERSISTENT},
{"TSS2Tune", PERSISTENT}, {"TSS2Tune", PERSISTENT},

View File

@@ -616,7 +616,7 @@ class Controls:
# Update VehicleModel # Update VehicleModel
lp = self.sm['liveParameters'] lp = self.sm['liveParameters']
x = max(lp.stiffnessFactor, 0.1) x = max(lp.stiffnessFactor, 0.1)
sr = max(lp.steerRatio, 0.1) sr = max(self.steer_ratio, 0.1)
self.VM.update_params(x, sr) self.VM.update_params(x, sr)
# Update Torque Params # Update Torque Params
@@ -994,6 +994,9 @@ class Controls:
self.green_light_alert = self.params.get_bool("GreenLightAlert") self.green_light_alert = self.params.get_bool("GreenLightAlert")
lateral_tune = self.params.get_bool("LateralTune")
self.steer_ratio = self.params.get_int("SteerRatio") / 100 if lateral_tune else self.params.get_int("SteerRatioStock") / 100
longitudinal_tune = self.params.get_bool("LongitudinalTune") longitudinal_tune = self.params.get_bool("LongitudinalTune")
self.sport_plus = self.params.get_int("AccelerationProfile") == 3 and longitudinal_tune self.sport_plus = self.params.get_int("AccelerationProfile") == 3 and longitudinal_tune

View File

@@ -27,6 +27,7 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil
{"LateralTune", "Lateral Tuning", "Modify openpilot's steering behavior.", "../frogpilot/assets/toggle_icons/icon_lateral_tune.png"}, {"LateralTune", "Lateral Tuning", "Modify openpilot's steering behavior.", "../frogpilot/assets/toggle_icons/icon_lateral_tune.png"},
{"AverageCurvature", "Average Desired Curvature", "Use Pfeiferj's distance-based curvature adjustment for improved curve handling.", ""}, {"AverageCurvature", "Average Desired Curvature", "Use Pfeiferj's distance-based curvature adjustment for improved curve handling.", ""},
{"NNFF", "NNFF - Neural Network Feedforward", "Use Twilsonco's Neural Network Feedforward for enhanced precision in lateral control.", ""}, {"NNFF", "NNFF - Neural Network Feedforward", "Use Twilsonco's Neural Network Feedforward for enhanced precision in lateral control.", ""},
{"SteerRatio", steerRatioStock != 0 ? QString("Steer Ratio (Default: " + QString::number(steerRatioStock / 100.0) + ")") : "Steer Ratio", "Set a custom steer ratio for your vehicle controls.", ""},
{"LongitudinalTune", "Longitudinal Tuning", "Modify openpilot's acceleration and braking behavior.", "../frogpilot/assets/toggle_icons/icon_longitudinal_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.", ""}, {"AccelerationProfile", "Acceleration Profile", "Change the acceleration rate to be either sporty or eco-friendly.", ""},
@@ -176,6 +177,8 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil
} }
}); });
toggle = lateralTuneToggle; toggle = lateralTuneToggle;
} else if (param == "SteerRatio") {
toggle = new FrogPilotParamValueControl(param, title, desc, icon, steerRatioStock * 0.75, steerRatioStock * 1.25, std::map<int, QString>(), this, false, "", 100);
} else if (param == "LongitudinalTune") { } else if (param == "LongitudinalTune") {
FrogPilotParamManageControl *longitudinalTuneToggle = new FrogPilotParamManageControl(param, title, desc, icon, this); FrogPilotParamManageControl *longitudinalTuneToggle = new FrogPilotParamManageControl(param, title, desc, icon, this);
@@ -359,11 +362,17 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil
conditionalExperimentalKeys = {"CECurves", "CECurvesLead", "CESlowerLead", "CENavigation", "CEStopLights", "CESignal"}; conditionalExperimentalKeys = {"CECurves", "CECurvesLead", "CESlowerLead", "CENavigation", "CEStopLights", "CESignal"};
fireTheBabysitterKeys = {"NoLogging", "MuteDM", "MuteDoor", "MuteOverheated", "MuteSeatbelt"}; fireTheBabysitterKeys = {"NoLogging", "MuteDM", "MuteDoor", "MuteOverheated", "MuteSeatbelt"};
laneChangeKeys = {"LaneChangeTime", "LaneDetection", "OneLaneChange", "PauseLateralOnSignal"}; laneChangeKeys = {"LaneChangeTime", "LaneDetection", "OneLaneChange", "PauseLateralOnSignal"};
lateralTuneKeys = {"AverageCurvature", "NNFF"}; lateralTuneKeys = {"AverageCurvature", "NNFF", "SteerRatio"};
longitudinalTuneKeys = {"AccelerationProfile", "AggressiveAcceleration", "SmoothBraking", "StoppingDistance"}; longitudinalTuneKeys = {"AccelerationProfile", "AggressiveAcceleration", "SmoothBraking", "StoppingDistance"};
speedLimitControllerKeys = {"Offset1", "Offset2", "Offset3", "Offset4", "SLCFallback", "SLCOverride", "SLCPriority"}; speedLimitControllerKeys = {"Offset1", "Offset2", "Offset3", "Offset4", "SLCFallback", "SLCOverride", "SLCPriority"};
visionTurnControlKeys = {}; visionTurnControlKeys = {};
QObject::connect(uiState(), &UIState::offroadTransition, this, [this](bool offroad) {
if (!offroad) {
updateCarToggles();
}
});
QObject::connect(device(), &Device::interactiveTimeout, this, &FrogPilotControlsPanel::hideSubToggles); QObject::connect(device(), &Device::interactiveTimeout, this, &FrogPilotControlsPanel::hideSubToggles);
QObject::connect(parent, &SettingsWindow::closeParentToggle, this, &FrogPilotControlsPanel::hideSubToggles); QObject::connect(parent, &SettingsWindow::closeParentToggle, this, &FrogPilotControlsPanel::hideSubToggles);
QObject::connect(parent, &SettingsWindow::updateMetric, this, &FrogPilotControlsPanel::updateMetric); QObject::connect(parent, &SettingsWindow::updateMetric, this, &FrogPilotControlsPanel::updateMetric);
@@ -372,6 +381,14 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil
updateMetric(); updateMetric();
} }
void FrogPilotControlsPanel::updateCarToggles() {
FrogPilotParamValueControl *steerRatioToggle = static_cast<FrogPilotParamValueControl*>(toggles["SteerRatio"]);
steerRatioStock = params.getInt("SteerRatioStock");
steerRatioToggle->setTitle(steerRatioStock != 0 ? QString("Steer Ratio (Default: " + QString::number(steerRatioStock / 100.0) + ")") : QString("Steer Ratio"));
steerRatioToggle->updateControl(steerRatioStock * 0.75, steerRatioStock * 1.25, "", 100);
steerRatioToggle->refresh();
}
void FrogPilotControlsPanel::updateToggles() { void FrogPilotControlsPanel::updateToggles() {
std::thread([this]() { std::thread([this]() {
paramsMemory.putBool("FrogPilotTogglesUpdated", true); paramsMemory.putBool("FrogPilotTogglesUpdated", true);

View File

@@ -19,6 +19,7 @@ private:
void hideEvent(QHideEvent *event); void hideEvent(QHideEvent *event);
void hideSubToggles(); void hideSubToggles();
void parentToggleClicked(); void parentToggleClicked();
void updateCarToggles();
void updateMetric(); void updateMetric();
void updateToggles(); void updateToggles();
@@ -46,4 +47,5 @@ private:
Params paramsMemory{"/dev/shm/params"}; Params paramsMemory{"/dev/shm/params"};
bool isMetric = params.getBool("IsMetric"); bool isMetric = params.getBool("IsMetric");
int steerRatioStock = params.getInt("SteerRatioStock");
}; };

View File

@@ -179,8 +179,8 @@ class FrogPilotParamToggleControl : public ParamControl {
Q_OBJECT Q_OBJECT
public: public:
FrogPilotParamToggleControl(const QString &param, const QString &title, const QString &desc, FrogPilotParamToggleControl(const QString &param, const QString &title, const QString &desc,
const QString &icon, const std::vector<QString> &button_params, const QString &icon, const std::vector<QString> &button_params,
const std::vector<QString> &button_texts, QWidget *parent = nullptr, const std::vector<QString> &button_texts, QWidget *parent = nullptr,
const int minimum_button_width = 225) const int minimum_button_width = 225)
: ParamControl(param, title, desc, icon, parent) { : ParamControl(param, title, desc, icon, parent) {
@@ -313,10 +313,11 @@ public:
valueLabel->setStyleSheet("QLabel { color: #E0E879; }"); valueLabel->setStyleSheet("QLabel { color: #E0E879; }");
} }
void updateControl(int newMinValue, int newMaxValue, const QString &newLabel) { void updateControl(int newMinValue, int newMaxValue, const QString &newLabel, int newDivision = 1) {
minValue = newMinValue; minValue = newMinValue;
maxValue = newMaxValue; maxValue = newMaxValue;
labelText = newLabel; labelText = newLabel;
division = newDivision;
} }
void showEvent(QShowEvent *event) override { void showEvent(QShowEvent *event) override {
@@ -492,10 +493,11 @@ public:
valueLabel->setStyleSheet("QLabel { color: #E0E879; }"); valueLabel->setStyleSheet("QLabel { color: #E0E879; }");
} }
void updateControl(int newMinValue, int newMaxValue, const QString &newLabel) { void updateControl(int newMinValue, int newMaxValue, const QString &newLabel, int newDivision) {
minValue = newMinValue; minValue = newMinValue;
maxValue = newMaxValue; maxValue = newMaxValue;
labelText = newLabel; labelText = newLabel;
division = newDivision;
} }
void showEvent(QShowEvent *event) override { void showEvent(QShowEvent *event) override {

View File

@@ -134,6 +134,11 @@ def main():
CP = msg CP = msg
cloudlog.info("paramsd got CarParams") cloudlog.info("paramsd got CarParams")
steer_ratio_stock = params_reader.get_int("SteerRatioStock")
if steer_ratio_stock != CP.steerRatio * 100:
params_reader.put_int("SteerRatio", CP.steerRatio * 100)
params_reader.put_int("SteerRatioStock", CP.steerRatio * 100)
min_sr, max_sr = 0.5 * CP.steerRatio, 2.0 * CP.steerRatio min_sr, max_sr = 0.5 * CP.steerRatio, 2.0 * CP.steerRatio
params = params_reader.get("LiveParameters") params = params_reader.get("LiveParameters")