soundd: configure as persistent process (#22878)

* soundd: configure as persistent process

* update c2 test

* fix that

* little more

Co-authored-by: Comma Device <device@comma.ai>
pull/22752/head
Adeeb Shihadeh 4 years ago committed by GitHub
parent bcd4a46814
commit ed8e6f857c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      selfdrive/debug/cycle_alerts.py
  2. 2
      selfdrive/manager/process_config.py
  3. 18
      selfdrive/ui/soundd/sound.cc
  4. 1
      selfdrive/ui/soundd/sound.h
  5. 6
      selfdrive/ui/tests/test_soundd.py
  6. 2
      selfdrive/ui/ui.h

@ -17,8 +17,8 @@ def cycle_alerts(duration=2000, is_metric=False):
alerts = list(EVENTS.keys()) alerts = list(EVENTS.keys())
print(alerts) print(alerts)
#alerts = [EventName.preDriverDistracted, EventName.promptDriverDistracted, EventName.driverDistracted] alerts = [EventName.preDriverDistracted, EventName.promptDriverDistracted, EventName.driverDistracted]
alerts = [EventName.preLaneChangeLeft, EventName.preLaneChangeRight] #alerts = [EventName.preLaneChangeLeft, EventName.preLaneChangeRight]
CP = CarInterface.get_params("HONDA CIVIC 2016") CP = CarInterface.get_params("HONDA CIVIC 2016")
sm = messaging.SubMaster(['deviceState', 'pandaStates', 'roadCameraState', 'modelV2', 'liveCalibration', sm = messaging.SubMaster(['deviceState', 'pandaStates', 'roadCameraState', 'modelV2', 'liveCalibration',

@ -19,7 +19,7 @@ procs = [
NativeProcess("sensord", "selfdrive/sensord", ["./sensord"], enabled=not PC, persistent=EON, sigkill=EON), NativeProcess("sensord", "selfdrive/sensord", ["./sensord"], enabled=not PC, persistent=EON, sigkill=EON),
NativeProcess("ubloxd", "selfdrive/locationd", ["./ubloxd"], enabled=(not PC or WEBCAM)), 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("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("locationd", "selfdrive/locationd", ["./locationd"]),
NativeProcess("boardd", "selfdrive/boardd", ["./boardd"], enabled=False), NativeProcess("boardd", "selfdrive/boardd", ["./boardd"], enabled=False),
PythonProcess("calibrationd", "selfdrive.locationd.calibrationd"), PythonProcess("calibrationd", "selfdrive.locationd.calibrationd"),

@ -6,7 +6,7 @@
// TODO: detect when we can't play sounds // TODO: detect when we can't play sounds
// TODO: detect when we can't display the UI // 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/"; const QString sound_asset_path = Hardware::TICI() ? "../../assets/sounds_tici/" : "../../assets/sounds/";
for (auto &[alert, fn, loops] : sound_list) { for (auto &[alert, fn, loops] : sound_list) {
QSoundEffect *s = new QSoundEffect(this); QSoundEffect *s = new QSoundEffect(this);
@ -24,8 +24,22 @@ Sound::Sound(QObject *parent) : sm({"carState", "controlsState"}) {
}; };
void Sound::update() { void Sound::update() {
const bool started_prev = sm["deviceState"].getDeviceState().getStarted();
sm.update(0); 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 // scale volume with speed
if (sm.updated("carState")) { if (sm.updated("carState")) {
float volume = util::map_val(sm["carState"].getCarState().getVEgo(), 0.f, 20.f, 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) { void Sound::setAlert(const Alert &alert) {

@ -28,4 +28,5 @@ protected:
Alert current_alert = {}; Alert current_alert = {};
QMap<AudibleAlert, QPair<QSoundEffect *, int>> sounds; QMap<AudibleAlert, QPair<QSoundEffect *, int>> sounds;
SubMaster sm; SubMaster sm;
uint64_t started_frame;
}; };

@ -37,7 +37,7 @@ class TestSoundd(unittest.TestCase):
@phone_only @phone_only
@with_processes(['soundd']) @with_processes(['soundd'])
def test_alert_sounds(self): def test_alert_sounds(self):
pm = messaging.PubMaster(['controlsState']) pm = messaging.PubMaster(['deviceState', 'controlsState'])
# make sure they're all defined # make sure they're all defined
alert_sounds = {v: k for k, v in car.CarControl.HUDControl.AudibleAlert.schema.enumerants.items()} 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() start_writes = get_total_writes()
for _ in range(int(9 / DT_CTRL)): 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 = messaging.new_message('controlsState')
msg.controlsState.alertSound = sound msg.controlsState.alertSound = sound
msg.controlsState.alertType = str(sound) msg.controlsState.alertType = str(sound)

@ -57,7 +57,7 @@ struct Alert {
cereal::ControlsState::AlertSize size; cereal::ControlsState::AlertSize size;
AudibleAlert sound; AudibleAlert sound;
bool equal(const Alert &a2) { 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) { static Alert get(const SubMaster &sm, uint64_t started_frame) {

Loading…
Cancel
Save