Skip to content

Commit

Permalink
clear no entry alerts if engaged (commaai#23559)
Browse files Browse the repository at this point in the history
* clear no entry alerts if engaged

* fix test
  • Loading branch information
adeebshihadeh authored Jan 17, 2022
1 parent 3f89834 commit 59894a6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,15 @@ def publish_logs(self, CS, start_time, actuators, lac_log):
if hudControl.rightLaneDepart or hudControl.leftLaneDepart:
self.events.add(EventName.ldw)

clear_event = ET.WARNING if ET.WARNING not in self.current_alert_types else None
clear_event_types = set()
if ET.WARNING not in self.current_alert_types:
clear_event_types.add(ET.WARNING)
if self.enabled:
clear_event_types.add(ET.NO_ENTRY)

alerts = self.events.create_alerts(self.current_alert_types, [self.CP, self.sm, self.is_metric, self.soft_disable_timer])
self.AM.add_many(self.sm.frame, alerts)
current_alert = self.AM.process_alerts(self.sm.frame, clear_event)
current_alert = self.AM.process_alerts(self.sm.frame, clear_event_types)
if current_alert:
hudControl.visualAlert = current_alert.visual_alert

Expand Down
4 changes: 2 additions & 2 deletions selfdrive/controls/lib/alertmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ def add_many(self, frame: int, alerts: List[Alert]) -> None:
min_end_frame = entry.start_frame + alert.duration
entry.end_frame = max(frame + 1, min_end_frame)

def process_alerts(self, frame: int, clear_event_type=None) -> Optional[Alert]:
def process_alerts(self, frame: int, clear_event_types: set) -> Optional[Alert]:
current_alert = AlertEntry()
for v in self.alerts.values():
if not v.alert:
continue

if clear_event_type and v.alert.event_type == clear_event_type:
if v.alert.event_type in clear_event_types:
v.end_frame = -1

# sort by priority first and then by start_frame
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/controls/lib/tests/test_alertmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_duration(self):
for frame in range(duration+10):
if frame < add_duration:
AM.add_many(frame, [alert, ])
current_alert = AM.process_alerts(frame)
current_alert = AM.process_alerts(frame, {})

shown = current_alert is not None
should_show = frame <= show_duration
Expand Down

0 comments on commit 59894a6

Please sign in to comment.