From c51c185d5b2d27e2ec28e2d3d0ed7fc1e75ab536 Mon Sep 17 00:00:00 2001 From: Alfonso hernandez Date: Thu, 1 Feb 2024 13:28:53 +0100 Subject: [PATCH] Debug: Tap on Ui to capture snapshot of debug data --- common/params.cc | 1 + selfdrive/ui/qt/offroad/settings.cc | 6 +++ selfdrive/ui/qt/onroad.cc | 69 +++++++++++++++++++++++- selfdrive/ui/soundd/sound.cc | 2 +- selfdrive/ui/translations/main_ar.ts | 23 ++++++++ selfdrive/ui/translations/main_de.ts | 23 ++++++++ selfdrive/ui/translations/main_fr.ts | 23 ++++++++ selfdrive/ui/translations/main_ja.ts | 23 ++++++++ selfdrive/ui/translations/main_ko.ts | 23 ++++++++ selfdrive/ui/translations/main_pt-BR.ts | 23 ++++++++ selfdrive/ui/translations/main_th.ts | 23 ++++++++ selfdrive/ui/translations/main_tr.ts | 23 ++++++++ selfdrive/ui/translations/main_zh-CHS.ts | 23 ++++++++ selfdrive/ui/translations/main_zh-CHT.ts | 23 ++++++++ selfdrive/ui/ui.cc | 1 + selfdrive/ui/ui.h | 9 +++- 16 files changed, 314 insertions(+), 4 deletions(-) diff --git a/common/params.cc b/common/params.cc index 8603670d36b7ae..ec0bca003eee16 100644 --- a/common/params.cc +++ b/common/params.cc @@ -114,6 +114,7 @@ std::unordered_map keys = { {"DoReboot", CLEAR_ON_MANAGER_START}, {"DoShutdown", CLEAR_ON_MANAGER_START}, {"DoUninstall", CLEAR_ON_MANAGER_START}, + {"EnableDebugSnapshot", PERSISTENT}, {"ExperimentalLongitudinalEnabled", PERSISTENT}, {"ExperimentalMode", PERSISTENT}, {"ExperimentalModeConfirmed", PERSISTENT}, diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index e824e4e7113a4e..7f297c5bf07cfd 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -107,6 +107,12 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) { "Show UI elements that aid debugging.", "../assets/offroad/icon_calibration.png", }, + { + "EnableDebugSnapshot", + "Debug snapshot on screen center tap", + "Stores snapshot file with current state of some modules.", + "../assets/offroad/icon_calibration.png", + }, #ifdef ENABLE_MAPS { "NavSettingTime24h", diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index 33117a298af747..1e6de8a905d61e 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include "common/timing.h" #include "selfdrive/ui/qt/util.h" @@ -75,7 +76,7 @@ void OnroadWindow::updateState(const UIState &s) { } QColor bgColor = bg_colors[s.status]; - Alert alert = Alert::get(*(s.sm), s.scene.started_frame); + Alert alert = Alert::get(*(s.sm), s.scene.started_frame, s.scene.display_debug_alert_frame); alerts->updateAlert(alert); if (s.scene.map_on_left) { @@ -93,6 +94,68 @@ void OnroadWindow::updateState(const UIState &s) { } } +void issue_debug_snapshot(SubMaster &sm) { + auto longitudinal_plan = sm["longitudinalPlan"].getLongitudinalPlan(); + auto live_map_data = sm["liveMapData"].getLiveMapData(); + auto car_state = sm["carState"].getCarState(); + + auto t = std::time(nullptr); + auto tm = *std::localtime(&t); + std::ostringstream param_name_os; + param_name_os << std::put_time(&tm, "%Y-%m-%d--%H-%M-%S"); + + std::ostringstream os; + os.setf(std::ios_base::fixed); + os.precision(2); + os << "Datetime: " << param_name_os.str() << ", vEgo: " << car_state.getVEgo() * 3.6 << "\n\n"; + os.precision(6); + os << "Location: (" << live_map_data.getLastGpsLatitude() << ", " << live_map_data.getLastGpsLongitude() << ")\n"; + os.precision(2); + os << "Bearing: " << live_map_data.getLastGpsBearingDeg() << "; "; + os << "GPSSpeed: " << live_map_data.getLastGpsSpeed() * 3.6 << "\n\n"; + os.precision(1); + os << "Speed Limit: " << live_map_data.getSpeedLimit() * 3.6 << ", "; + os << "Valid: " << live_map_data.getSpeedLimitValid() << "\n"; + os << "Speed Limit Ahead: " << live_map_data.getSpeedLimitAhead() * 3.6 << ", "; + os << "Valid: " << live_map_data.getSpeedLimitAheadValid() << ", "; + os << "Distance: " << live_map_data.getSpeedLimitAheadDistance() << "\n"; + os << "Turn Speed Limit: " << live_map_data.getTurnSpeedLimit() * 3.6 << ", "; + os << "Valid: " << live_map_data.getTurnSpeedLimitValid() << ", "; + os << "End Distance: " << live_map_data.getTurnSpeedLimitEndDistance() << ", "; + os << "Sign: " << live_map_data.getTurnSpeedLimitSign() << "\n\n"; + + const auto turn_speeds = live_map_data.getTurnSpeedLimitsAhead(); + os << "Turn Speed Limits Ahead:\n"; + os << "VALUE\tDIST\tSIGN\n"; + + if (turn_speeds.size() == 0) { + os << "-\t-\t-" << "\n\n"; + } else { + const auto distances = live_map_data.getTurnSpeedLimitsAheadDistances(); + const auto signs = live_map_data.getTurnSpeedLimitsAheadSigns(); + for (int i = 0; i < turn_speeds.size(); i++) { + os << turn_speeds[i] * 3.6 << "\t" << distances[i] << "\t" << signs[i] << "\n"; + } + os << "\n"; + } + + os << "SPEED LIMIT CONTROLLER:\n"; + os << "sl: " << longitudinal_plan.getSpeedLimit() * 3.6 << ", "; + os << "state: " << int(longitudinal_plan.getSpeedLimitControlState()) << ", "; + os << "isMap: " << longitudinal_plan.getIsMapSpeedLimit() << "\n\n"; + + os << "TURN SPEED CONTROLLER:\n"; + os << "speed: " << longitudinal_plan.getTurnSpeed() * 3.6 << ", "; + os << "state: " << int(longitudinal_plan.getTurnSpeedControlState()) << "\n\n"; + + os << "VISION TURN CONTROLLER:\n"; + os << "speed: " << longitudinal_plan.getVisionTurnSpeed() * 3.6 << ", "; + os << "state: " << int(longitudinal_plan.getVisionTurnControllerState()); + + Params().put(param_name_os.str().c_str(), os.str().c_str(), os.str().length()); + uiState()->scene.display_debug_alert_frame = sm.frame; +} + void OnroadWindow::mousePressEvent(QMouseEvent* e) { bool propagate_event = true; @@ -100,6 +163,7 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) { SubMaster &sm = *(uiState()->sm); auto longitudinal_plan = sm["longitudinalPlan"].getLongitudinalPlan(); const QRect speed_limit_touch_rect = speed_sgn_rc.adjusted(-50, -50, 50, 50); + const QRect debug_tap_rect = QRect(rect().center().x() - 200, rect().center().y() - 200, 400, 400); if (longitudinal_plan.getSpeedLimit() > 0.0 && speed_limit_touch_rect.contains(e->x(), e->y())) { // If touching the speed limit sign area when visible @@ -107,6 +171,9 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) { uiState()->scene.speed_limit_control_enabled = !uiState()->scene.speed_limit_control_enabled; Params().putBool("SpeedLimitControl", uiState()->scene.speed_limit_control_enabled); propagate_event = false; + } else if (uiState()->scene.debug_snapshot_enabled && debug_tap_rect.contains(e->x(), e->y())) { + issue_debug_snapshot(sm); + propagate_event = false; } #ifdef ENABLE_MAPS else diff --git a/selfdrive/ui/soundd/sound.cc b/selfdrive/ui/soundd/sound.cc index a5884f113fbcc9..128b9dd0110504 100644 --- a/selfdrive/ui/soundd/sound.cc +++ b/selfdrive/ui/soundd/sound.cc @@ -1,4 +1,4 @@ -#include "selfdrive/ui/soundd/sound.h" + #include "selfdrive/ui/soundd/sound.h" #include diff --git a/selfdrive/ui/translations/main_ar.ts b/selfdrive/ui/translations/main_ar.ts index 4159f28c31e11f..47db6f9cd86263 100644 --- a/selfdrive/ui/translations/main_ar.ts +++ b/selfdrive/ui/translations/main_ar.ts @@ -460,6 +460,29 @@ تنبيه + + OnroadWindow + + km/h + كم/س + + + mph + ميل/س + + + MAX + MAX + + + SPEED + SPEED + + + LIMIT + LIMIT + + PairingPopup diff --git a/selfdrive/ui/translations/main_de.ts b/selfdrive/ui/translations/main_de.ts index e2e57719059c28..d302686e1e605e 100644 --- a/selfdrive/ui/translations/main_de.ts +++ b/selfdrive/ui/translations/main_de.ts @@ -455,6 +455,29 @@ HINWEIS + + OnroadWindow + + km/h + km/h + + + mph + mph + + + MAX + MAX + + + SPEED + Geschwindigkeit + + + LIMIT + LIMIT + + PairingPopup diff --git a/selfdrive/ui/translations/main_fr.ts b/selfdrive/ui/translations/main_fr.ts index 456efe63660961..bdaa479cac17c9 100644 --- a/selfdrive/ui/translations/main_fr.ts +++ b/selfdrive/ui/translations/main_fr.ts @@ -456,6 +456,29 @@ ALERTE + + OnroadWindow + + km/h + km/h + + + mph + mi/h + + + MAX + MAX + + + SPEED + VITESSE + + + LIMIT + LIMITE + + PairingPopup diff --git a/selfdrive/ui/translations/main_ja.ts b/selfdrive/ui/translations/main_ja.ts index 63de8f047120ca..05f825e4c77c12 100644 --- a/selfdrive/ui/translations/main_ja.ts +++ b/selfdrive/ui/translations/main_ja.ts @@ -454,6 +454,29 @@ 警告 + + OnroadWindow + + km/h + km/h + + + mph + mph + + + MAX + 最高速度 + + + SPEED + 速度 + + + LIMIT + 制限速度 + + PairingPopup diff --git a/selfdrive/ui/translations/main_ko.ts b/selfdrive/ui/translations/main_ko.ts index bc0c5f2b0e56e8..195696a08bfc45 100644 --- a/selfdrive/ui/translations/main_ko.ts +++ b/selfdrive/ui/translations/main_ko.ts @@ -455,6 +455,29 @@ 알림 + + OnroadWindow + + km/h + km/h + + + mph + mph + + + MAX + MAX + + + SPEED + SPEED + + + LIMIT + LIMIT + + PairingPopup diff --git a/selfdrive/ui/translations/main_pt-BR.ts b/selfdrive/ui/translations/main_pt-BR.ts index 4cf37cc5857b26..1163562ce18932 100644 --- a/selfdrive/ui/translations/main_pt-BR.ts +++ b/selfdrive/ui/translations/main_pt-BR.ts @@ -456,6 +456,29 @@ ALERTA + + OnroadWindow + + km/h + km/h + + + mph + mph + + + MAX + LIMITE + + + SPEED + MAX + + + LIMIT + VELO + + PairingPopup diff --git a/selfdrive/ui/translations/main_th.ts b/selfdrive/ui/translations/main_th.ts index a1748a6951118f..16bc753dad1744 100644 --- a/selfdrive/ui/translations/main_th.ts +++ b/selfdrive/ui/translations/main_th.ts @@ -455,6 +455,29 @@ การแจ้งเตือน + + OnroadWindow + + km/h + กม./ชม. + + + mph + ไมล์/ชม. + + + MAX + สูงสุด + + + SPEED + ความเร็ว + + + LIMIT + จำกัด + + PairingPopup diff --git a/selfdrive/ui/translations/main_tr.ts b/selfdrive/ui/translations/main_tr.ts index 51fdddd5ce6d6e..c6caf40c1c5429 100644 --- a/selfdrive/ui/translations/main_tr.ts +++ b/selfdrive/ui/translations/main_tr.ts @@ -454,6 +454,29 @@ UYARI + + OnroadWindow + + km/h + km/h + + + mph + mph + + + MAX + MAX + + + SPEED + HIZ + + + LIMIT + LİMİT + + PairingPopup diff --git a/selfdrive/ui/translations/main_zh-CHS.ts b/selfdrive/ui/translations/main_zh-CHS.ts index 7b682535ce9e39..bb2531fc9b9bd0 100644 --- a/selfdrive/ui/translations/main_zh-CHS.ts +++ b/selfdrive/ui/translations/main_zh-CHS.ts @@ -455,6 +455,29 @@ 警报 + + OnroadWindow + + km/h + km/h + + + mph + mph + + + MAX + 最高定速 + + + SPEED + SPEED + + + LIMIT + LIMIT + + PairingPopup diff --git a/selfdrive/ui/translations/main_zh-CHT.ts b/selfdrive/ui/translations/main_zh-CHT.ts index 1794cc78ac1389..2dcdd47d460c2b 100644 --- a/selfdrive/ui/translations/main_zh-CHT.ts +++ b/selfdrive/ui/translations/main_zh-CHT.ts @@ -455,6 +455,29 @@ 提醒 + + OnroadWindow + + km/h + km/h + + + mph + mph + + + MAX + 最高 + + + SPEED + 速度 + + + LIMIT + 速限 + + PairingPopup diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index aede26143b67c0..7e1938150317ec 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -234,6 +234,7 @@ void UIState::updateStatus() { scene.show_debug_ui = Params().getBool("ShowDebugUI"); scene.speed_limit_control_enabled = Params().getBool("SpeedLimitControl"); scene.speed_limit_perc_offset = Params().getBool("SpeedLimitPercOffset"); + scene.debug_snapshot_enabled = Params().getBool("EnableDebugSnapshot"); } started_prev = scene.started; emit offroadTransition(!scene.started); diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 2787ebbc7a7e6d..efb24476c69d14 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -49,12 +49,15 @@ struct Alert { return text1 == a2.text1 && text2 == a2.text2 && type == a2.type && sound == a2.sound; } - static Alert get(const SubMaster &sm, uint64_t started_frame) { + static Alert get(const SubMaster &sm, uint64_t started_frame, uint64_t display_debug_alert_frame = 0) { const cereal::ControlsState::Reader &cs = sm["controlsState"].getControlsState(); const uint64_t controls_frame = sm.rcv_frame("controlsState"); Alert alert = {}; - if (controls_frame >= started_frame) { // Don't get old alert. + if (display_debug_alert_frame > 0 && (sm.frame - display_debug_alert_frame) <= 1 * UI_FREQ) { + alert = {"Debug snapshot collected", "", "debugTapDetected", cereal::ControlsState::AlertSize::SMALL, + cereal::ControlsState::AlertStatus::NORMAL, AudibleAlert::WARNING_SOFT}; + } else if (controls_frame >= started_frame) { // Don't get old alert. alert = {cs.getAlertText1().cStr(), cs.getAlertText2().cStr(), cs.getAlertType().cStr(), cs.getAlertSize(), cs.getAlertStatus(), @@ -136,6 +139,8 @@ typedef struct UIScene { // Debug UI bool show_debug_ui; + bool debug_snapshot_enabled; + uint64_t display_debug_alert_frame; // Speed limit control bool speed_limit_control_enabled;