Skip to content
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
35 changes: 33 additions & 2 deletions cereal/log.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct OnroadEvent @0xc4fa6047f024e718 {
stockAeb @52;
stockLkas @98;
lateralManeuver @99;
laneChangeStarted @100;
ldw @53;
carUnrecognized @54;
invalidLkasSetting @55;
Expand Down Expand Up @@ -771,13 +772,31 @@ struct SelfdriveState {
alertStatus @5 :AlertStatus;
alertSize @6 :AlertSize;
alertType @7 :Text;
alertSound @8 :Car.CarControl.HUDControl.AudibleAlert;
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;

confirmation @9;
preAlert @10;
}

enum OpenpilotState @0xdbe58b96d2d1ac61 {
disabled @0;
preEnabled @1;
Expand All @@ -798,6 +817,10 @@ struct SelfdriveState {
mid @2;
full @3;
}

deprecated :group {
alertSound @8 :Car.CarControl.HUDControl.AudibleAlert;
}
}

struct ControlsState @0x97ff69c53601abf1 {
Expand Down Expand Up @@ -918,7 +941,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 Expand Up @@ -2431,6 +2454,13 @@ struct SoundPressure @0xdc24138990726023 {
}
}

struct SoundDebug {
volume @0 :Float32;
ambientDb @1 :Float32;
rawDb @2 :Float32;
alert @3 :SelfdriveState.AudibleAlert;
}

struct AudioData {
data @0 :Data;
sampleRate @1 :UInt32;
Expand Down Expand Up @@ -2515,6 +2545,7 @@ struct Event {
# microphone data
soundPressure @103 :SoundPressure;
rawAudioData @147 :AudioData;
soundDebug @152 :SoundDebug;

# systems stuff
androidLog @20 :AndroidLogEntry;
Expand Down
1 change: 1 addition & 0 deletions cereal/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self, should_log: bool, frequency: float, decimation: Optional[int]
"userBookmark": (True, 0., 1),
"soundPressure": (True, 10., 10),
"rawAudioData": (False, 20.),
"soundDebug": (False, 20.),
"bookmarkButton": (True, 0., 1),
"audioFeedback": (True, 0., 1),
"roadEncodeData": (False, 20., None, QueueSize.BIG),
Expand Down
2 changes: 2 additions & 0 deletions common/params_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
{"DoShutdown", {CLEAR_ON_MANAGER_START, BOOL}},
{"DoUninstall", {CLEAR_ON_MANAGER_START, BOOL}},
{"DriverTooDistracted", {CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_ON, BOOL}},
{"SingleToneSounds", {PERSISTENT, BOOL}},
{"AlphaLongitudinalEnabled", {PERSISTENT | DEVELOPMENT_ONLY, BOOL}},
{"ExperimentalMode", {PERSISTENT, BOOL}},
{"ExperimentalModeConfirmed", {PERSISTENT, BOOL}},
Expand Down Expand Up @@ -111,6 +112,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
{"RecordFrontLock", {PERSISTENT, BOOL}}, // for the internal fleet
{"SecOCKey", {PERSISTENT | DONT_LOG, STRING}},
{"ShowDebugInfo", {PERSISTENT, BOOL}},
{"ShowSoundDebug", {PERSISTENT, BOOL}},
{"RouteCount", {PERSISTENT, INT, "0"}},
{"SnoozeUpdate", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION, BOOL}},
{"SshEnabled", {PERSISTENT, 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
3 changes: 3 additions & 0 deletions selfdrive/assets/sounds/dual_disengage.wav
Git LFS file not shown
3 changes: 3 additions & 0 deletions selfdrive/assets/sounds/dual_engage.wav
Git LFS file not shown
4 changes: 2 additions & 2 deletions selfdrive/assets/sounds/engage.wav
Git LFS file not shown
3 changes: 3 additions & 0 deletions selfdrive/assets/sounds/pre_alert.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
18 changes: 13 additions & 5 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 @@ -517,7 +517,7 @@ def invalid_lkas_setting_alert(CP: car.CarParams, CS: car.CarState, sm: messagin
"Pay Attention",
"",
AlertStatus.normal, AlertSize.small,
Priority.LOW, VisualAlert.none, AudibleAlert.none, .1),
Priority.LOW, VisualAlert.none, AudibleAlert.preAlert, .1),
},

EventName.driverDistracted2: {
Expand Down Expand Up @@ -612,6 +612,14 @@ def invalid_lkas_setting_alert(CP: car.CarParams, CS: car.CarState, sm: messagin
Priority.LOW, VisualAlert.none, AudibleAlert.none, .1),
},

EventName.laneChangeStarted: {
ET.WARNING: Alert(
"",
"",
AlertStatus.normal, AlertSize.none,
Priority.MID, VisualAlert.none, AudibleAlert.confirmation, .2),
},

EventName.steerSaturated: {
ET.WARNING: Alert(
"Take Control",
Expand Down Expand Up @@ -1037,7 +1045,7 @@ def invalid_lkas_setting_alert(CP: car.CarParams, CS: car.CarState, sm: messagin
"Pay Attention",
"",
AlertStatus.normal, AlertSize.small,
Priority.LOW, VisualAlert.none, AudibleAlert.none, 2),
Priority.LOW, VisualAlert.none, AudibleAlert.preAlert, 2),
},
EventName.driverDistracted2: {
ET.PERMANENT: Alert(
Expand Down
3 changes: 3 additions & 0 deletions selfdrive/selfdrived/selfdrived.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ def update_events(self, CS):
self.events.add(EventName.preLaneChangeRight)
elif self.sm['modelV2'].meta.laneChangeState in (LaneChangeState.laneChangeStarting,
LaneChangeState.laneChangeFinishing):
# one-off event to prevent lanechange alert from being played repeatedly during lanechange
if EventName.laneChange not in self.events_prev:
self.events.add(EventName.laneChangeStarted)
self.events.add(EventName.laneChange)

for i, pandaState in enumerate(self.sm['pandaStates']):
Expand Down
12 changes: 12 additions & 0 deletions selfdrive/ui/layouts/settings/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,17 @@ def __init__(self):
initial_state=self._params.get_bool("ShowDebugInfo"),
callback=self._on_enable_ui_debug,
)

self._single_tone_toggle = toggle_item(
lambda: tr("Single Tone Sounds"),
description="",
initial_state=self._params.get_bool("SingleToneSounds"),
callback=self._on_single_tone_sounds,
)
self._on_enable_ui_debug(self._params.get_bool("ShowDebugInfo"))

self._scroller = Scroller([
self._single_tone_toggle,
self._adb_toggle,
self._ssh_toggle,
self._ssh_keys,
Expand Down Expand Up @@ -147,9 +155,13 @@ def _update_toggles(self):
("LateralManeuverMode", self._lat_maneuver_toggle),
("AlphaLongitudinalEnabled", self._alpha_long_toggle),
("ShowDebugInfo", self._ui_debug_toggle),
("SingleToneSounds", self._single_tone_toggle),
):
item.action_item.set_state(self._params.get_bool(key))

def _on_single_tone_sounds(self, state: bool):
self._params.put_bool("SingleToneSounds", state, block=True)

def _on_enable_ui_debug(self, state: bool):
self._params.put_bool("ShowDebugInfo", state, block=True)
gui_app.set_show_touches(state)
Expand Down
4 changes: 4 additions & 0 deletions selfdrive/ui/mici/layouts/settings/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ def ssh_keys_callback():
self._alpha_long_toggle = BigToggle("alpha longitudinal",
initial_state=ui_state.params.get_bool("AlphaLongitudinalEnabled"),
toggle_callback=self._on_alpha_long_enabled)
self._sound_debug_toggle = BigParamControl("show sound debug", "ShowSoundDebug")
self._single_tone_toggle = BigParamControl("single tone sounds", "SingleToneSounds")
self._debug_mode_toggle = BigParamControl("ui debug mode", "ShowDebugInfo",
toggle_callback=lambda checked: (gui_app.set_show_touches(checked),
gui_app.set_show_fps(checked)))

self._scroller.add_widgets([
self._sound_debug_toggle,
self._single_tone_toggle,
self._adb_toggle,
self._ssh_toggle,
self._ssh_keys_btn,
Expand Down
4 changes: 4 additions & 0 deletions selfdrive/ui/mici/onroad/augmented_road_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from openpilot.selfdrive.ui.mici.onroad.hud_renderer import HudRenderer
from openpilot.selfdrive.ui.mici.onroad.model_renderer import ModelRenderer
from openpilot.selfdrive.ui.mici.onroad.confidence_ball import ConfidenceBall
from openpilot.selfdrive.ui.mici.onroad.sound_debug import SoundDebug
from openpilot.selfdrive.ui.mici.onroad.cameraview import CameraView
from openpilot.system.ui.lib.application import FontWeight, gui_app, MousePos, MouseEvent
from openpilot.system.ui.widgets.label import UnifiedLabel
Expand Down Expand Up @@ -151,6 +152,7 @@ def __init__(self, bookmark_callback=None, stream_type: VisionStreamType = Visio
self._alert_renderer = AlertRenderer()
self._driver_state_renderer = DriverStateRenderer()
self._confidence_ball = ConfidenceBall()
self._sound_debug = SoundDebug()
self._offroad_label = UnifiedLabel("start the car to\nuse openpilot", 54, FontWeight.DISPLAY,
text_color=rl.Color(255, 255, 255, int(255 * 0.9)),
alignment=rl.GuiTextAlignment.TEXT_ALIGN_CENTER,
Expand Down Expand Up @@ -243,6 +245,8 @@ def _render(self, _):

self._bookmark_icon.render(self.rect)

self._sound_debug.render(self._content_rect)

def _switch_stream_if_needed(self, sm):
if sm['selfdriveState'].experimentalMode and WIDE_CAM in self.available_streams:
v_ego = sm['carState'].vEgo
Expand Down
5 changes: 3 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,8 +104,9 @@ def _publish_alert_sound(self, dm_state):
if self._pm is None:
return

AudibleAlert = car.CarControl.HUDControl.AudibleAlert
AudibleAlert = log.SelfdriveState.AudibleAlert
ALERT_SOUNDS = {
'one': AudibleAlert.preAlert,
'two': AudibleAlert.promptDistracted,
'three': AudibleAlert.warningImmediate,
}
Expand Down
43 changes: 43 additions & 0 deletions selfdrive/ui/mici/onroad/sound_debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pyray as rl
from openpilot.common.params import Params
from openpilot.system.ui.lib.application import gui_app, FontWeight
from openpilot.system.ui.lib.text_measure import measure_text_cached
from openpilot.system.ui.widgets import Widget
from openpilot.selfdrive.ui.ui_state import ui_state


class SoundDebug(Widget):
def __init__(self):
super().__init__()
self._params = Params()
self._enabled = self._params.get_bool("ShowSoundDebug")
self._font = gui_app.font(FontWeight.MEDIUM)

def _render(self, rect):
if gui_app.frame % 30 == 0:
self._enabled = self._params.get_bool("ShowSoundDebug")
if not self._enabled:
return

sd = ui_state.sm["soundDebug"]
alert = str(sd.alert).split(".")[-1]
rows = [
("volume", f"{sd.volume * 100:.0f}%"),
("ambient", f"{sd.ambientDb:.1f} dB"),
("mic raw", f"{sd.rawDb:.1f} dB"),
("alert", alert),
]
fs, pad, gap, lh = 32, 14, 24, 40

label_w = max(measure_text_cached(self._font, lbl, fs).x for lbl, _ in rows)
value_w = max(measure_text_cached(self._font, val, fs).x for _, val in rows)
w = 2 * pad + label_w + gap + value_w
h = 2 * pad + lh * len(rows)
x0, y0 = rect.x + rect.width - w - 6, rect.y + 6

rl.draw_rectangle_rounded(rl.Rectangle(x0, y0, w, h), 0.12, 10, rl.Color(0, 0, 0, 210))
for i, (label, value) in enumerate(rows):
y = y0 + pad + lh * i
rl.draw_text_ex(self._font, label, rl.Vector2(x0 + pad, y), fs, 0, rl.Color(170, 170, 170, 255))
vx = x0 + w - pad - measure_text_cached(self._font, value, fs).x
rl.draw_text_ex(self._font, value, rl.Vector2(vx, y), fs, 0, rl.WHITE)
Loading
Loading