MOSS: a small, mostly 3D-printed litter-picking rover. Cleaner streets, one maker at a time.
Python
sounds: PulseAudio first (the Bluetooth speaker is a PulseAudio sink on the Jetson), MOSS_SOUND_BACKEND; cockpit service template exports the user's XDG_RUNTIME_DIR so a stack launched from the cockpit reaches the audio session
metroxc406777264d1
diff --git a/docs/cockpit.md b/docs/cockpit.mdindex 3e07a49..303ae62 100644--- a/docs/cockpit.md+++ b/docs/cockpit.md@@ -282,7 +282,7 @@ absolute path of this checkout (with its `.venv`). From the root of thecheckout:```-$ sed -e "s|MOSS_USER|$USER|g" -e "s|MOSS_DIR|$PWD|g" tools/moss-cockpit.service \+$ sed -e "s|MOSS_USER|$USER|g" -e "s|MOSS_DIR|$PWD|g" -e "s|MOSS_UID|$(id -u)|g" tools/moss-cockpit.service \| sudo tee /etc/systemd/system/moss-cockpit.service >/dev/null$ sudo systemctl daemon-reload && sudo systemctl enable moss-cockpit && sudo systemctl restart moss-cockpit```diff --git a/moss_dimos/sounds.py b/moss_dimos/sounds.pyindex 444ab16..6203e5b 100644--- a/moss_dimos/sounds.py+++ b/moss_dimos/sounds.py@@ -20,7 +20,8 @@ twice in a row within an event's cooldown, and nothing plays while muted.Environment: MOSS_SOUNDS (on by default; 0 = the blueprint leaves the moduleout), MOSS_SOUND_VOLUME (0..1, default from assets/sounds/config.json),MOSS_SOUND_SINK (a PulseAudio sink name or index; default = the session's-default sink, which is the Bluetooth speaker once it is connected).+default sink, which is the Bluetooth speaker once it is connected),+MOSS_SOUND_BACKEND (paplay or pw-play; default: paplay when present).The player needs the user's audio session: a stack launched from a loginshell or over ssh as the robot's user finds it (XDG_RUNTIME_DIR); a system@@ -47,7 +48,8 @@ from moss_dimos import robot_profilelogger = setup_logger()ASSETS_DIR = Path(__file__).resolve().parent.parent / "assets" / "sounds"-BACKENDS = ("pw-play", "paplay")+BACKENDS = ("paplay", "pw-play") # PulseAudio first: on the Jetson the Bluetooth speaker is a PulseAudio sink (module-bluez5),+ # PipeWire there has no Bluetooth; MOSS_SOUND_BACKEND forces one of the twoBATTERY_LOW_MV = 11000 # 3S pack: low below this at rest...BATTERY_LOW_CLEAR_MV = 11300 # ...and back to normal above this (hysteresis: a sag under load does not toggle it)BATTERY_CRITICAL_MV = 10600 # the flight check refuses below 10.8 V; critical is lower still@@ -68,8 +70,12 @@ def sound_volume(default: float, env: dict | None = None) -> float:return max(0.0, min(1.0, v))-def playback_backend() -> str | None:- """The first playback command on the PATH, None when there is none."""+def playback_backend(env: dict | None = None) -> str | None:+ """The playback command: MOSS_SOUND_BACKEND when set and on the PATH, else the+ first of BACKENDS on the PATH, None when there is none."""+ forced = (env if env is not None else os.environ).get("MOSS_SOUND_BACKEND", "").strip()+ if forced:+ return forced if forced in BACKENDS and shutil.which(forced) else Nonefor name in BACKENDS:if shutil.which(name):return namediff --git a/tools/moss-cockpit.service b/tools/moss-cockpit.serviceindex 59ac4bd..83e8a77 100644--- a/tools/moss-cockpit.service+++ b/tools/moss-cockpit.service@@ -1,7 +1,7 @@# MOSS cockpit server: the bus tap and the page on :8904 (docs/cockpit.md).-# A template: MOSS_USER is the account that runs the rover's stack, MOSS_DIR the+# A template: MOSS_USER is the account that runs the rover's stack, MOSS_UID its uid, MOSS_DIR the# absolute path of this checkout (with its .venv). Install from the checkout:-# sed -e "s|MOSS_USER|$USER|g" -e "s|MOSS_DIR|$PWD|g" tools/moss-cockpit.service \+# sed -e "s|MOSS_USER|$USER|g" -e "s|MOSS_DIR|$PWD|g" -e "s|MOSS_UID|$(id -u)|g" tools/moss-cockpit.service \# | sudo tee /etc/systemd/system/moss-cockpit.service >/dev/null# sudo systemctl daemon-reload && sudo systemctl enable moss-cockpit && sudo systemctl restart moss-cockpit# `restart`, not `enable --now`: a cockpit already running (an older install, or@@ -24,6 +24,9 @@ User=MOSS_USERWorkingDirectory=MOSS_DIREnvironment=GLIBC_TUNABLES=glibc.rtld.optional_static_tls=4194304Environment=MOSS_COCKPIT_PORT=8904+# the robot user's audio session (PulseAudio / PipeWire sockets): a stack launched from this+# service plays the sound pack through it; without it the rover stays silent from the cockpit+Environment=XDG_RUNTIME_DIR=/run/user/MOSS_UIDExecStart=MOSS_DIR/.venv/bin/python tools/moss_cockpit.pyRestart=alwaysRestartSec=3