FrogPilot features - Force device onroad/offroad

This commit is contained in:
FrogAi
2024-07-31 19:39:35 -07:00
parent 7eeabbda3f
commit 1e930ec10b
4 changed files with 36 additions and 1 deletions
+22 -1
View File
@@ -272,7 +272,9 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) {
}
}
for (FrogPilotButtonsControl *btn : findChildren<FrogPilotButtonsControl *>()) {
btn->setEnabled(offroad);
if (btn != forceStartedBtn) {
btn->setEnabled(offroad);
}
}
});
@@ -459,6 +461,25 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) {
});
addItem(toggleBackupBtn);
// Force offroad/onroad
std::vector<QString> forceStartedOptions{tr("OFFROAD"), tr("ONROAD"), tr("OFF")};
forceStartedBtn = new FrogPilotButtonsControl(tr("Force Started State"), tr("Force openpilot either offroad or onroad."), "", forceStartedOptions, true);
connect(forceStartedBtn, &FrogPilotButtonsControl::buttonClicked, [=](int id) {
if (id == 0) {
paramsMemory.putBool("ForceOffroad", true);
paramsMemory.putBool("ForceOnroad", false);
} else if (id == 1) {
paramsMemory.putBool("ForceOffroad", false);
paramsMemory.putBool("ForceOnroad", true);
} else if (id == 2) {
paramsMemory.putBool("ForceOffroad", false);
paramsMemory.putBool("ForceOnroad", false);
}
forceStartedBtn->updateButtonStyles(id);
});
forceStartedBtn->updateButtonStyles(2);
addItem(forceStartedBtn);
// power buttons
QHBoxLayout *power_layout = new QHBoxLayout();
power_layout->setSpacing(30);
+5
View File
@@ -72,6 +72,11 @@ private slots:
private:
Params params;
ButtonControl *pair_device;
// FrogPilot variables
Params paramsMemory{"/dev/shm/params"};
FrogPilotButtonsControl *forceStartedBtn;
};
class TogglesPanel : public ListWidget {
+3
View File
@@ -286,6 +286,9 @@ void UIState::updateStatus() {
}
}
scene.started |= paramsMemory.getBool("ForceOnroad");
scene.started &= !paramsMemory.getBool("ForceOffroad");
// Handle onroad/offroad transition
if (scene.started != started_prev || sm->frame == 1) {
if (scene.started) {
+6
View File
@@ -209,6 +209,8 @@ def hardware_thread(end_event, hw_queue) -> None:
# FrogPilot variables
frogpilot_toggles = FrogPilotVariables.toggles
params_memory = Params("/dev/shm/params")
update_toggles = False
while not end_event.is_set():
@@ -343,6 +345,10 @@ def hardware_thread(end_event, hw_queue) -> None:
if started_ts is None:
should_start = should_start and all(startup_conditions.values())
# Handle force offroad/onroad
should_start |= params_memory.get_bool("ForceOnroad")
should_start &= not params_memory.get_bool("ForceOffroad")
if should_start != should_start_prev or (count == 0):
params.put_bool("IsEngaged", False)
engaged_prev = False