Rotating steering wheel in onroad UI

Added toggle to rotate the steering wheel in the top right corner of the onroad UI.
This commit is contained in:
FrogAi
2024-04-03 16:22:08 -07:00
parent f174661e81
commit d52faeef33
6 changed files with 24 additions and 3 deletions
+1
View File
@@ -359,6 +359,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"RoadEdgesWidth", PERSISTENT},
{"RoadName", PERSISTENT},
{"RoadNameUI", PERSISTENT},
{"RotatingWheel", PERSISTENT},
{"SchedulePending", PERSISTENT},
{"SearchInput", PERSISTENT},
{"ShowCPU", PERSISTENT},
Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

+16 -3
View File
@@ -18,15 +18,19 @@
#include "selfdrive/ui/qt/maps/map_panel.h"
#endif
static void drawIcon(QPainter &p, const QPoint &center, const QPixmap &img, const QBrush &bg, float opacity) {
static void drawIcon(QPainter &p, const QPoint &center, const QPixmap &img, const QBrush &bg, float opacity, const int angle = 0) {
p.setRenderHint(QPainter::Antialiasing);
p.setOpacity(1.0); // bg dictates opacity of ellipse
p.setPen(Qt::NoPen);
p.setBrush(bg);
p.drawEllipse(center, btn_size / 2, btn_size / 2);
p.save();
p.translate(center);
p.rotate(-angle);
p.setOpacity(opacity);
p.drawPixmap(center - QPoint(img.width() / 2, img.height() / 2), img);
p.drawPixmap(-QPoint(img.width() / 2, img.height() / 2), img);
p.setOpacity(1.0);
p.restore();
}
OnroadWindow::OnroadWindow(QWidget *parent) : QWidget(parent), scene(uiState()->scene) {
@@ -394,14 +398,23 @@ void ExperimentalButton::updateState(const UIState &s, bool leadInfo) {
}
// FrogPilot variables
rotatingWheel = scene.rotating_wheel;
y_offset = leadInfo ? 10 : 0;
if (rotatingWheel && steeringAngleDeg != scene.steering_angle_deg) {
update();
steeringAngleDeg = scene.steering_angle_deg;
} else if (!rotatingWheel) {
steeringAngleDeg = 0;
}
}
void ExperimentalButton::paintEvent(QPaintEvent *event) {
QPainter p(this);
QPixmap img = experimental_mode ? experimental_img : engage_img;
if (!(scene.map_open && scene.big_map)) {
drawIcon(p, QPoint(btn_size / 2, btn_size / 2 + y_offset), img, QColor(0, 0, 0, 166), (isDown() || !engageable) ? 0.6 : 1.0);
drawIcon(p, QPoint(btn_size / 2, btn_size / 2 + y_offset), img, QColor(0, 0, 0, 166), (isDown() || !engageable) ? 0.6 : 1.0, steeringAngleDeg);
}
}
+3
View File
@@ -104,6 +104,9 @@ private:
Params paramsMemory{"/dev/shm/params"};
UIScene &scene;
bool rotatingWheel;
int steeringAngleDeg;
int y_offset;
};
+2
View File
@@ -234,6 +234,7 @@ static void update_state(UIState *s) {
scene.blind_spot_right = carState.getRightBlindspot();
scene.reverse = carState.getGearShifter() == cereal::CarState::GearShifter::REVERSE;
scene.standstill = carState.getStandstill();
scene.steering_angle_deg = carState.getSteeringAngleDeg();
scene.turn_signal_left = carState.getLeftBlinker();
scene.turn_signal_right = carState.getRightBlinker();
}
@@ -325,6 +326,7 @@ void ui_update_frogpilot_params(UIState *s) {
scene.lead_info = scene.longitudinal_control && custom_onroad_ui && params.getBool("LeadInfo");
scene.pedals_on_ui = custom_onroad_ui && params.getBool("PedalsOnUI");
scene.road_name_ui = custom_onroad_ui && params.getBool("RoadNameUI");
scene.rotating_wheel = custom_onroad_ui && params.getBool("RotatingWheel");
scene.show_jerk = scene.longitudinal_control && developer_ui && params.getBool("ShowJerk");
scene.show_tuning = scene.has_auto_tune && developer_ui && !(params.getBool("LateralTune") && params.getBool("NNFF")) && params.getBool("ShowTuning");
scene.use_si = (scene.lead_info || developer_ui) && params.getBool("UseSI");
+2
View File
@@ -214,6 +214,7 @@ typedef struct UIScene {
bool reverse_cruise_ui;
bool right_hand_drive;
bool road_name_ui;
bool rotating_wheel;
bool show_aol_status_bar;
bool show_cem_status_bar;
bool show_jerk;
@@ -256,6 +257,7 @@ typedef struct UIScene {
int driver_camera_timer;
int obstacle_distance;
int obstacle_distance_stock;
int steering_angle_deg;
int stopped_equivalence;
QPolygonF track_adjacent_vertices[6];