clear irrelevant alerts on state transition (#2318)
* cleanup * clear warnings * more types * needs refactor * update refs * update refsalbatross
parent
de833ecb06
commit
1c6905cac1
|
@ -447,9 +447,10 @@ class Controls:
|
|||
if CC.hudControl.rightLaneDepart or CC.hudControl.leftLaneDepart:
|
||||
self.events.add(EventName.ldw)
|
||||
|
||||
clear_event = ET.WARNING if ET.WARNING in self.current_alert_types else None
|
||||
alerts = self.events.create_alerts(self.current_alert_types, [self.CP, self.sm, self.is_metric])
|
||||
self.AM.add_many(self.sm.frame, alerts, self.enabled)
|
||||
self.AM.process_alerts(self.sm.frame)
|
||||
self.AM.process_alerts(self.sm.frame, clear_event)
|
||||
CC.hudControl.visualAlert = self.AM.visual_alert
|
||||
|
||||
if not self.read_only:
|
||||
|
|
|
@ -32,9 +32,6 @@ class AlertManager:
|
|||
self.activealerts: List[Alert] = []
|
||||
self.clear_current_alert()
|
||||
|
||||
def alert_present(self) -> bool:
|
||||
return len(self.activealerts) > 0
|
||||
|
||||
def clear_current_alert(self) -> None:
|
||||
self.alert_type: str = ""
|
||||
self.alert_text_1: str = ""
|
||||
|
@ -46,34 +43,32 @@ class AlertManager:
|
|||
self.alert_rate: float = 0.
|
||||
|
||||
def add_many(self, frame: int, alerts: List[Alert], enabled: bool = True) -> None:
|
||||
for a in alerts:
|
||||
self.add(frame, a, enabled=enabled)
|
||||
for alert in alerts:
|
||||
added_alert = copy.copy(alert)
|
||||
added_alert.start_time = frame * DT_CTRL
|
||||
|
||||
def add(self, frame: int, alert: Alert, enabled: bool = True) -> None:
|
||||
added_alert = copy.copy(alert)
|
||||
added_alert.start_time = frame * DT_CTRL
|
||||
# if new alert is higher priority, log it
|
||||
if not len(self.activealerts) or added_alert.alert_priority > self.activealerts[0].alert_priority:
|
||||
cloudlog.event('alert_add', alert_type=added_alert.alert_type, enabled=enabled)
|
||||
|
||||
# if new alert is higher priority, log it
|
||||
if not self.alert_present() or added_alert.alert_priority > self.activealerts[0].alert_priority:
|
||||
cloudlog.event('alert_add', alert_type=added_alert.alert_type, enabled=enabled)
|
||||
self.activealerts.append(added_alert)
|
||||
|
||||
self.activealerts.append(added_alert)
|
||||
def process_alerts(self, frame: int, clear_event_type=None) -> None:
|
||||
cur_time = frame * DT_CTRL
|
||||
|
||||
# first get rid of all the expired alerts
|
||||
self.activealerts = [a for a in self.activealerts if a.event_type != clear_event_type and
|
||||
a.start_time + max(a.duration_sound, a.duration_hud_alert, a.duration_text) > cur_time]
|
||||
|
||||
# sort by priority first and then by start_time
|
||||
self.activealerts.sort(key=lambda k: (k.alert_priority, k.start_time), reverse=True)
|
||||
|
||||
def process_alerts(self, frame: int) -> None:
|
||||
cur_time = frame * DT_CTRL
|
||||
|
||||
# first get rid of all the expired alerts
|
||||
self.activealerts = [a for a in self.activealerts if a.start_time +
|
||||
max(a.duration_sound, a.duration_hud_alert, a.duration_text) > cur_time]
|
||||
|
||||
# start with assuming no alerts
|
||||
self.clear_current_alert()
|
||||
|
||||
current_alert = self.activealerts[0] if self.alert_present() else None
|
||||
if current_alert is not None:
|
||||
if len(self.activealerts):
|
||||
current_alert = self.activealerts[0]
|
||||
|
||||
self.alert_type = current_alert.alert_type
|
||||
|
||||
if current_alert.start_time + current_alert.duration_sound > cur_time:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from functools import total_ordering
|
||||
from enum import IntEnum
|
||||
from typing import Dict, Union, Callable, Any
|
||||
|
||||
from cereal import log, car
|
||||
|
@ -14,7 +14,7 @@ AudibleAlert = car.CarControl.HUDControl.AudibleAlert
|
|||
EventName = car.CarEvent.EventName
|
||||
|
||||
# Alert priorities
|
||||
class Priority:
|
||||
class Priority(IntEnum):
|
||||
LOWEST = 0
|
||||
LOWER = 1
|
||||
LOW = 2
|
||||
|
@ -79,6 +79,7 @@ class Events:
|
|||
|
||||
if DT_CTRL * (self.events_prev[e] + 1) >= alert.creation_delay:
|
||||
alert.alert_type = f"{EVENT_NAME[e]}/{et}"
|
||||
alert.event_type = et
|
||||
ret.append(alert)
|
||||
return ret
|
||||
|
||||
|
@ -96,23 +97,21 @@ class Events:
|
|||
ret.append(event)
|
||||
return ret
|
||||
|
||||
@total_ordering
|
||||
class Alert:
|
||||
def __init__(self,
|
||||
alert_text_1: str,
|
||||
alert_text_2: str,
|
||||
alert_status,
|
||||
alert_size,
|
||||
alert_priority,
|
||||
visual_alert,
|
||||
audible_alert,
|
||||
alert_status: log.ControlsState.AlertStatus,
|
||||
alert_size: log.ControlsState.AlertSize,
|
||||
alert_priority: Priority,
|
||||
visual_alert: car.CarControl.HUDControl.VisualAlert,
|
||||
audible_alert: car.CarControl.HUDControl.AudibleAlert,
|
||||
duration_sound: float,
|
||||
duration_hud_alert: float,
|
||||
duration_text: float,
|
||||
alert_rate: float = 0.,
|
||||
creation_delay: float = 0.):
|
||||
|
||||
self.alert_type = ""
|
||||
self.alert_text_1 = alert_text_1
|
||||
self.alert_text_2 = alert_text_2
|
||||
self.alert_status = alert_status
|
||||
|
@ -125,24 +124,19 @@ class Alert:
|
|||
self.duration_hud_alert = duration_hud_alert
|
||||
self.duration_text = duration_text
|
||||
|
||||
self.start_time = 0.
|
||||
self.alert_rate = alert_rate
|
||||
self.creation_delay = creation_delay
|
||||
|
||||
# typecheck that enums are valid on startup
|
||||
tst = car.CarControl.new_message()
|
||||
tst.hudControl.visualAlert = self.visual_alert
|
||||
self.start_time = 0.
|
||||
self.alert_type = ""
|
||||
self.event_type = None
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.alert_text_1 + "/" + self.alert_text_2 + " " + str(self.alert_priority) + " " + str(
|
||||
self.visual_alert) + " " + str(self.audible_alert)
|
||||
return f"{self.alert_text_1}/{self.alert_text_2} {self.alert_priority} {self.visual_alert} {self.audible_alert}"
|
||||
|
||||
def __gt__(self, alert2) -> bool:
|
||||
return self.alert_priority > alert2.alert_priority
|
||||
|
||||
def __eq__(self, alert2) -> bool:
|
||||
return self.alert_priority == alert2.alert_priority
|
||||
|
||||
class NoEntryAlert(Alert):
|
||||
def __init__(self, alert_text_2, audible_alert=AudibleAlert.chimeError,
|
||||
visual_alert=VisualAlert.none, duration_hud_alert=2.):
|
||||
|
|
|
@ -1 +1 @@
|
|||
1ca0db37c9fab1328fe1f86cc884b9bc7123aaee
|
||||
6f90ffa4970c48edc018ee733bf81b3231b4c463
|
Loading…
Reference in New Issue