Controls - Driving Personalities - Onroad Distance Button
Simulate a distance button via the onroad UI to control personalities, 'Experimental Mode', and 'Traffic Mode'.
This commit is contained in:
parent
386f32ef6e
commit
1266b2282a
@ -71,6 +71,7 @@ class Controls:
|
|||||||
self.frogpilot_toggles = FrogPilotVariables.toggles
|
self.frogpilot_toggles = FrogPilotVariables.toggles
|
||||||
|
|
||||||
self.drive_added = False
|
self.drive_added = False
|
||||||
|
self.onroad_distance_pressed = False
|
||||||
self.openpilot_crashed_triggered = False
|
self.openpilot_crashed_triggered = False
|
||||||
|
|
||||||
self.display_timer = 0
|
self.display_timer = 0
|
||||||
@ -681,12 +682,13 @@ class Controls:
|
|||||||
|
|
||||||
# decrement personality on distance button press
|
# decrement personality on distance button press
|
||||||
if self.CP.openpilotLongitudinalControl:
|
if self.CP.openpilotLongitudinalControl:
|
||||||
if any(not be.pressed and be.type == ButtonType.gapAdjustCruise for be in CS.buttonEvents):
|
if any(not be.pressed and be.type == ButtonType.gapAdjustCruise for be in CS.buttonEvents) or self.onroad_distance_pressed:
|
||||||
menu_open = self.display_timer > 0 or self.CP.carName != "gm" or not self.sm['frogpilotCarState'].hasCamera
|
menu_open = self.display_timer > 0 or self.CP.carName != "gm" or not self.sm['frogpilotCarState'].hasCamera
|
||||||
if menu_open:
|
if not self.params_memory.get_bool("OnroadDistanceButtonPressed") and menu_open:
|
||||||
self.personality = (self.personality - 1) % 3
|
self.personality = (self.personality - 1) % 3
|
||||||
self.params.put_nonblocking('LongitudinalPersonality', str(self.personality))
|
self.params.put_nonblocking('LongitudinalPersonality', str(self.personality))
|
||||||
self.display_timer = 350
|
self.display_timer = 350
|
||||||
|
self.onroad_distance_pressed = self.params_memory.get_bool("OnroadDistanceButtonPressed")
|
||||||
|
|
||||||
self.display_timer -= 1
|
self.display_timer -= 1
|
||||||
|
|
||||||
|
BIN
selfdrive/frogpilot/assets/other_images/aggressive.png
Normal file
BIN
selfdrive/frogpilot/assets/other_images/aggressive.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 62 KiB |
BIN
selfdrive/frogpilot/assets/other_images/aggressive_kaofui.png
Normal file
BIN
selfdrive/frogpilot/assets/other_images/aggressive_kaofui.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.5 KiB |
BIN
selfdrive/frogpilot/assets/other_images/relaxed.png
Normal file
BIN
selfdrive/frogpilot/assets/other_images/relaxed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 81 KiB |
BIN
selfdrive/frogpilot/assets/other_images/relaxed_kaofui.png
Normal file
BIN
selfdrive/frogpilot/assets/other_images/relaxed_kaofui.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
selfdrive/frogpilot/assets/other_images/standard.png
Normal file
BIN
selfdrive/frogpilot/assets/other_images/standard.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 73 KiB |
BIN
selfdrive/frogpilot/assets/other_images/standard_kaofui.png
Normal file
BIN
selfdrive/frogpilot/assets/other_images/standard_kaofui.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
@ -544,6 +544,7 @@ void AnnotatedCameraWidget::drawDriverState(QPainter &painter, const UIState *s)
|
|||||||
// base icon
|
// base icon
|
||||||
int offset = UI_BORDER_SIZE + btn_size / 2;
|
int offset = UI_BORDER_SIZE + btn_size / 2;
|
||||||
int x = rightHandDM ? width() - offset : offset;
|
int x = rightHandDM ? width() - offset : offset;
|
||||||
|
x += onroadDistanceButton ? 250 : 0;
|
||||||
offset += showAlwaysOnLateralStatusBar || showConditionalExperimentalStatusBar ? 25 : 0;
|
offset += showAlwaysOnLateralStatusBar || showConditionalExperimentalStatusBar ? 25 : 0;
|
||||||
int y = height() - offset;
|
int y = height() - offset;
|
||||||
float opacity = dmActive ? 0.65 : 0.2;
|
float opacity = dmActive ? 0.65 : 0.2;
|
||||||
@ -719,6 +720,9 @@ void AnnotatedCameraWidget::showEvent(QShowEvent *event) {
|
|||||||
void AnnotatedCameraWidget::initializeFrogPilotWidgets() {
|
void AnnotatedCameraWidget::initializeFrogPilotWidgets() {
|
||||||
bottom_layout = new QHBoxLayout();
|
bottom_layout = new QHBoxLayout();
|
||||||
|
|
||||||
|
distance_btn = new DistanceButton(this);
|
||||||
|
bottom_layout->addWidget(distance_btn);
|
||||||
|
|
||||||
QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||||
bottom_layout->addItem(spacer);
|
bottom_layout->addItem(spacer);
|
||||||
|
|
||||||
@ -758,6 +762,8 @@ void AnnotatedCameraWidget::updateFrogPilotWidgets() {
|
|||||||
experimentalMode = scene.experimental_mode;
|
experimentalMode = scene.experimental_mode;
|
||||||
|
|
||||||
mapOpen = scene.map_open;
|
mapOpen = scene.map_open;
|
||||||
|
|
||||||
|
onroadDistanceButton = scene.onroad_distance_button;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnnotatedCameraWidget::paintFrogPilotWidgets(QPainter &p) {
|
void AnnotatedCameraWidget::paintFrogPilotWidgets(QPainter &p) {
|
||||||
@ -765,6 +771,13 @@ void AnnotatedCameraWidget::paintFrogPilotWidgets(QPainter &p) {
|
|||||||
drawStatusBar(p);
|
drawStatusBar(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool enableDistanceButton = onroadDistanceButton && !hideBottomIcons;
|
||||||
|
distance_btn->setVisible(enableDistanceButton);
|
||||||
|
if (enableDistanceButton) {
|
||||||
|
distance_btn->updateState();
|
||||||
|
bottom_layout->setAlignment(distance_btn, (rightHandDM ? Qt::AlignRight : Qt::AlignLeft));
|
||||||
|
}
|
||||||
|
|
||||||
map_settings_btn_bottom->setEnabled(map_settings_btn->isEnabled());
|
map_settings_btn_bottom->setEnabled(map_settings_btn->isEnabled());
|
||||||
if (map_settings_btn_bottom->isEnabled()) {
|
if (map_settings_btn_bottom->isEnabled()) {
|
||||||
map_settings_btn_bottom->setVisible(!hideBottomIcons);
|
map_settings_btn_bottom->setVisible(!hideBottomIcons);
|
||||||
@ -772,6 +785,76 @@ void AnnotatedCameraWidget::paintFrogPilotWidgets(QPainter &p) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DistanceButton::DistanceButton(QWidget *parent) : QPushButton(parent), scene(uiState()->scene) {
|
||||||
|
setFixedSize(btn_size * 1.5, btn_size * 1.5);
|
||||||
|
|
||||||
|
profile_data = {
|
||||||
|
{QPixmap("../frogpilot/assets/other_images/traffic.png"), "Traffic"},
|
||||||
|
{QPixmap("../frogpilot/assets/other_images/aggressive.png"), "Aggressive"},
|
||||||
|
{QPixmap("../frogpilot/assets/other_images/standard.png"), "Standard"},
|
||||||
|
{QPixmap("../frogpilot/assets/other_images/relaxed.png"), "Relaxed"}
|
||||||
|
};
|
||||||
|
|
||||||
|
profile_data_kaofui = {
|
||||||
|
{QPixmap("../frogpilot/assets/other_images/traffic_kaofui.png"), "Traffic"},
|
||||||
|
{QPixmap("../frogpilot/assets/other_images/aggressive_kaofui.png"), "Aggressive"},
|
||||||
|
{QPixmap("../frogpilot/assets/other_images/standard_kaofui.png"), "Standard"},
|
||||||
|
{QPixmap("../frogpilot/assets/other_images/relaxed_kaofui.png"), "Relaxed"}
|
||||||
|
};
|
||||||
|
|
||||||
|
transitionTimer.start();
|
||||||
|
|
||||||
|
connect(this, &QPushButton::pressed, this, &DistanceButton::buttonPressed);
|
||||||
|
connect(this, &QPushButton::released, this, &DistanceButton::buttonReleased);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DistanceButton::buttonPressed() {
|
||||||
|
paramsMemory.putBool("OnroadDistanceButtonPressed", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DistanceButton::buttonReleased() {
|
||||||
|
paramsMemory.putBool("OnroadDistanceButtonPressed", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DistanceButton::updateState() {
|
||||||
|
bool stateChanged = (trafficModeActive != scene.traffic_mode_active) ||
|
||||||
|
(personality != static_cast<int>(scene.personality) && !trafficModeActive);
|
||||||
|
|
||||||
|
if (stateChanged) {
|
||||||
|
transitionTimer.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
personality = static_cast<int>(scene.personality);
|
||||||
|
trafficModeActive = scene.traffic_mode_active;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DistanceButton::paintEvent(QPaintEvent *event) {
|
||||||
|
QPainter p(this);
|
||||||
|
p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
|
||||||
|
|
||||||
|
constexpr qreal fadeDuration = 1000.0;
|
||||||
|
constexpr qreal textDuration = 3000.0;
|
||||||
|
int elapsed = transitionTimer.elapsed();
|
||||||
|
|
||||||
|
qreal textOpacity = qBound(0.0, 1.0 - ((elapsed - textDuration) / fadeDuration), 1.0);
|
||||||
|
qreal imageOpacity = qBound(0.0, (elapsed - textDuration) / fadeDuration, 1.0);
|
||||||
|
|
||||||
|
int profile = trafficModeActive ? 0 : personality + 1;
|
||||||
|
auto &[profileImage, profileText] = scene.use_kaofui_icons ? profile_data_kaofui[profile] : profile_data[profile];
|
||||||
|
|
||||||
|
if (textOpacity > 0.0) {
|
||||||
|
p.setOpacity(textOpacity);
|
||||||
|
p.setFont(InterFont(40, QFont::Bold));
|
||||||
|
p.setPen(Qt::white);
|
||||||
|
QRect textRect(-25, 0, width(), height() + 95);
|
||||||
|
p.drawText(textRect, Qt::AlignCenter, profileText);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imageOpacity > 0.0) {
|
||||||
|
drawIcon(p, QPoint((btn_size / 2) * 1.25, btn_size / 2 + 95), profileImage, Qt::transparent, imageOpacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AnnotatedCameraWidget::drawStatusBar(QPainter &p) {
|
void AnnotatedCameraWidget::drawStatusBar(QPainter &p) {
|
||||||
p.save();
|
p.save();
|
||||||
|
|
||||||
|
@ -34,6 +34,32 @@ private:
|
|||||||
UIScene &scene;
|
UIScene &scene;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DistanceButton : public QPushButton {
|
||||||
|
public:
|
||||||
|
explicit DistanceButton(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
void buttonPressed();
|
||||||
|
void buttonReleased();
|
||||||
|
void updateState();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Params paramsMemory{"/dev/shm/params"};
|
||||||
|
|
||||||
|
UIScene &scene;
|
||||||
|
|
||||||
|
bool trafficModeActive;
|
||||||
|
|
||||||
|
int personality;
|
||||||
|
|
||||||
|
QElapsedTimer transitionTimer;
|
||||||
|
|
||||||
|
QVector<std::pair<QPixmap, QString>> profile_data;
|
||||||
|
QVector<std::pair<QPixmap, QString>> profile_data_kaofui;
|
||||||
|
};
|
||||||
|
|
||||||
class ExperimentalButton : public QPushButton {
|
class ExperimentalButton : public QPushButton {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -116,11 +142,14 @@ private:
|
|||||||
Params paramsMemory{"/dev/shm/params"};
|
Params paramsMemory{"/dev/shm/params"};
|
||||||
UIScene &scene;
|
UIScene &scene;
|
||||||
|
|
||||||
|
DistanceButton *distance_btn;
|
||||||
|
|
||||||
QHBoxLayout *bottom_layout;
|
QHBoxLayout *bottom_layout;
|
||||||
|
|
||||||
bool alwaysOnLateralActive;
|
bool alwaysOnLateralActive;
|
||||||
bool experimentalMode;
|
bool experimentalMode;
|
||||||
bool mapOpen;
|
bool mapOpen;
|
||||||
|
bool onroadDistanceButton;
|
||||||
bool showAlwaysOnLateralStatusBar;
|
bool showAlwaysOnLateralStatusBar;
|
||||||
bool showConditionalExperimentalStatusBar;
|
bool showConditionalExperimentalStatusBar;
|
||||||
|
|
||||||
|
@ -268,6 +268,10 @@ void ui_update_frogpilot_params(UIState *s) {
|
|||||||
scene.conditional_speed = scene.conditional_experimental ? params.getInt("CESpeed") : 0;
|
scene.conditional_speed = scene.conditional_experimental ? params.getInt("CESpeed") : 0;
|
||||||
scene.conditional_speed_lead = scene.conditional_experimental ? params.getInt("CESpeedLead") : 0;
|
scene.conditional_speed_lead = scene.conditional_experimental ? params.getInt("CESpeedLead") : 0;
|
||||||
scene.show_cem_status_bar = scene.conditional_experimental && !params.getBool("HideCEMStatusBar");
|
scene.show_cem_status_bar = scene.conditional_experimental && !params.getBool("HideCEMStatusBar");
|
||||||
|
|
||||||
|
bool driving_personalities = scene.longitudinal_control && params.getBool("DrivingPersonalities");
|
||||||
|
scene.onroad_distance_button = driving_personalities && params.getBool("OnroadDistanceButton");
|
||||||
|
scene.use_kaofui_icons = scene.onroad_distance_button && params.getBool("KaofuiIcons");
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIState::updateStatus() {
|
void UIState::updateStatus() {
|
||||||
|
@ -188,11 +188,13 @@ typedef struct UIScene {
|
|||||||
bool experimental_mode;
|
bool experimental_mode;
|
||||||
bool map_open;
|
bool map_open;
|
||||||
bool online;
|
bool online;
|
||||||
|
bool onroad_distance_button;
|
||||||
bool parked;
|
bool parked;
|
||||||
bool right_hand_drive;
|
bool right_hand_drive;
|
||||||
bool show_aol_status_bar;
|
bool show_aol_status_bar;
|
||||||
bool show_cem_status_bar;
|
bool show_cem_status_bar;
|
||||||
bool tethering_enabled;
|
bool tethering_enabled;
|
||||||
|
bool use_kaofui_icons;
|
||||||
|
|
||||||
int alert_size;
|
int alert_size;
|
||||||
int conditional_speed;
|
int conditional_speed;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user