MOSS: a small, mostly 3D-printed litter-picking rover. Cleaner streets, one maker at a time.
Python
base adapter: MOSS_TRACK_SIGN, the track polarity on the wire and on the raw ticks (the twist path drove the rover backwards; the pad had been inverted instead); bench 200
metroxeb873ecd3d4b
diff --git a/benches/bench_moss_adapter_cold.py b/benches/bench_moss_adapter_cold.pyindex 07cb012..77890e5 100644--- a/benches/bench_moss_adapter_cold.py+++ b/benches/bench_moss_adapter_cold.py@@ -758,6 +758,36 @@ finally:os.environ.pop("MOSS_PULSE_MS", None)os.environ.pop("MOSS_BUS_REF_MV", None)+# ── track polarity: MOSS_TRACK_SIGN=-1 (the firmware's positive drives the rover backwards) ──+print("T. MOSS_TRACK_SIGN=-1: the wire and the raw ticks flip, the commander's convention does not")+os.environ["MOSS_TRACK_SIGN"] = "-1"+fwT = FakeMossFirmware()+fT = lambda: fwT+fT.is_mock = True+GT = MossGeometry(track_m=0.30, mps_at_limit=0.15, max_pct=25, ticks_per_m=10000.0, min_pct=0)+aT = MossBaseAdapter(dof=3, port_factory=fT, geometry=GT)+os.environ.pop("MOSS_TRACK_SIGN", None)+check(aT.connect() is True and aT.write_enable(True) is True, "sign -1: connect and arm")+check(aT.write_velocities([0.15, 0.0, 0.0]) is True and (fwT.left, fwT.right) == (-25, -25),+ f"sign -1: a forward twist goes on the wire as drive -25 -25 (got {fwT.left} {fwT.right})")+check(aT.target_pct == (-25, -25), f"sign -1: target_pct is the wire pair (-25, -25): {aT.target_pct}")+check(aT.write_velocities([0.0, 0.0, 1.0]) is True and fwT.left > 0 and fwT.right < 0,+ f"sign -1: a left turn (wz +1) is L={fwT.left} R={fwT.right} on the wire: the pivot flips with the sign")+fwT.ticks = [0, 0]; fwT.emit_telemetry(); settle(0.15)+fwT.ticks = [-1000, -1000]; fwT.emit_telemetry(); settle(0.15)+od = aT.read_odometry()+vel = aT.read_velocities()+check(od is not None and od[0] > 0.05, f"sign -1: raw ticks going negative are the rover going FORWARD: odometry x {od}")+check(vel is not None and vel[0] > 0.0, f"sign -1: the velocity from the encoders is forward too: {vel}")+aT.write_stop(); aT.disconnect()+fwU = FakeMossFirmware()+fU = lambda: fwU+fU.is_mock = True+aU = MossBaseAdapter(dof=3, port_factory=fU, geometry=GT)+check(aU.connect() is True and aU.write_enable(True) is True and aU.write_velocities([0.15, 0.0, 0.0]) is True+ and (fwU.left, fwU.right) == (25, 25), "no MOSS_TRACK_SIGN: the wire is drive 25 25 as before")+aU.write_stop(); aU.disconnect()+print(f"{OK} OK, {KO} KO")print("TEST PASSED" if KO == 0 else "TEST FAILED")sys.exit(1 if KO else 0)diff --git a/docs/base.md b/docs/base.mdindex 308a711..087f307 100644--- a/docs/base.md+++ b/docs/base.md@@ -35,6 +35,12 @@ then silence (`MOSS_BRAKE_S`, 0 to 1.0 s). Unloaded, the motors start betweenadapter delivers every non-zero command as full-duty pulses (`MOSS_PULSE_MS`,see [cockpit.md](cockpit.md)).+`MOSS_TRACK_SIGN=-1` in `robot.env` flips the sign of both tracks on the wire and takes it off the+encoder ticks, for a build whose firmware positive drives the rover backwards: every commander+(the planner, the mission, a script) keeps forward positive, the pad needs no inversion of its+own any more, and the odometry counts forward as positive. Prove it with a tape measure before+setting it: a `vx=+0.1` twist for two seconds must move the rover forward.+This is the dimOS path. The bench tool in `moss_pi/` drives the same firmwarewithout dimOS and reads raw SDL button 4 as its deadman: L1 on an Xbox-layoutpad, not on this one ([Software.md](../Software.md)).diff --git a/moss_dimos/moss_adapter.py b/moss_dimos/moss_adapter.pyindex 916e588..fc1ea1c 100644--- a/moss_dimos/moss_adapter.py+++ b/moss_dimos/moss_adapter.py@@ -60,6 +60,10 @@ Calibration (env, all optional):(default robot_profile.MOSS.track_m, 0.266 CAD, placeholder)MOSS_MPS_AT_LIMIT floor speed in m/s at MOSS_MAX_PCT, measuredMOSS_MAX_PCT percent ceiling, <= the firmware's 100+ MOSS_TRACK_SIGN 1 (default) or -1: the sign put on BOTH tracks on the wire, and taken off the encoder ticks, when the+ firmware's positive drives the rover backwards (measured on the rover: a positive twist reversed it, and the+ pad had been corrected with MOSS_PAD_INVERT_Y instead of the wire). Commands, the floor, the stall guard+ and the odometry all keep the forward-positive convention; only the wire and the raw ticks differ.MOSS_MIN_PCT static-friction floor in percent (0 = off, default 50: measured 40 on a full battery, 10 of margin for the sag): a non-zero track command below it is raised to it, sign kept; an arc is scaled up whole so its curvature survives (floor_tracks)MOSS_BUS_REF_MV the bus voltage the floor and the speeds were measured at (default 12400): every command is scaled by ref/bus so a sagging pack puts the same voltage on the motors (never below 1, at most x1.5, capped at the limit); 0 = offMOSS_ONE_TRACK_PIVOT a pivot whose one track freezes while the other turns is not a contact: that track is braked and the pivot turns on the other, for the rest of the run (default on; 0 = off, such a pivot is a stall)@@ -399,6 +403,7 @@ class MossBaseAdapter:self._hardware_id = hardware_idself._port_factory = port_factoryself._geometry = geometry or MossGeometry.from_env()+ self._track_sign = -1 if _env_float("MOSS_TRACK_SIGN", 1) < 0 else 1 # see MOSS_TRACK_SIGN aboveself._ser = Noneself._mock = Falseself._lock = threading.RLock()@@ -764,7 +769,8 @@ class MossBaseAdapter:then the pulse slice of this tick when pulsing. The commander's pairitself (`_want`) stays as asked: the stall guard and the push comparepercents between themselves, which the gain does not change."""- return self._slice(bus_scaled(want, self._gain(), int(self._geometry.max_pct)))+ l, r = self._slice(bus_scaled(want, self._gain(), int(self._geometry.max_pct)))+ return self._track_sign * l, self._track_sign * rdef _pivot_fallback(self, want: tuple[int, int]) -> tuple[int, int]:"""A pivot whose one track is known not to turn in that direction (it froze@@ -975,7 +981,7 @@ class MossBaseAdapter:returntry:l, r = tel["ticks"]- l, r = int(l), int(r)+ l, r = self._track_sign * int(l), self._track_sign * int(r)except (KeyError, TypeError, ValueError):returnnow = time.monotonic()