diff --git a/selfdrive/debug/cycle_alerts.py b/selfdrive/debug/cycle_alerts.py index 47a37933c1..9e9924efc6 100755 --- a/selfdrive/debug/cycle_alerts.py +++ b/selfdrive/debug/cycle_alerts.py @@ -17,8 +17,8 @@ def cycle_alerts(duration=2000, is_metric=False): alerts = list(EVENTS.keys()) print(alerts) - #alerts = [EventName.preDriverDistracted, EventName.promptDriverDistracted, EventName.driverDistracted] - alerts = [EventName.preLaneChangeLeft, EventName.preLaneChangeRight] + alerts = [EventName.preDriverDistracted, EventName.promptDriverDistracted, EventName.driverDistracted] + #alerts = [EventName.preLaneChangeLeft, EventName.preLaneChangeRight] CP = CarInterface.get_params("HONDA CIVIC 2016") sm = messaging.SubMaster(['deviceState', 'pandaStates', 'roadCameraState', 'modelV2', 'liveCalibration', diff --git a/selfdrive/manager/process_config.py b/selfdrive/manager/process_config.py index 8fc07a06ef..2e3741350e 100644 --- a/selfdrive/manager/process_config.py +++ b/selfdrive/manager/process_config.py @@ -19,7 +19,7 @@ procs = [ NativeProcess("sensord", "selfdrive/sensord", ["./sensord"], enabled=not PC, persistent=EON, sigkill=EON), NativeProcess("ubloxd", "selfdrive/locationd", ["./ubloxd"], enabled=(not PC or WEBCAM)), NativeProcess("ui", "selfdrive/ui", ["./ui"], persistent=True, watchdog_max_dt=(5 if TICI else None)), - NativeProcess("soundd", "selfdrive/ui/soundd", ["./soundd"]), + NativeProcess("soundd", "selfdrive/ui/soundd", ["./soundd"], persistent=True), NativeProcess("locationd", "selfdrive/locationd", ["./locationd"]), NativeProcess("boardd", "selfdrive/boardd", ["./boardd"], enabled=False), PythonProcess("calibrationd", "selfdrive.locationd.calibrationd"), diff --git a/selfdrive/ui/soundd/sound.cc b/selfdrive/ui/soundd/sound.cc index d004d0dd2e..df8b4fa6ac 100644 --- a/selfdrive/ui/soundd/sound.cc +++ b/selfdrive/ui/soundd/sound.cc @@ -6,7 +6,7 @@ // TODO: detect when we can't play sounds // TODO: detect when we can't display the UI -Sound::Sound(QObject *parent) : sm({"carState", "controlsState"}) { +Sound::Sound(QObject *parent) : sm({"carState", "controlsState", "deviceState"}) { const QString sound_asset_path = Hardware::TICI() ? "../../assets/sounds_tici/" : "../../assets/sounds/"; for (auto &[alert, fn, loops] : sound_list) { QSoundEffect *s = new QSoundEffect(this); @@ -24,8 +24,22 @@ Sound::Sound(QObject *parent) : sm({"carState", "controlsState"}) { }; void Sound::update() { + const bool started_prev = sm["deviceState"].getDeviceState().getStarted(); sm.update(0); + const bool started = sm["deviceState"].getDeviceState().getStarted(); + if (started && !started_prev) { + started_frame = sm.frame; + } + + // no sounds while offroad + // also no sounds if nothing is alive in case thermald crashes while offroad + const bool crashed = (sm.frame - std::max(sm.rcv_frame("deviceState"), sm.rcv_frame("controlsState"))) > 10*UI_FREQ; + if (!started || crashed) { + setAlert({}); + return; + } + // scale volume with speed if (sm.updated("carState")) { float volume = util::map_val(sm["carState"].getCarState().getVEgo(), 0.f, 20.f, @@ -35,7 +49,7 @@ void Sound::update() { } } - setAlert(Alert::get(sm, 1)); + setAlert(Alert::get(sm, started_frame)); } void Sound::setAlert(const Alert &alert) { diff --git a/selfdrive/ui/soundd/sound.h b/selfdrive/ui/soundd/sound.h index e9f186de5d..cbc7b87078 100644 --- a/selfdrive/ui/soundd/sound.h +++ b/selfdrive/ui/soundd/sound.h @@ -28,4 +28,5 @@ protected: Alert current_alert = {}; QMap> sounds; SubMaster sm; + uint64_t started_frame; }; diff --git a/selfdrive/ui/tests/test_soundd.py b/selfdrive/ui/tests/test_soundd.py index ad07f86303..98f17d620f 100755 --- a/selfdrive/ui/tests/test_soundd.py +++ b/selfdrive/ui/tests/test_soundd.py @@ -37,7 +37,7 @@ class TestSoundd(unittest.TestCase): @phone_only @with_processes(['soundd']) def test_alert_sounds(self): - pm = messaging.PubMaster(['controlsState']) + pm = messaging.PubMaster(['deviceState', 'controlsState']) # make sure they're all defined alert_sounds = {v: k for k, v in car.CarControl.HUDControl.AudibleAlert.schema.enumerants.items()} @@ -52,6 +52,10 @@ class TestSoundd(unittest.TestCase): start_writes = get_total_writes() for _ in range(int(9 / DT_CTRL)): + msg = messaging.new_message('deviceState') + msg.deviceState.started = True + pm.send('deviceState', msg) + msg = messaging.new_message('controlsState') msg.controlsState.alertSound = sound msg.controlsState.alertType = str(sound) diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 611af54877..4fcc137df7 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -57,7 +57,7 @@ struct Alert { cereal::ControlsState::AlertSize size; AudibleAlert sound; bool equal(const Alert &a2) { - return text1 == a2.text1 && text2 == a2.text2 && type == a2.type; + return text1 == a2.text1 && text2 == a2.text2 && type == a2.type && sound == a2.sound; } static Alert get(const SubMaster &sm, uint64_t started_frame) {