mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-21 08:14:00 +08:00
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> old-commit-hash: ed8e6f857ca45a1d814dd9a98ddf5c40c6d08c20
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -28,4 +28,5 @@ protected:
|
||||
Alert current_alert = {};
|
||||
QMap<AudibleAlert, QPair<QSoundEffect *, int>> sounds;
|
||||
SubMaster sm;
|
||||
uint64_t started_frame;
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
|
||||
+1
-1
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user