Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play disengage chime when booting while engaged #34884

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cereal/log.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct OnroadEvent @0xc4fa6047f024e718 {
controlsMismatch @22;
pcmEnable @23;
pcmDisable @24;
cancellingCruise @94;
radarFault @25;
radarTempUnavailable @93;
brakeHold @26;
Expand Down
16 changes: 16 additions & 0 deletions selfdrive/selfdrived/alertmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class AlertManager:
def __init__(self):
self.alerts: dict[str, AlertEntry] = defaultdict(AlertEntry)
self.current_alert = EmptyAlert
self.current_audible_alert = EmptyAlert

def add_many(self, frame: int, alerts: list[Alert]) -> None:
for alert in alerts:
Expand All @@ -52,6 +53,7 @@ def add_many(self, frame: int, alerts: list[Alert]) -> None:

def process_alerts(self, frame: int, clear_event_types: set):
ae = AlertEntry()
ae_audible = AlertEntry()
for v in self.alerts.values():
if not v.alert:
continue
Expand All @@ -63,5 +65,19 @@ def process_alerts(self, frame: int, clear_event_types: set):
greater = ae.alert is None or (v.alert.priority, v.start_frame) > (ae.alert.priority, ae.start_frame)
if v.active(frame) and greater:
ae = v
ae_audible = v

for v in self.alerts.values():
if not v.alert:
continue

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

# sort by priority first and then by start_frame
greater = ae_audible.alert is None or (v.alert.priority, v.start_frame) > (ae_audible.alert.priority, ae_audible.start_frame)
if v.active(frame) and v.alert.alert_size == AlertSize.none and greater:
ae_audible = v

self.current_alert = ae.alert if ae.alert is not None else EmptyAlert
self.current_alert = ae_audible.alert if ae_audible.alert is not None else EmptyAlert
16 changes: 13 additions & 3 deletions selfdrive/selfdrived/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,11 @@ def __init__(self, alert_text_1: str, alert_text_2: str = "", duration: float =


class StartupAlert(Alert):
def __init__(self, alert_text_1: str, alert_text_2: str = "Always keep hands on wheel and eyes on road", alert_status=AlertStatus.normal):
def __init__(self, alert_text_1: str, alert_text_2: str = "Always keep hands on wheel and eyes on road", alert_status=AlertStatus.normal,
audible_alert: car.CarControl.HUDControl.AudibleAlert = AudibleAlert.none):
super().__init__(alert_text_1, alert_text_2,
alert_status, AlertSize.mid,
Priority.LOWER, VisualAlert.none, AudibleAlert.none, 5.),
Priority.LOWER, VisualAlert.none, audible_alert, 5.),


# ********** helper functions **********
Expand Down Expand Up @@ -229,7 +230,12 @@ def startup_master_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubM
if "REPLAY" in os.environ:
branch = "replay"

return StartupAlert("WARNING: This branch is not tested", branch, alert_status=AlertStatus.userPrompt)
# TODO: also need cb for other startup alerts
audible_alert = AudibleAlert.none
if CS.cruiseState.enabled:
audible_alert = AudibleAlert.disengage

return StartupAlert("WARNING: This branch is not tested", branch, alert_status=AlertStatus.userPrompt, audible_alert=audible_alert)

def below_engage_speed_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int, personality) -> Alert:
return NoEntryAlert(f"Drive above {get_display_speed(CP.minEnableSpeed, metric)} to engage")
Expand Down Expand Up @@ -646,6 +652,10 @@ def personality_changed_alert(CP: car.CarParams, CS: car.CarState, sm: messaging
ET.USER_DISABLE: EngagementAlert(AudibleAlert.disengage),
},

EventName.cancellingCruise: {
ET.USER_DISABLE: EngagementAlert(AudibleAlert.disengage),
},

EventName.buttonCancel: {
ET.USER_DISABLE: EngagementAlert(AudibleAlert.disengage),
ET.NO_ENTRY: NoEntryAlert("Cancel Pressed"),
Expand Down
3 changes: 3 additions & 0 deletions selfdrive/selfdrived/selfdrived.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ def update_events(self, CS):
if self.CP.passive:
return

if CS.cruiseState.enabled and not self.enabled:
self.events.add(EventName.cancellingCruise)

# Block resume if cruise never previously enabled
resume_pressed = any(be.type in (ButtonType.accelCruise, ButtonType.resumeCruise) for be in CS.buttonEvents)
if not self.CP.pcmCruise and CS.vCruise > 250 and resume_pressed:
Expand Down
Loading