From 409872bf13c54e39f7b324204a277dad77679f91 Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Mon, 29 Apr 2024 15:58:25 -0700 Subject: [PATCH] Camera view selection Added toggle to select the preferred camera view between "auto", "standard", "wide", and "driver". --- common/params.cc | 2 ++ selfdrive/frogpilot/ui/qt/offroad/visual_settings.cc | 5 +++++ selfdrive/frogpilot/ui/qt/offroad/visual_settings.h | 2 +- selfdrive/manager/manager.py | 4 ++++ selfdrive/ui/qt/onroad.cc | 8 ++++++-- selfdrive/ui/qt/onroad.h | 1 + selfdrive/ui/ui.cc | 1 + selfdrive/ui/ui.h | 1 + 8 files changed, 21 insertions(+), 3 deletions(-) diff --git a/common/params.cc b/common/params.cc index 187eb2983..f148c3acc 100644 --- a/common/params.cc +++ b/common/params.cc @@ -218,6 +218,8 @@ std::unordered_map keys = { {"ApiCache_DriveStats", PERSISTENT}, {"AutomaticUpdates", PERSISTENT}, {"BlindSpotPath", PERSISTENT}, + {"CameraView", PERSISTENT}, + {"CameraViewReset", PERSISTENT}, {"CustomAlerts", PERSISTENT}, {"CustomPaths", PERSISTENT}, {"CustomUI", PERSISTENT}, diff --git a/selfdrive/frogpilot/ui/qt/offroad/visual_settings.cc b/selfdrive/frogpilot/ui/qt/offroad/visual_settings.cc index 71a954931..19137e27d 100644 --- a/selfdrive/frogpilot/ui/qt/offroad/visual_settings.cc +++ b/selfdrive/frogpilot/ui/qt/offroad/visual_settings.cc @@ -17,6 +17,7 @@ FrogPilotVisualsPanel::FrogPilotVisualsPanel(SettingsWindow *parent) : FrogPilot {"CustomPaths", tr("Paths"), tr("Show your projected acceleration on the driving path, detected adjacent lanes, or when a vehicle is detected in your blindspot."), ""}, {"QOLVisuals", tr("Quality of Life"), tr("Miscellaneous quality of life changes to improve your overall openpilot experience."), "../frogpilot/assets/toggle_icons/quality_of_life.png"}, + {"CameraView", tr("Camera View"), tr("Choose your preferred camera view for the onroad UI. This is purely a visual change and doesn't impact how openpilot drives."), ""}, }; for (const auto &[param, title, desc, icon] : visualToggles) { @@ -75,6 +76,10 @@ FrogPilotVisualsPanel::FrogPilotVisualsPanel(SettingsWindow *parent) : FrogPilot } }); toggle = qolToggle; + } else if (param == "CameraView") { + std::vector cameraOptions{tr("Auto"), tr("Driver"), tr("Standard"), tr("Wide")}; + FrogPilotButtonParamControl *preferredCamera = new FrogPilotButtonParamControl(param, title, desc, icon, cameraOptions); + toggle = preferredCamera; } else { toggle = new ParamControl(param, title, desc, icon, this); diff --git a/selfdrive/frogpilot/ui/qt/offroad/visual_settings.h b/selfdrive/frogpilot/ui/qt/offroad/visual_settings.h index a5677901e..d167564a3 100644 --- a/selfdrive/frogpilot/ui/qt/offroad/visual_settings.h +++ b/selfdrive/frogpilot/ui/qt/offroad/visual_settings.h @@ -27,7 +27,7 @@ private: std::set customOnroadUIKeys = {"CustomPaths"}; std::set customThemeKeys = {}; std::set modelUIKeys = {}; - std::set qolKeys = {}; + std::set qolKeys = {"CameraView"}; std::set screenKeys = {}; std::map toggles; diff --git a/selfdrive/manager/manager.py b/selfdrive/manager/manager.py index d93999509..bf30bb1bf 100644 --- a/selfdrive/manager/manager.py +++ b/selfdrive/manager/manager.py @@ -62,6 +62,10 @@ def manager_init(frogpilot_functions) -> None: if is_release_branch(): params.clear_all(ParamKeyType.DEVELOPMENT_ONLY) + if not params.get_bool("CameraViewReset"): + params.remove("CameraView") + params.put_bool("CameraViewReset", True) + default_params: list[tuple[str, str | bytes]] = [ ("CarParamsPersistent", ""), ("CompletedTrainingVersion", "0"), diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index f5ddf5ec5..fd9ca07cd 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -658,7 +658,7 @@ void AnnotatedCameraWidget::paintGL() { // Wide or narrow cam dependent on speed bool has_wide_cam = available_streams.count(VISION_STREAM_WIDE_ROAD); - if (has_wide_cam) { + if (has_wide_cam && cameraView == 0) { float v_ego = sm["carState"].getCarState().getVEgo(); if ((v_ego < 10) || available_streams.size() == 1) { wide_cam_requested = true; @@ -669,7 +669,9 @@ void AnnotatedCameraWidget::paintGL() { // for replay of old routes, never go to widecam wide_cam_requested = wide_cam_requested && s->scene.calibration_wide_valid; } - CameraWidget::setStreamType(wide_cam_requested ? VISION_STREAM_WIDE_ROAD : VISION_STREAM_ROAD); + CameraWidget::setStreamType(cameraView == 1 ? VISION_STREAM_DRIVER : + cameraView == 3 || wide_cam_requested ? VISION_STREAM_WIDE_ROAD : + VISION_STREAM_ROAD); s->scene.wide_cam = CameraWidget::getStreamType() == VISION_STREAM_WIDE_ROAD; if (s->scene.calibration_valid) { @@ -756,6 +758,8 @@ void AnnotatedCameraWidget::updateFrogPilotWidgets() { blindSpotLeft = scene.blind_spot_left; blindSpotRight = scene.blind_spot_right; + cameraView = scene.camera_view; + experimentalMode = scene.experimental_mode; mapOpen = scene.map_open; diff --git a/selfdrive/ui/qt/onroad.h b/selfdrive/ui/qt/onroad.h index eef6dcf6f..3b5391ada 100644 --- a/selfdrive/ui/qt/onroad.h +++ b/selfdrive/ui/qt/onroad.h @@ -126,6 +126,7 @@ private: bool showAlwaysOnLateralStatusBar; int alertSize; + int cameraView; protected: void paintGL() override; diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 9bc9e857c..3c44ae795 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -271,6 +271,7 @@ void ui_update_frogpilot_params(UIState *s) { bool quality_of_life_controls = params.getBool("QOLControls"); bool quality_of_life_visuals = params.getBool("QOLVisuals"); + scene.camera_view = quality_of_life_visuals ? params.getInt("CameraView") : 0; } void UIState::updateStatus() { diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 72acd0f47..dd50f9ef4 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -187,6 +187,7 @@ typedef struct UIScene { float lane_width_right; int alert_size; + int camera_view; QPolygonF track_adjacent_vertices[6];