MOSS: a small, mostly 3D-printed litter-picking rover. Cleaner streets, one maker at a time.
Python
firmware: MDD10A build drives the left track without the drive inversion (kept for its encoder); speed profile: --metres stop and distance by the encoders
metrox92688989913f
diff --git a/firmware/MOSS_QTPY_MDD3A/MOSS_QTPY_MDD3A.ino b/firmware/MOSS_QTPY_MDD3A/MOSS_QTPY_MDD3A.inoindex 95aeef0..b99d6dd 100644--- a/firmware/MOSS_QTPY_MDD3A/MOSS_QTPY_MDD3A.ino+++ b/firmware/MOSS_QTPY_MDD3A/MOSS_QTPY_MDD3A.ino@@ -22,11 +22,21 @@ constexpr int ENC_L_A = SDA, ENC_L_B = SCL; // GPIO 7 / 6 (primary I2C pins reconstexpr int ENC_R_A = TX, ENC_R_B = RX; // GPIO 5 / 16// INA219 on the STEMMA QT connector = Wire1 (SDA1 = GPIO 41, SCL1 = GPIO 40)constexpr uint8_t INA_ADDRESS = 0x40;-constexpr bool INVERT_LEFT = true, INVERT_RIGHT = false; // the left track runs backwards without it; its encoder ticks are inverted with it+// The left motor is mounted mirrored: its encoder counts down when the track runs forward, so its+// ticks are always inverted. Its DRIVE inversion depends on the driver: on the MDD3A (two PWM pins)+// the left track ran backwards without it; on the MDD10A (PWM + DIR) the same wiring runs forward+// on DIR low, and keeping the inversion made the rover pivot counter-clockwise (measured on the+// first run with the 10 A driver: left -9031 ticks, right +7552, then straight once removed).+constexpr bool INVERT_LEFT_TICKS = true, INVERT_RIGHT = false;+#ifdef MOSS_DRIVER_MDD10A+constexpr bool INVERT_LEFT_DRIVE = false;+#else+constexpr bool INVERT_LEFT_DRIVE = true;+#endifconstexpr float SHUNT_OHMS = 0.0f; // voltage only (see V0.3 README)constexpr uint32_t PWM_HZ = 20000;constexpr int PWM_BITS = 10;-constexpr const char* FW = "qtpy-mdd3a-v3";+constexpr const char* FW = "qtpy-mdd3a-v4";moss::Control control;moss::Ramp rampL, rampR;@@ -43,7 +53,7 @@ void ARDUINO_ISR_ATTR encoderLeft() {portENTER_CRITICAL_ISR(&encoderMux);uint8_t next = (gpio_get_level((gpio_num_t)ENC_L_A) << 1) | gpio_get_level((gpio_num_t)ENC_L_B);if ((prevL ^ next) == 3) badL = badL + 1;- ticksL += INVERT_LEFT ? -quadrature[(prevL << 2) | next] : quadrature[(prevL << 2) | next]; prevL = next;+ ticksL += INVERT_LEFT_TICKS ? -quadrature[(prevL << 2) | next] : quadrature[(prevL << 2) | next]; prevL = next;portEXIT_CRITICAL_ISR(&encoderMux);}void ARDUINO_ISR_ATTR encoderRight() {@@ -197,7 +207,7 @@ void loop() {now = millis();if (control.poll(now)) outputsZero();if (pwmOK && (control.mode == moss::DRIVE || control.mode == moss::TEST)) {- motorWrite(M1A, M1B, rampL.tick(control.left, now, control.rampRiseMs, control.rampFallMs), INVERT_LEFT);+ motorWrite(M1A, M1B, rampL.tick(control.left, now, control.rampRiseMs, control.rampFallMs), INVERT_LEFT_DRIVE);motorWrite(M2A, M2B, rampR.tick(control.right, now, control.rampRiseMs, control.rampFallMs), INVERT_RIGHT);}if (uint32_t(now - lastTelemetry) >= 200) {diff --git a/firmware/README.md b/firmware/README.mdindex d4e3d0d..7e54358 100644--- a/firmware/README.md+++ b/firmware/README.md@@ -1,6 +1,6 @@# MOSS motor firmware-**Current: [`MOSS_QTPY_MDD3A/`](MOSS_QTPY_MDD3A/)**, QT Py ESP32-S3 on its screw-terminal carrier, native USB, limit 100 % since the first drive on the floor (10 October 2026), `ramp` command, one build per driver (Cytron MDD3A by default, `-DMOSS_DRIVER_MDD10A` for the MDD10A, see its `bench/README.md`). Host test: `tests/control_v04_test.cpp`.+**Current: [`MOSS_QTPY_MDD3A/`](MOSS_QTPY_MDD3A/)** (`qtpy-mdd3a-v4`; the MDD10A build, `-DMOSS_DRIVER_MDD10A`, drives the left track without the drive inversion the MDD3A needed and keeps its encoder inversion: measured straight, 1.065 m by tape for 1.066 m by the encoders, 5 s at 100 %), QT Py ESP32-S3 on its screw-terminal carrier, native USB, limit 100 % since the first drive on the floor (10 October 2026), `ramp` command, one build per driver (Cytron MDD3A by default, `-DMOSS_DRIVER_MDD10A` for the MDD10A, see its `bench/README.md`). Host test: `tests/control_v04_test.cpp`.The rest of this page is the V0.3 bench firmware on the DevKitC, kept as history.diff --git a/tools/moss_speed_profile.py b/tools/moss_speed_profile.pyindex c263a35..b470163 100755--- a/tools/moss_speed_profile.py+++ b/tools/moss_speed_profile.py@@ -28,11 +28,14 @@ def main() -> int:ap.add_argument("--pct", type=int, default=100)ap.add_argument("--seconds", type=float, default=5.0)ap.add_argument("--pivot", action="store_true")+ ap.add_argument("--metres", type=float, default=None,+ help="stop once the mean encoder travel reaches this distance (ticks_per_m of the profile); --seconds stays the cap")ap.add_argument("--port", default=None)ap.add_argument("--go", action="store_true")a = ap.parse_args()if not a.go:- print(f"plan: {'pivot' if a.pivot else 'straight'} at {a.pct} % for {a.seconds:.1f} s; nothing moves without --go")+ print(f"plan: {'pivot' if a.pivot else 'straight'} at {a.pct} % for {a.seconds:.1f} s"+ + (f" or {a.metres:.2f} m" if a.metres else "") + "; nothing moves without --go")return 0os.environ["MOSS_PIVOT_PCT"] = "0"os.environ["MOSS_BUS_REF_MV"] = "0"@@ -55,6 +58,8 @@ def main() -> int:twist = [0.0, 0.0, a.pct / 100.0 / (adapter._geometry.track_m / 2.0)] if a.pivot else [a.pct / 100.0, 0.0, 0.0]t0 = time.monotonic()last = None+ target = a.metres * adapter._geometry.ticks_per_m if a.metres else None+ base = Nonewhile time.monotonic() - t0 < a.seconds:adapter.write_velocities(twist)time.sleep(KEEPALIVE_S)@@ -64,6 +69,11 @@ def main() -> int:if last is None or row[1:3] != last[1:3]:samples.append(row)last = row+ if target is not None:+ if base is None:+ base = (row[1], row[2])+ elif (abs(row[1] - base[0]) + abs(row[2] - base[1])) / 2.0 >= target:+ breakadapter.write_stop()t_stop = time.monotonic()while time.monotonic() - t_stop < 1.5:@@ -99,7 +109,10 @@ def main() -> int:top = max((max(lr, rr) for _, lr, rr in rates), default=0.0)t90 = next((t for t, lr, rr in rates if max(lr, rr) >= 0.9 * top), None)tot_l, tot_r = samples[-1][1] - l0, samples[-1][2] - r0- print(f"total {tot_l} / {tot_r} ticks in {a.seconds:.1f} s at {a.pct} %; top rate {top:.0f} ticks/s"+ tpm = adapter._geometry.ticks_per_m or 0+ if tpm:+ print(f"distance by the encoders: {(abs(tot_l) + abs(tot_r)) / 2.0 / tpm:.3f} m (mean of both tracks at {tpm:.0f} ticks/m, coast after the stop included)")+ print(f"total {tot_l} / {tot_r} ticks in {samples[-1][0]:.1f} s at {a.pct} %; top rate {top:.0f} ticks/s"+ (f", reached 90 % of it at {t90:.1f} s" if t90 is not None else ""))return 0