MOSS: a small, mostly 3D-printed litter-picking rover. Cleaner streets, one maker at a time.
Python
stall guard: a stall is every commanded track frozen; one track frozen while the other turns (an arc's inner track under its floor, a pivot with one dead track) is not a contact
metrox93019d19507c
diff --git a/benches/bench_moss_adapter_cold.py b/benches/bench_moss_adapter_cold.pyindex 6bb75c5..3805654 100644--- a/benches/bench_moss_adapter_cold.py+++ b/benches/bench_moss_adapter_cold.py@@ -510,6 +510,26 @@ class Turning(FakeMossFirmware):if self.mode == DRIVE:self.ticks[0] += 80; self.ticks[1] += 80return super()._telemetry_line()+++# one track frozen while the other turns: an arc's inner track under its floor, not a stall+class OneSided(FakeMossFirmware):+ def _telemetry_line(self):+ if self.mode == DRIVE:+ self.ticks[1] += 80+ return super()._telemetry_line()+++fw11 = OneSided(auto_time=True)+f11 = lambda: fw11 # noqa: E731+f11.is_mock = True+sc = MossBaseAdapter(dof=3, port_factory=f11, geometry=MossGeometry(track_m=0.30, mps_at_limit=0.15, max_pct=100, min_pct=0))+check(sc.connect() and sc.write_enable(True), "a fake with only the right encoder turning")+t_start = time.monotonic()+while time.monotonic() - t_start < STALL_S + 0.6:+ sc.write_velocities([0.06, 0.0, 0.1]); settle(0.1)+check(not sc.stalled and sc.stall_count == 0 and fw11.mode == DRIVE, f"one track frozen, the other turning: not a stall (count {sc.stall_count}, mode {fw11.mode})")+sc.write_stop(); sc.disconnect()fw10 = Turning(auto_time=True)f10 = lambda: fw10 # noqa: E731f10.is_mock = Truediff --git a/moss_dimos/moss_adapter.py b/moss_dimos/moss_adapter.pyindex cf29eb9..480767b 100644--- a/moss_dimos/moss_adapter.py+++ b/moss_dimos/moss_adapter.py@@ -103,8 +103,8 @@ REPLY_TIMEOUT_S = 0.150 # the firmware answers within a loop tick (ms)CONNECT_PROBE_S = 1.000 # the first "status" of a process: reader thread start + first parse on a Jetson take longer than a reply tickTELEMETRY_FRESH_S = 1.0 # mode read from telemetry older than this = unknownMOCK_BUS_ENV = "MOSS_MOCK_BUS"-STALL_S = 1.0 # a track commanded for this long whose encoder did not move is STALLED: the- # rover is pushing against something (no bumper on MOSS: the encoders are the bumper)+STALL_S = 1.0 # every commanded track frozen for this long = STALLED: the rover is pushing against+ # something (no bumper on MOSS: the encoders are the bumper)STALL_MIN_TICKS = 20 # ticks over STALL_S that count as motion (a track at 40 % makes ~800 per second)STALL_WINDOW_S = 2.0 # how long the tick history is kept for the comparisonPULSE_MS_DEFAULT = 0 # MOSS_PULSE_MS: period of the full-duty time slicing, 0 = off (then MOSS_MIN_PCT applies).@@ -701,7 +701,12 @@ class MossBaseAdapter:want_l, want_r = self._wantstalled_l = want_l != 0 and abs(l_new - l_old) < STALL_MIN_TICKSstalled_r = want_r != 0 and abs(r_new - r_old) < STALL_MIN_TICKS- if not (stalled_l or stalled_r):+ commanded = [stalled for want, stalled in ((want_l, stalled_l), (want_r, stalled_r)) if want != 0]+ # a stall is the rover pushing against something: EVERY commanded track frozen. One+ # track frozen while the other turns is an arc whose inner track sits under its+ # friction floor, or a tread dragging on a step: the rover still moves, the planner's+ # own stuck detection owns that case, and a false bump would back it off for nothing.+ if not commanded or not all(commanded):return Falseself._send("stop")self._stall_count += 1