mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-14 19:44:05 +08:00
Controls - Always On Lateral
Maintain openpilot lateral control when the brake or gas pedals are used. Deactivation occurs only through the 'Cruise Control' button. 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>
This commit is contained in:
@@ -165,7 +165,7 @@ void MapWindow::updateState(const UIState &s) {
|
||||
if (sm.updated("modelV2")) {
|
||||
// set path color on change, and show map on rising edge of navigate on openpilot
|
||||
bool nav_enabled = sm["modelV2"].getModelV2().getNavEnabled() &&
|
||||
sm["controlsState"].getControlsState().getEnabled();
|
||||
(sm["controlsState"].getControlsState().getEnabled() || sm["frogpilotCarControl"].getFrogpilotCarControl().getAlwaysOnLateral());
|
||||
if (nav_enabled != uiState()->scene.navigate_on_openpilot) {
|
||||
if (loaded_once) {
|
||||
m_map->setPaintProperty("navLayer", "line-color", getNavPathColor(nav_enabled));
|
||||
|
||||
@@ -157,6 +157,9 @@ void TogglesPanel::showEvent(QShowEvent *event) {
|
||||
}
|
||||
|
||||
void TogglesPanel::updateToggles() {
|
||||
auto disengage_on_accelerator_toggle = toggles["DisengageOnAccelerator"];
|
||||
disengage_on_accelerator_toggle->setVisible(!params.getBool("AlwaysOnLateral"));
|
||||
|
||||
auto experimental_mode_toggle = toggles["ExperimentalMode"];
|
||||
auto op_long_toggle = toggles["ExperimentalLongitudinalEnabled"];
|
||||
const QString e2e_description = QString("%1<br>"
|
||||
|
||||
@@ -171,7 +171,7 @@ void OnroadAlerts::paintEvent(QPaintEvent *event) {
|
||||
|
||||
int margin = 40;
|
||||
int radius = 30;
|
||||
int offset = true ? 25 : 0;
|
||||
int offset = scene.show_aol_status_bar ? 25 : 0;
|
||||
if (alert.size == cereal::ControlsState::AlertSize::FULL) {
|
||||
margin = 0;
|
||||
radius = 0;
|
||||
@@ -236,7 +236,7 @@ void ExperimentalButton::changeMode() {
|
||||
|
||||
void ExperimentalButton::updateState(const UIState &s) {
|
||||
const auto cs = (*s.sm)["controlsState"].getControlsState();
|
||||
bool eng = cs.getEngageable() || cs.getEnabled();
|
||||
bool eng = cs.getEngageable() || cs.getEnabled() || scene.always_on_lateral_active;
|
||||
if ((cs.getExperimentalMode() != experimental_mode) || (eng != engageable)) {
|
||||
engageable = eng;
|
||||
experimental_mode = cs.getExperimentalMode();
|
||||
@@ -544,7 +544,7 @@ void AnnotatedCameraWidget::drawDriverState(QPainter &painter, const UIState *s)
|
||||
// base icon
|
||||
int offset = UI_BORDER_SIZE + btn_size / 2;
|
||||
int x = rightHandDM ? width() - offset : offset;
|
||||
offset += true ? 25 : 0;
|
||||
offset += showAlwaysOnLateralStatusBar ? 25 : 0;
|
||||
int y = height() - offset;
|
||||
float opacity = dmActive ? 0.65 : 0.2;
|
||||
drawIcon(painter, QPoint(x, y), dm_img, blackColor(70), opacity);
|
||||
@@ -749,13 +749,16 @@ void AnnotatedCameraWidget::updateFrogPilotWidgets() {
|
||||
|
||||
alertSize = scene.alert_size;
|
||||
|
||||
alwaysOnLateralActive = scene.always_on_lateral_active;
|
||||
showAlwaysOnLateralStatusBar = scene.show_aol_status_bar;
|
||||
|
||||
experimentalMode = scene.experimental_mode;
|
||||
|
||||
mapOpen = scene.map_open;
|
||||
}
|
||||
|
||||
void AnnotatedCameraWidget::paintFrogPilotWidgets(QPainter &p) {
|
||||
if (true) {
|
||||
if (showAlwaysOnLateralStatusBar) {
|
||||
drawStatusBar(p);
|
||||
}
|
||||
|
||||
@@ -786,6 +789,10 @@ void AnnotatedCameraWidget::drawStatusBar(QPainter &p) {
|
||||
p.setOpacity(1.0);
|
||||
p.drawRoundedRect(statusBarRect, 30, 30);
|
||||
|
||||
if (alwaysOnLateralActive && showAlwaysOnLateralStatusBar) {
|
||||
newStatus = tr("Always On Lateral active") + (mapOpen ? "" : tr(". Press the \"Cruise Control\" button to disable"));
|
||||
}
|
||||
|
||||
if (newStatus != lastShownStatus) {
|
||||
displayStatusText = true;
|
||||
lastShownStatus = newStatus;
|
||||
|
||||
@@ -118,8 +118,10 @@ private:
|
||||
|
||||
QHBoxLayout *bottom_layout;
|
||||
|
||||
bool alwaysOnLateralActive;
|
||||
bool experimentalMode;
|
||||
bool mapOpen;
|
||||
bool showAlwaysOnLateralStatusBar;
|
||||
|
||||
float accelerationConversion;
|
||||
float distanceConversion;
|
||||
|
||||
@@ -223,6 +223,7 @@ static void update_state(UIState *s) {
|
||||
}
|
||||
if (sm.updated("frogpilotCarControl")) {
|
||||
auto frogpilotCarControl = sm["frogpilotCarControl"].getFrogpilotCarControl();
|
||||
scene.always_on_lateral_active = !scene.enabled && frogpilotCarControl.getAlwaysOnLateral();
|
||||
}
|
||||
if (sm.updated("frogpilotCarState")) {
|
||||
auto frogpilotCarState = sm["frogpilotCarState"].getFrogpilotCarState();
|
||||
@@ -259,6 +260,9 @@ void ui_update_params(UIState *s) {
|
||||
void ui_update_frogpilot_params(UIState *s) {
|
||||
Params params = Params();
|
||||
UIScene &scene = s->scene;
|
||||
|
||||
bool always_on_lateral = params.getBool("AlwaysOnLateral");
|
||||
scene.show_aol_status_bar = always_on_lateral && !params.getBool("HideAOLStatusBar");
|
||||
}
|
||||
|
||||
void UIState::updateStatus() {
|
||||
@@ -267,6 +271,8 @@ void UIState::updateStatus() {
|
||||
auto state = controls_state.getState();
|
||||
if (state == cereal::ControlsState::OpenpilotState::PRE_ENABLED || state == cereal::ControlsState::OpenpilotState::OVERRIDING) {
|
||||
status = STATUS_OVERRIDE;
|
||||
} else if (scene.always_on_lateral_active) {
|
||||
status = STATUS_ALWAYS_ON_LATERAL_ACTIVE;
|
||||
} else {
|
||||
status = controls_state.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED;
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@ typedef enum UIStatus {
|
||||
STATUS_ENGAGED,
|
||||
|
||||
// FrogPilot statuses
|
||||
STATUS_ALWAYS_ON_LATERAL_ACTIVE,
|
||||
STATUS_EXPERIMENTAL_MODE_ACTIVE,
|
||||
STATUS_NAVIGATION_ACTIVE,
|
||||
} UIStatus;
|
||||
@@ -135,6 +136,7 @@ const QColor bg_colors [] = {
|
||||
[STATUS_ENGAGED] = QColor(0x17, 0x86, 0x44, 0xf1),
|
||||
|
||||
// FrogPilot colors
|
||||
[STATUS_ALWAYS_ON_LATERAL_ACTIVE] = QColor(0x0a, 0xba, 0xb5, 0xf1),
|
||||
[STATUS_EXPERIMENTAL_MODE_ACTIVE] = QColor(0xda, 0x6f, 0x25, 0xf1),
|
||||
[STATUS_NAVIGATION_ACTIVE] = QColor(0x31, 0xa1, 0xee, 0xf1),
|
||||
};
|
||||
@@ -180,12 +182,14 @@ typedef struct UIScene {
|
||||
uint64_t started_frame;
|
||||
|
||||
// FrogPilot variables
|
||||
bool always_on_lateral_active;
|
||||
bool enabled;
|
||||
bool experimental_mode;
|
||||
bool map_open;
|
||||
bool online;
|
||||
bool parked;
|
||||
bool right_hand_drive;
|
||||
bool show_aol_status_bar;
|
||||
bool tethering_enabled;
|
||||
|
||||
int alert_size;
|
||||
|
||||
Reference in New Issue
Block a user