From 6d8a1419386843502d9e0f1b1b80873ed6e28a0e Mon Sep 17 00:00:00 2001 From: Kevin Robert Keegan Date: Tue, 25 Jan 2022 02:13:59 -0800 Subject: [PATCH] Use Wide Road Camera as Light Sensor for Screen Brightness (#23610) Using the narrow camera as a light sensor meant that the reflection of our own headlights, tail lights, and head lights of opposing vehicles dominated the sensor value at night even though the broader overall scene is very dark. This has very little effect during daylight hours. The change affects nightime driving the most, resulting in a dimmer screen when it is dark. I think this makes more sense as the wide angle camera's field of view is much closer to the human eye's field of view than the narrow road camera. old-commit-hash: 347583d4238d31dbd042d963b0dd37e3028bbd10 --- selfdrive/ui/ui.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index bfb805fd59..d3f33294a1 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -166,16 +166,22 @@ static void update_state(UIState *s) { } } } - if (sm.updated("roadCameraState")) { + if (!Hardware::TICI() && sm.updated("roadCameraState")) { auto camera_state = sm["roadCameraState"].getRoadCameraState(); float max_lines = Hardware::EON() ? 5408 : 1904; float max_gain = Hardware::EON() ? 1.0: 10.0; float max_ev = max_lines * max_gain; - if (Hardware::TICI()) { - max_ev /= 6; - } + float ev = camera_state.getGain() * float(camera_state.getIntegLines()); + + scene.light_sensor = std::clamp(1.0 - (ev / max_ev), 0.0, 1.0); + } else if (Hardware::TICI() && sm.updated("wideRoadCameraState")) { + auto camera_state = sm["wideRoadCameraState"].getWideRoadCameraState(); + + float max_lines = 1904; + float max_gain = 10.0; + float max_ev = max_lines * max_gain / 6; float ev = camera_state.getGain() * float(camera_state.getIntegLines()); @@ -220,6 +226,7 @@ UIState::UIState(QObject *parent) : QObject(parent) { sm = std::make_unique>({ "modelV2", "controlsState", "liveCalibration", "radarState", "deviceState", "roadCameraState", "pandaStates", "carParams", "driverMonitoringState", "sensorEvents", "carState", "liveLocationKalman", + "wideRoadCameraState", }); Params params;