diff --git a/openpilot/cereal/log.capnp b/openpilot/cereal/log.capnp index cf69ce44c3..b884002b11 100644 --- a/openpilot/cereal/log.capnp +++ b/openpilot/cereal/log.capnp @@ -844,6 +844,7 @@ struct SelfdriveState { preAlert @9; complete @10; + warningImmediateSystem @11; } enum OpenpilotState @0xdbe58b96d2d1ac61 { diff --git a/openpilot/selfdrive/selfdrived/events.py b/openpilot/selfdrive/selfdrived/events.py index 862ecae65c..d4a895dcd5 100755 --- a/openpilot/selfdrive/selfdrived/events.py +++ b/openpilot/selfdrive/selfdrived/events.py @@ -175,11 +175,11 @@ class UserSoftDisableAlert(SoftDisableAlert): class ImmediateDisableAlert(Alert): - def __init__(self, alert_text_2: str): + def __init__(self, alert_text_2: str, *, user_triggered: bool = False): super().__init__("TAKE CONTROL IMMEDIATELY", alert_text_2, AlertStatus.critical, AlertSize.full, Priority.HIGHEST, VisualAlert.steerRequired, - AudibleAlert.warningImmediate, 4.), + AudibleAlert.warningImmediate if user_triggered else AudibleAlert.warningImmediateSystem, 4.), class EngagementAlert(Alert): @@ -232,7 +232,7 @@ def soft_disable_alert(alert_text_2: str) -> AlertCallbackType: def user_soft_disable_alert(alert_text_2: str) -> AlertCallbackType: def func(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int, personality) -> Alert: if soft_disable_time < int(0.5 / DT_CTRL): - return ImmediateDisableAlert(alert_text_2) + return ImmediateDisableAlert(alert_text_2, user_triggered=True) return UserSoftDisableAlert(alert_text_2) return func @@ -964,7 +964,7 @@ EVENTS: dict[int, dict[str, Alert | AlertCallbackType]] = { "", AlertStatus.normal, AlertSize.full, Priority.LOWEST, VisualAlert.none, AudibleAlert.none, .2, creation_delay=0.5), - ET.USER_DISABLE: ImmediateDisableAlert("Reverse Gear"), + ET.USER_DISABLE: ImmediateDisableAlert("Reverse Gear", user_triggered=True), ET.NO_ENTRY: NoEntryAlert("Reverse Gear"), }, @@ -1084,7 +1084,7 @@ if HARDWARE.get_device_type() == 'mici': "", AlertStatus.normal, AlertSize.full, Priority.LOWEST, VisualAlert.none, AudibleAlert.none, .2, creation_delay=0.5), - ET.USER_DISABLE: ImmediateDisableAlert("Reverse"), + ET.USER_DISABLE: ImmediateDisableAlert("Reverse", user_triggered=True), ET.NO_ENTRY: NoEntryAlert("Reverse"), }, }) diff --git a/openpilot/selfdrive/ui/soundd.py b/openpilot/selfdrive/ui/soundd.py index a43eb0b899..ad5470bbb8 100644 --- a/openpilot/selfdrive/ui/soundd.py +++ b/openpilot/selfdrive/ui/soundd.py @@ -38,7 +38,8 @@ if HARDWARE.get_device_type() in ("tici", "tizi"): VOLUME_BASE = 10 AudibleAlert = log.SelfdriveState.AudibleAlert -CRITICAL_MAX = -1 # internal sound key, not an AudibleAlert +CRITICAL_MAX = -1 +SYSTEM_CRITICAL_MAX = -2 sound_list: dict[int, tuple[str, int | None, float]] = { @@ -55,7 +56,15 @@ sound_list: dict[int, tuple[str, int | None, float]] = { AudibleAlert.warningSoft: ("critical.wav", None, MAX_VOLUME), AudibleAlert.warningImmediate: ("dm_critical.wav", None, MAX_VOLUME), + AudibleAlert.warningImmediateSystem: ("critical.wav", None, MAX_VOLUME), CRITICAL_MAX: ("dm_critical_max.wav", None, MAX_VOLUME), + SYSTEM_CRITICAL_MAX: ("critical_max.wav", None, MAX_VOLUME), +} + +critical_max_sounds = { + AudibleAlert.warningSoft: SYSTEM_CRITICAL_MAX, + AudibleAlert.warningImmediate: CRITICAL_MAX, + AudibleAlert.warningImmediateSystem: SYSTEM_CRITICAL_MAX, } ALERT_VOLUME_KEYS = { @@ -68,6 +77,7 @@ ALERT_VOLUME_KEYS = { AudibleAlert.promptDistracted: "PromptDistractedVolume", AudibleAlert.warningSoft: "WarningSoftVolume", AudibleAlert.warningImmediate: "WarningImmediateVolume", + AudibleAlert.warningImmediateSystem: "WarningImmediateVolume", } def check_selfdrive_timeout_alert(sm): @@ -151,7 +161,7 @@ class Soundd: ambient = max(ambient, STARPILOT_AUTO_MIN) gain = ambient if key is None else effective_volume( key, self.saved_volumes.get(key), ambient, - immediate_ramp=self.current_volume if producing_alert in (AudibleAlert.warningSoft, AudibleAlert.warningImmediate) else None) + immediate_ramp=self.current_volume if producing_alert in critical_max_sounds else None) return ret * gain def _refresh_car_fingerprint(self) -> None: @@ -218,7 +228,7 @@ class Soundd: return self.pending_stop = False if self.current_alert != new_alert and (new_alert != AudibleAlert.none or current_alert_played_once): - if new_alert in (AudibleAlert.warningSoft, AudibleAlert.warningImmediate): + if new_alert in critical_max_sounds: self.ramp_start_volume = self.current_volume self.ramp_start_time = time.monotonic() self.current_alert = new_alert @@ -232,21 +242,22 @@ class Soundd: new_alert = self.axis_alerts.update(sm, new_alert, now_ns) self.update_alert(new_alert) elif check_selfdrive_timeout_alert(sm): - self.update_alert(AudibleAlert.warningImmediate) + self.update_alert(AudibleAlert.warningImmediateSystem) self.selfdrive_timeout_alert = True elif self.selfdrive_timeout_alert: self.update_alert(AudibleAlert.none) self.selfdrive_timeout_alert = False def update_critical_sound(self, now: float) -> None: - if self.current_alert in (AudibleAlert.warningSoft, AudibleAlert.warningImmediate): + if self.current_alert in critical_max_sounds: elapsed = now - self.ramp_start_time ramp_vol = float(np.interp(elapsed, [0, ALERT_RAMP_TIME], [self.ramp_start_volume, MAX_VOLUME])) self.current_volume = max(self.current_volume, ramp_vol) # Dismissal owns the current waveform's remaining tail. Escalating here # would reset its cursor and start an additional critical-max loop. - if elapsed >= ALERT_MAX_TIME and self.current_sound != CRITICAL_MAX and not self.pending_stop: - self.current_sound = CRITICAL_MAX + max_sound = critical_max_sounds[self.current_alert] + if elapsed >= ALERT_MAX_TIME and self.current_sound != max_sound and not self.pending_stop: + self.current_sound = max_sound self.current_sound_frame = 0 def calculate_volume(self, weighted_db):