From 1d05704d27dbe4f73c0eba7e8dad2ae84d4e205e Mon Sep 17 00:00:00 2001 From: ZwX1616 Date: Wed, 17 Apr 2024 12:56:37 -0700 Subject: [PATCH] Toggle to always enable DM (#32205) * permanent * param * correct behavior * toggle * need trans * ref_commit * translate for chs/t * disable on P and R * read --- common/params.cc | 1 + selfdrive/controls/lib/events.py | 12 ++++++------ selfdrive/monitoring/dmonitoringd.py | 8 ++++++-- selfdrive/monitoring/driver_monitor.py | 15 +++++++++++---- selfdrive/monitoring/test_monitoring.py | 2 +- selfdrive/test/process_replay/ref_commit | 2 +- selfdrive/ui/qt/offroad/settings.cc | 6 ++++++ selfdrive/ui/translations/main_ar.ts | 8 ++++++++ selfdrive/ui/translations/main_de.ts | 8 ++++++++ selfdrive/ui/translations/main_fr.ts | 8 ++++++++ selfdrive/ui/translations/main_ja.ts | 8 ++++++++ selfdrive/ui/translations/main_ko.ts | 8 ++++++++ selfdrive/ui/translations/main_pt-BR.ts | 8 ++++++++ selfdrive/ui/translations/main_th.ts | 8 ++++++++ selfdrive/ui/translations/main_tr.ts | 8 ++++++++ selfdrive/ui/translations/main_zh-CHS.ts | 8 ++++++++ selfdrive/ui/translations/main_zh-CHT.ts | 8 ++++++++ 17 files changed, 112 insertions(+), 14 deletions(-) diff --git a/common/params.cc b/common/params.cc index 8635f30d26..a00401d20a 100644 --- a/common/params.cc +++ b/common/params.cc @@ -89,6 +89,7 @@ private: std::unordered_map keys = { {"AccessToken", CLEAR_ON_MANAGER_START | DONT_LOG}, + {"AlwaysOnDM", PERSISTENT}, {"ApiCache_Device", PERSISTENT}, {"ApiCache_NavDestinations", PERSISTENT}, {"AssistNowToken", PERSISTENT}, diff --git a/selfdrive/controls/lib/events.py b/selfdrive/controls/lib/events.py index c6e9504f35..2de4d61d88 100755 --- a/selfdrive/controls/lib/events.py +++ b/selfdrive/controls/lib/events.py @@ -433,7 +433,7 @@ EVENTS: dict[int, dict[str, Alert | AlertCallbackType]] = { }, EventName.preDriverDistracted: { - ET.WARNING: Alert( + ET.PERMANENT: Alert( "Pay Attention", "", AlertStatus.normal, AlertSize.small, @@ -441,7 +441,7 @@ EVENTS: dict[int, dict[str, Alert | AlertCallbackType]] = { }, EventName.promptDriverDistracted: { - ET.WARNING: Alert( + ET.PERMANENT: Alert( "Pay Attention", "Driver Distracted", AlertStatus.userPrompt, AlertSize.mid, @@ -449,7 +449,7 @@ EVENTS: dict[int, dict[str, Alert | AlertCallbackType]] = { }, EventName.driverDistracted: { - ET.WARNING: Alert( + ET.PERMANENT: Alert( "DISENGAGE IMMEDIATELY", "Driver Distracted", AlertStatus.critical, AlertSize.full, @@ -457,7 +457,7 @@ EVENTS: dict[int, dict[str, Alert | AlertCallbackType]] = { }, EventName.preDriverUnresponsive: { - ET.WARNING: Alert( + ET.PERMANENT: Alert( "Touch Steering Wheel: No Face Detected", "", AlertStatus.normal, AlertSize.small, @@ -465,7 +465,7 @@ EVENTS: dict[int, dict[str, Alert | AlertCallbackType]] = { }, EventName.promptDriverUnresponsive: { - ET.WARNING: Alert( + ET.PERMANENT: Alert( "Touch Steering Wheel", "Driver Unresponsive", AlertStatus.userPrompt, AlertSize.mid, @@ -473,7 +473,7 @@ EVENTS: dict[int, dict[str, Alert | AlertCallbackType]] = { }, EventName.driverUnresponsive: { - ET.WARNING: Alert( + ET.PERMANENT: Alert( "DISENGAGE IMMEDIATELY", "Driver Unresponsive", AlertStatus.critical, AlertSize.full, diff --git a/selfdrive/monitoring/dmonitoringd.py b/selfdrive/monitoring/dmonitoringd.py index 579e79093f..84a147bd47 100755 --- a/selfdrive/monitoring/dmonitoringd.py +++ b/selfdrive/monitoring/dmonitoringd.py @@ -17,7 +17,7 @@ def dmonitoringd_thread(): pm = messaging.PubMaster(['driverMonitoringState']) sm = messaging.SubMaster(['driverStateV2', 'liveCalibration', 'carState', 'controlsState', 'modelV2'], poll='driverStateV2') - driver_status = DriverStatus(rhd_saved=params.get_bool("IsRhdDetected")) + driver_status = DriverStatus(rhd_saved=params.get_bool("IsRhdDetected"), always_on=params.get_bool("AlwaysOnDM")) v_cruise_last = 0 driver_engaged = False @@ -52,7 +52,8 @@ def dmonitoringd_thread(): events.add(car.CarEvent.EventName.tooDistracted) # Update events from driver state - driver_status.update_events(events, driver_engaged, sm['controlsState'].enabled, sm['carState'].standstill) + driver_status.update_events(events, driver_engaged, sm['controlsState'].enabled, + sm['carState'].standstill, sm['carState'].gearShifter in [car.CarState.GearShifter.reverse, car.CarState.GearShifter.park]) # build driverMonitoringState packet dat = messaging.new_message('driverMonitoringState', valid=sm.all_checks()) @@ -76,6 +77,9 @@ def dmonitoringd_thread(): } pm.send('driverMonitoringState', dat) + if sm['driverStateV2'].frameId % 40 == 1: + driver_status.always_on = params.get_bool("AlwaysOnDM") + # save rhd virtual toggle every 5 mins if (sm['driverStateV2'].frameId % 6000 == 0 and driver_status.wheelpos_learner.filtered_stat.n > driver_status.settings._WHEELPOS_FILTER_MIN_COUNT and diff --git a/selfdrive/monitoring/driver_monitor.py b/selfdrive/monitoring/driver_monitor.py index 7c1c297fff..749931af77 100644 --- a/selfdrive/monitoring/driver_monitor.py +++ b/selfdrive/monitoring/driver_monitor.py @@ -121,7 +121,7 @@ class DriverBlink(): self.right_blink = 0. class DriverStatus(): - def __init__(self, rhd_saved=False, settings=None): + def __init__(self, rhd_saved=False, settings=None, always_on=False): if settings is None: settings = DRIVER_MONITOR_SETTINGS() # init policy settings @@ -139,6 +139,7 @@ class DriverStatus(): self.ee1_calibrated = False self.ee2_calibrated = False + self.always_on = always_on self.awareness = 1. self.awareness_active = 1. self.awareness_passive = 1. @@ -301,8 +302,12 @@ class DriverStatus(): elif self.face_detected and self.pose.low_std: self.hi_stds = 0 - def update_events(self, events, driver_engaged, ctrl_active, standstill): - if (driver_engaged and self.awareness > 0 and not self.active_monitoring_mode) or not ctrl_active: # reset only when on disengagement if red reached + def update_events(self, events, driver_engaged, ctrl_active, standstill, wrong_gear): + always_on_valid = self.always_on and not wrong_gear + if (driver_engaged and self.awareness > 0 and not self.active_monitoring_mode) or \ + (not always_on_valid and not ctrl_active) or \ + (always_on_valid and not ctrl_active and self.awareness <= 0): + # always reset on disengage with normal mode; disengage resets only on red if always on self._reset_awareness() return @@ -323,11 +328,13 @@ class DriverStatus(): return standstill_exemption = standstill and self.awareness - self.step_change <= self.threshold_prompt + always_on_red_exemption = always_on_valid and not ctrl_active and self.awareness - self.step_change <= 0 certainly_distracted = self.driver_distraction_filter.x > 0.63 and self.driver_distracted and self.face_detected maybe_distracted = self.hi_stds > self.settings._HI_STD_FALLBACK_TIME or not self.face_detected if certainly_distracted or maybe_distracted: # should always be counting if distracted unless at standstill and reaching orange - if not standstill_exemption: + # also will not be reaching 0 if DM is active when not engaged + if not standstill_exemption and not always_on_red_exemption: self.awareness = max(self.awareness - self.step_change, -0.1) alert = None diff --git a/selfdrive/monitoring/test_monitoring.py b/selfdrive/monitoring/test_monitoring.py index c02d44849f..39fef75479 100755 --- a/selfdrive/monitoring/test_monitoring.py +++ b/selfdrive/monitoring/test_monitoring.py @@ -63,7 +63,7 @@ class TestMonitoring(unittest.TestCase): # cal_rpy and car_speed don't matter here # evaluate events at 10Hz for tests - DS.update_events(e, interaction[idx], engaged[idx], standstill[idx]) + DS.update_events(e, interaction[idx], engaged[idx], standstill[idx], 0) events.append(e) assert len(events) == len(msgs), f"got {len(events)} for {len(msgs)} driverState input msgs" return events, DS diff --git a/selfdrive/test/process_replay/ref_commit b/selfdrive/test/process_replay/ref_commit index 1156aefeb2..a253da0258 100644 --- a/selfdrive/test/process_replay/ref_commit +++ b/selfdrive/test/process_replay/ref_commit @@ -1 +1 @@ -28001018eae89eb4906717bebf892345ad590b5a +f759be555103697918d5d6c22292ef10536e68bd \ No newline at end of file diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 5aa33974ac..96fe6585cc 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -51,6 +51,12 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) { tr("Receive alerts to steer back into the lane when your vehicle drifts over a detected lane line without a turn signal activated while driving over 31 mph (50 km/h)."), "../assets/offroad/icon_warning.png", }, + { + "AlwaysOnDM", + tr("Always-On Driver Monitoring"), + tr("Enable driver monitoring even when openpilot is not engaged."), + "../assets/offroad/icon_monitoring.png", + }, { "RecordFront", tr("Record and Upload Driver Camera"), diff --git a/selfdrive/ui/translations/main_ar.ts b/selfdrive/ui/translations/main_ar.ts index 85b1fd040a..f00905b75b 100644 --- a/selfdrive/ui/translations/main_ar.ts +++ b/selfdrive/ui/translations/main_ar.ts @@ -1182,6 +1182,14 @@ This may take up to a minute. The driving visualization will transition to the road-facing wide-angle camera at low speeds to better show some turns. The Experimental mode logo will also be shown in the top right corner. + + Always-On Driver Monitoring + + + + Enable driver monitoring even when openpilot is not engaged. + + Updater diff --git a/selfdrive/ui/translations/main_de.ts b/selfdrive/ui/translations/main_de.ts index 4154c47abb..71d95244cb 100644 --- a/selfdrive/ui/translations/main_de.ts +++ b/selfdrive/ui/translations/main_de.ts @@ -1168,6 +1168,14 @@ This may take up to a minute. The driving visualization will transition to the road-facing wide-angle camera at low speeds to better show some turns. The Experimental mode logo will also be shown in the top right corner. + + Always-On Driver Monitoring + + + + Enable driver monitoring even when openpilot is not engaged. + + Updater diff --git a/selfdrive/ui/translations/main_fr.ts b/selfdrive/ui/translations/main_fr.ts index 0736e161a8..5da51d8b47 100644 --- a/selfdrive/ui/translations/main_fr.ts +++ b/selfdrive/ui/translations/main_fr.ts @@ -1166,6 +1166,14 @@ Cela peut prendre jusqu'à une minute. The driving visualization will transition to the road-facing wide-angle camera at low speeds to better show some turns. The Experimental mode logo will also be shown in the top right corner. La visualisation de la conduite passera sur la caméra grand angle dirigée vers la route à faible vitesse afin de mieux montrer certains virages. Le logo du mode expérimental s'affichera également dans le coin supérieur droit. + + Always-On Driver Monitoring + + + + Enable driver monitoring even when openpilot is not engaged. + + Updater diff --git a/selfdrive/ui/translations/main_ja.ts b/selfdrive/ui/translations/main_ja.ts index 0bfca5e826..7a27f46ea3 100644 --- a/selfdrive/ui/translations/main_ja.ts +++ b/selfdrive/ui/translations/main_ja.ts @@ -1160,6 +1160,14 @@ This may take up to a minute. The driving visualization will transition to the road-facing wide-angle camera at low speeds to better show some turns. The Experimental mode logo will also be shown in the top right corner. + + Always-On Driver Monitoring + + + + Enable driver monitoring even when openpilot is not engaged. + + Updater diff --git a/selfdrive/ui/translations/main_ko.ts b/selfdrive/ui/translations/main_ko.ts index 639371d135..518bb4b58f 100644 --- a/selfdrive/ui/translations/main_ko.ts +++ b/selfdrive/ui/translations/main_ko.ts @@ -1162,6 +1162,14 @@ This may take up to a minute. The driving visualization will transition to the road-facing wide-angle camera at low speeds to better show some turns. The Experimental mode logo will also be shown in the top right corner. + + Always-On Driver Monitoring + + + + Enable driver monitoring even when openpilot is not engaged. + + Updater diff --git a/selfdrive/ui/translations/main_pt-BR.ts b/selfdrive/ui/translations/main_pt-BR.ts index 2706166b47..71f6a5caa6 100644 --- a/selfdrive/ui/translations/main_pt-BR.ts +++ b/selfdrive/ui/translations/main_pt-BR.ts @@ -1166,6 +1166,14 @@ Isso pode levar até um minuto. The driving visualization will transition to the road-facing wide-angle camera at low speeds to better show some turns. The Experimental mode logo will also be shown in the top right corner. A visualização de condução fará a transição para a câmera grande angular voltada para a estrada em baixas velocidades para mostrar melhor algumas curvas. O logotipo do modo Experimental também será mostrado no canto superior direito. + + Always-On Driver Monitoring + + + + Enable driver monitoring even when openpilot is not engaged. + + Updater diff --git a/selfdrive/ui/translations/main_th.ts b/selfdrive/ui/translations/main_th.ts index b196e0459a..c8bf0d3ade 100644 --- a/selfdrive/ui/translations/main_th.ts +++ b/selfdrive/ui/translations/main_th.ts @@ -1162,6 +1162,14 @@ This may take up to a minute. The driving visualization will transition to the road-facing wide-angle camera at low speeds to better show some turns. The Experimental mode logo will also be shown in the top right corner. การแสดงภาพการขับขี่จะเปลี่ยนไปใช้กล้องมุมกว้างที่หันหน้าไปทางถนนเมื่ออยู่ในความเร็วต่ำ เพื่อแสดงภาพการเลี้ยวที่ดีขึ้น โลโก้โหมดการทดลองจะแสดงที่มุมบนขวาด้วย + + Always-On Driver Monitoring + + + + Enable driver monitoring even when openpilot is not engaged. + + Updater diff --git a/selfdrive/ui/translations/main_tr.ts b/selfdrive/ui/translations/main_tr.ts index 4b51ce9b42..000fc1a2ec 100644 --- a/selfdrive/ui/translations/main_tr.ts +++ b/selfdrive/ui/translations/main_tr.ts @@ -1160,6 +1160,14 @@ This may take up to a minute. The driving visualization will transition to the road-facing wide-angle camera at low speeds to better show some turns. The Experimental mode logo will also be shown in the top right corner. + + Always-On Driver Monitoring + + + + Enable driver monitoring even when openpilot is not engaged. + + Updater diff --git a/selfdrive/ui/translations/main_zh-CHS.ts b/selfdrive/ui/translations/main_zh-CHS.ts index 3e2a041758..3d9cf1c001 100644 --- a/selfdrive/ui/translations/main_zh-CHS.ts +++ b/selfdrive/ui/translations/main_zh-CHS.ts @@ -1162,6 +1162,14 @@ This may take up to a minute. The driving visualization will transition to the road-facing wide-angle camera at low speeds to better show some turns. The Experimental mode logo will also be shown in the top right corner. + + Always-On Driver Monitoring + 驾驶员监控常开 + + + Enable driver monitoring even when openpilot is not engaged. + 即使在openpilot未激活时也启用驾驶员监控。 + Updater diff --git a/selfdrive/ui/translations/main_zh-CHT.ts b/selfdrive/ui/translations/main_zh-CHT.ts index c12b2c5fdd..d9030b82ff 100644 --- a/selfdrive/ui/translations/main_zh-CHT.ts +++ b/selfdrive/ui/translations/main_zh-CHT.ts @@ -1162,6 +1162,14 @@ This may take up to a minute. The driving visualization will transition to the road-facing wide-angle camera at low speeds to better show some turns. The Experimental mode logo will also be shown in the top right corner. + + Always-On Driver Monitoring + 駕駛監控常開 + + + Enable driver monitoring even when openpilot is not engaged. + 即使在openpilot未激活時也啟用駕駛監控。 + Updater