MOSS: a small, mostly 3D-printed litter-picking rover. Cleaner streets, one maker at a time.
Python
teleop at boot: tools/moss-teleop.service runs tools/moss-teleop-boot.sh, which retries the launcher until the pad and the board are there, then leaves the stack running
metrox836495026090
diff --git a/Software.md b/Software.mdindex cd3d3fd..3523649 100644--- a/Software.md+++ b/Software.md@@ -72,7 +72,7 @@ MOCK=1 tools/moss-fly.sh map # fake motor board, no motor; the lidar mutools/moss-teleop.sh # the pad only: gates, then moss-gamepad```-Pad on the dimOS path: left stick forward and back, right stick to turn, R2 boost; centre the sticks and the tracks stop. No deadman by default (`MOSS_PAD_DEADMAN=r1` in `robot.env` brings the held R1 back).+Pad on the dimOS path: left stick forward and back, right stick to turn, R2 boost; centre the sticks and the tracks stop. To drive as soon as the rover is powered, install `tools/moss-teleop.service` (its header has the three lines): it retries the launcher at boot until the pad and the board are there. No deadman by default (`MOSS_PAD_DEADMAN=r1` in `robot.env` brings the held R1 back).Every gate refuses rather than guesses, with the fix on the same line: a stack already up, a missing board, a port held by another program, a mute firmware, a battery at the BMS floor, a lidar that does not spin. Nothing moves by itself: in `map` only the pad drives; in `explore` the planner moves on a goal or once exploration is armed. The firmware stops the tracks 300 ms after the last command, whatever happens above it.diff --git a/tools/moss-teleop-boot.sh b/tools/moss-teleop-boot.shnew file mode 100755index 0000000..d33152d--- /dev/null+++ b/tools/moss-teleop-boot.sh@@ -0,0 +1,30 @@+#!/usr/bin/env bash+# MOSS drives from the pad as soon as the rover is powered: tools/moss-teleop.service runs+# this at boot. It runs tools/moss-teleop.sh and retries until its gates pass - at boot the+# receiver may enumerate after the first try, the pad may be switched on later, the motor+# board may still be starting. A dimOS stack already up (the cockpit's, or a previous try)+# counts as done. Once a stack is up this exits: a stack stopped by hand (tools/moss-teleop.sh+# stop) stays stopped until the next boot, so benches and the cockpit's own launches keep+# the rover to themselves.+#+# tools/moss-teleop-boot.sh retry every 15 s (MOSS_TELEOP_BOOT_RETRY_S)+# journalctl -u moss-teleop -b what each try said+# sudo systemctl disable --now moss-teleop no more teleop at boot+set -u+cd "$(dirname "$0")/.." || exit 1+STACK_RE='[b]in/dimos( [^ ]+)* run( |$)' # the same pattern as tools/moss-fly.sh and the cockpit+EVERY="${MOSS_TELEOP_BOOT_RETRY_S:-15}"+n=0+while :; do+ n=$((n + 1))+ if pgrep -f "$STACK_RE" >/dev/null; then+ echo "try $n: a dimOS stack is already up - done"+ exit 0+ fi+ echo "=== try $n $(date '+%H:%M:%S') ==="+ if tools/moss-teleop.sh; then+ echo "try $n: YOU CAN DRIVE"+ exit 0+ fi+ sleep "$EVERY"+donediff --git a/tools/moss-teleop.service b/tools/moss-teleop.servicenew file mode 100644index 0000000..711cb6c--- /dev/null+++ b/tools/moss-teleop.service@@ -0,0 +1,29 @@+# MOSS teleop at boot: the pad drives as soon as the rover is powered (tools/moss-teleop-boot.sh+# retries tools/moss-teleop.sh until its gates pass, then leaves the stack running).+# A template, like tools/moss-cockpit.service: MOSS_USER is the account that runs the rover's+# stack, 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-teleop.service \+# | sudo tee /etc/systemd/system/moss-teleop.service >/dev/null+# sudo systemctl daemon-reload && sudo systemctl enable moss-teleop+# Off again: sudo systemctl disable --now moss-teleop (the stack itself: tools/moss-teleop.sh stop).+# No NoNewPrivileges on purpose: dimOS sets loopback multicast and the socket buffers with sudo+# at launch (or tools/lcm-loopback.service does it at boot, ordered before this unit).+[Unit]+Description=MOSS teleop at boot: the pad drives as soon as the rover is powered+Wants=lcm-loopback.service+After=network.target lcm-loopback.service moss-cockpit.service++[Service]+Type=oneshot+RemainAfterExit=yes+User=MOSS_USER+WorkingDirectory=MOSS_DIR+Environment=GLIBC_TUNABLES=glibc.rtld.optional_static_tls=4194304+ExecStart=MOSS_DIR/tools/moss-teleop-boot.sh+# The dimOS daemon the launcher starts lives in this unit's cgroup: a stop or restart of this+# unit ends the retry loop only, never the stack (tools/moss-teleop.sh stop does that).+KillMode=process+LimitSTACK=8M++[Install]+WantedBy=multi-user.target