Skip to content
Draft
Show file tree
Hide file tree
Changes from 10 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
22 changes: 20 additions & 2 deletions cereal/log.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -771,13 +771,31 @@ struct SelfdriveState {
alertStatus @5 :AlertStatus;
alertSize @6 :AlertSize;
alertType @7 :Text;
alertSound @8 :Car.CarControl.HUDControl.AudibleAlert;
alertSoundDEPRECATED @8 :Car.CarControl.HUDControl.AudibleAlert;
Comment thread
elkoled marked this conversation as resolved.
Outdated
alertSound @13 :AudibleAlert;
alertHudVisual @12 :Car.CarControl.HUDControl.VisualAlert;

# configurable driving settings
experimentalMode @10 :Bool;
personality @11 :LongitudinalPersonality;

enum AudibleAlert {
none @0;

engage @1;
disengage @2;
refuse @3;

warningSoft @4;
warningImmediate @5;

prompt @6;
promptRepeat @7;
promptDistracted @8;

laneChangeConfirmed @9;
Comment thread
elkoled marked this conversation as resolved.
Outdated
}

enum OpenpilotState @0xdbe58b96d2d1ac61 {
disabled @0;
preEnabled @1;
Expand Down Expand Up @@ -918,7 +936,7 @@ struct ControlsState @0x97ff69c53601abf1 {
alertStatus @38 :SelfdriveState.AlertStatus;
alertSize @39 :SelfdriveState.AlertSize;
alertType @44 :Text;
alertSound2 @56 :Car.CarControl.HUDControl.AudibleAlert;
alertSound2 @56 :SelfdriveState.AudibleAlert;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like it will break backwards compatibility with old logs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the schema is identical up to @Confirmation, tested with master log against this branch.

engageable @41 :Bool; # can OP be engaged?
state @31 :SelfdriveState.OpenpilotState;
enabled @19 :Bool;
Expand Down
3 changes: 3 additions & 0 deletions selfdrive/assets/sounds/chime.wav
Git LFS file not shown
4 changes: 2 additions & 2 deletions selfdrive/assets/sounds/disengage.wav
Git LFS file not shown
4 changes: 2 additions & 2 deletions selfdrive/assets/sounds/engage.wav
Git LFS file not shown
4 changes: 2 additions & 2 deletions selfdrive/assets/sounds/prompt.wav
Git LFS file not shown
4 changes: 2 additions & 2 deletions selfdrive/assets/sounds/prompt_distracted.wav
Git LFS file not shown
4 changes: 2 additions & 2 deletions selfdrive/assets/sounds/refuse.wav
Git LFS file not shown
4 changes: 2 additions & 2 deletions selfdrive/assets/sounds/warning_immediate.wav
Git LFS file not shown
4 changes: 2 additions & 2 deletions selfdrive/assets/sounds/warning_soft.wav
Git LFS file not shown
8 changes: 4 additions & 4 deletions selfdrive/selfdrived/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
AlertSize = log.SelfdriveState.AlertSize
AlertStatus = log.SelfdriveState.AlertStatus
VisualAlert = car.CarControl.HUDControl.VisualAlert
AudibleAlert = car.CarControl.HUDControl.AudibleAlert
AudibleAlert = log.SelfdriveState.AudibleAlert
EventName = log.OnroadEvent.EventName


Expand Down Expand Up @@ -117,7 +117,7 @@ def __init__(self,
alert_size: log.SelfdriveState.AlertSize,
priority: Priority,
visual_alert: car.CarControl.HUDControl.VisualAlert,
audible_alert: car.CarControl.HUDControl.AudibleAlert,
audible_alert: log.SelfdriveState.AudibleAlert,
duration: float,
creation_delay: float = 0.):

Expand Down Expand Up @@ -182,7 +182,7 @@ def __init__(self, alert_text_2: str):


class EngagementAlert(Alert):
def __init__(self, audible_alert: car.CarControl.HUDControl.AudibleAlert):
def __init__(self, audible_alert: log.SelfdriveState.AudibleAlert):
super().__init__("", "",
AlertStatus.normal, AlertSize.none,
Priority.MID, VisualAlert.none,
Expand Down Expand Up @@ -609,7 +609,7 @@ def invalid_lkas_setting_alert(CP: car.CarParams, CS: car.CarState, sm: messagin
"Changing Lanes",
"",
AlertStatus.normal, AlertSize.small,
Priority.LOW, VisualAlert.none, AudibleAlert.none, .1),
Priority.LOW, VisualAlert.none, AudibleAlert.laneChangeConfirmed, .1),
},

EventName.steerSaturated: {
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/ui/mici/onroad/driver_camera_dialog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pyray as rl
from cereal import car, log, messaging
from cereal import log, messaging
from msgq.visionipc import VisionStreamType
from openpilot.selfdrive.ui.mici.onroad.cameraview import CameraView
from openpilot.selfdrive.ui.mici.onroad.driver_state import DriverStateRenderer
Expand Down Expand Up @@ -104,7 +104,7 @@ def _publish_alert_sound(self, dm_state):
if self._pm is None:
return

AudibleAlert = car.CarControl.HUDControl.AudibleAlert
AudibleAlert = log.SelfdriveState.AudibleAlert
ALERT_SOUNDS = {
'two': AudibleAlert.promptDistracted,
'three': AudibleAlert.warningImmediate,
Expand Down
16 changes: 14 additions & 2 deletions selfdrive/ui/soundd.py
Comment thread
elkoled marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import wave


from cereal import car, messaging
from cereal import log, messaging
from openpilot.common.basedir import BASEDIR
from openpilot.common.filter_simple import FirstOrderFilter
from openpilot.common.realtime import Ratekeeper
Expand All @@ -30,7 +30,7 @@
AMBIENT_DB = 30
VOLUME_BASE = 10

AudibleAlert = car.CarControl.HUDControl.AudibleAlert
AudibleAlert = log.SelfdriveState.AudibleAlert


sound_list: dict[int, tuple[str, int | None, float]] = {
Expand All @@ -45,6 +45,8 @@

AudibleAlert.warningSoft: ("warning_soft.wav", None, MAX_VOLUME),
AudibleAlert.warningImmediate: ("warning_immediate.wav", None, MAX_VOLUME),

AudibleAlert.laneChangeConfirmed: ("chime.wav", 1, MAX_VOLUME),
}
if HARDWARE.get_device_type() == "tizi":
sound_list.update({
Expand Down Expand Up @@ -74,6 +76,7 @@ def __init__(self):
self.ramp_start_time = 0.

self.selfdrive_timeout_alert = False
self.pending_stop = False

self.spl_filter_weighted = FirstOrderFilter(0, 2.5, FILTER_DT, initialized=False)

Expand Down Expand Up @@ -112,6 +115,10 @@ def get_sound_data(self, frames): # get "frames" worth of data from the current
self.current_sound_frame += frames_to_write
current_sound_frame = self.current_sound_frame % len(sound_data)
loops = self.current_sound_frame // len(sound_data)
if self.pending_stop and current_sound_frame == 0:
self.current_alert = AudibleAlert.none
self.pending_stop = False
break

return ret * self.current_volume

Expand All @@ -121,6 +128,11 @@ def callback(self, data_out: np.ndarray, frames: int, time, status) -> None:
data_out[:frames, 0] = self.get_sound_data(frames)

def update_alert(self, new_alert):
# let looping sounds complete instead of cutting off when there is no new alert pending
if new_alert == AudibleAlert.none and self.current_alert != AudibleAlert.none and sound_list[self.current_alert][1] is None:
self.pending_stop = True
return
self.pending_stop = False
current_alert_played_once = self.current_alert == AudibleAlert.none or self.current_sound_frame >= len(self.loaded_sounds[self.current_alert])
if self.current_alert != new_alert and (new_alert != AudibleAlert.none or current_alert_played_once):
if new_alert == AudibleAlert.warningImmediate:
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/ui/tests/test_soundd.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from cereal import car
from cereal import log
from cereal import messaging
from cereal.messaging import SubMaster, PubMaster
from openpilot.selfdrive.ui.soundd import SELFDRIVE_STATE_TIMEOUT, check_selfdrive_timeout_alert

import time

AudibleAlert = car.CarControl.HUDControl.AudibleAlert
AudibleAlert = log.SelfdriveState.AudibleAlert


class TestSoundd:
Expand Down
Loading