From c3aa7cffed66dc1794acfb73117ba8ade8e3523e Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Sat, 7 Jun 2025 12:10:51 +0800 Subject: [PATCH] ui: add auto camera switching based on speed in experimental mode (#35437) * add auto camera switching based on speed in experimental mode * fix conflit --- selfdrive/ui/onroad/augmented_road_view.py | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/selfdrive/ui/onroad/augmented_road_view.py b/selfdrive/ui/onroad/augmented_road_view.py index 738bd48c47..6520c827be 100644 --- a/selfdrive/ui/onroad/augmented_road_view.py +++ b/selfdrive/ui/onroad/augmented_road_view.py @@ -25,6 +25,9 @@ BORDER_COLORS = { UIStatus.ENGAGED: rl.Color(0x17, 0x86, 0x44, 0xF1), # Green for engaged state } +WIDE_CAM_MAX_SPEED = 10.0 # m/s (22 mph) +ROAD_CAM_MIN_SPEED = 15.0 # m/s (34 mph) + class AugmentedRoadView(CameraView): def __init__(self, stream_type: VisionStreamType = VisionStreamType.VISION_STREAM_ROAD): @@ -51,6 +54,8 @@ class AugmentedRoadView(CameraView): if not ui_state.started: return + self._switch_stream_if_needed(ui_state.sm) + # Update calibration before rendering self._update_calibration() @@ -93,6 +98,22 @@ class AugmentedRoadView(CameraView): border_color = BORDER_COLORS.get(ui_state.status, BORDER_COLORS[UIStatus.DISENGAGED]) rl.draw_rectangle_lines_ex(rect, UI_BORDER_SIZE, border_color) + def _switch_stream_if_needed(self, sm): + if sm['selfdriveState'].experimentalMode and WIDE_CAM in self.available_streams: + v_ego = sm['carState'].vEgo + if v_ego < WIDE_CAM_MAX_SPEED: + target = WIDE_CAM + elif v_ego > ROAD_CAM_MIN_SPEED: + target = ROAD_CAM + else: + # Hysteresis zone - keep current stream + target = self.stream_type + else: + target = ROAD_CAM + + if self.stream_type != target: + self.switch_stream(target) + def _update_calibration(self): # Update device camera if not already set sm = ui_state.sm @@ -128,7 +149,7 @@ class AugmentedRoadView(CameraView): # Get camera configuration device_camera = self.device_camera or DEFAULT_DEVICE_CAMERA - is_wide_camera = self.stream_type == VisionStreamType.VISION_STREAM_WIDE_ROAD + is_wide_camera = self.stream_type == WIDE_CAM intrinsic = device_camera.ecam.intrinsics if is_wide_camera else device_camera.fcam.intrinsics calibration = self.view_from_wide_calib if is_wide_camera else self.view_from_calib zoom = 2.0 if is_wide_camera else 1.1