Camera-free terrain mapping by feel. (formerly Project NEUMA)
Proprioceptive Terrain Classification and Visionless Mapping via Asymmetric Edge Computing Architectures Using a Rover
Grit is a low-cost, 100% camera-free mobile robotics platform that builds a 2.5D probabilistic elevation and semantic terrain map at 5 cm x 5 cm resolution over a 20 m x 20 m arena (radius > 10 m), using under $30 of compute hardware.
Naming note. Grit was originally called Project NEUMA. Internal identifiers keep the original prefix so they match the code and the flashed firmware:
neuma_daemon,neuma_laptop_suite,neuma_luckfox_daemon, theNEUMA_ROVER_APSSID, theNEUMA_MAPSvolume label,neuma_map_*.plyexports, and/root/neumaon the Luckfox.
It never looks at the world with light. It feels the terrain through the wheels (2 kHz IMU vibration, wheel speed, motor current) and pings the geometry ahead with active ranging (8x8 infrared Time-of-Flight array, ultrasonic backup).
- Why Grit Exists
- At a Glance
- Key Capabilities and Innovations
- System Architecture
- Hardware Overview
- Operating Modes
- ESP32-S3 Real-Time Front-End
- The ESP32 <-> Luckfox UART Protocol
- Proprioceptive Terrain Classification (CNN)
- Visionless 2.5D Mapping
- Luckfox Pico Pro Back-End Daemon
- Storage Architecture
- Timing and Resource Budget
- Repository Structure
- Prerequisites and Workstation Setup
- Building and Flashing the ESP32-S3 Firmware
- ML Training and RV1106 INT8 Quantization Pipeline
- Cross-Compiling and Deploying the Luckfox Daemon
- Visualizing 3D Terrain Maps
- Experimental Rigor and Validation Protocol
- Troubleshooting
- Known Limitations and Roadmap
- License and Academic Context
Most outdoor and indoor mapping robots depend on RGB cameras or scanning LiDAR. Both fail in the same conditions where a robot most needs to know where it is:
| Failure condition | Camera | Scanning LiDAR | Grit |
|---|---|---|---|
| Zero-lux darkness | Blind | Works | Works (no light needed) |
| Dust / fog / smoke | Degraded | Degraded | Short-range IR + ultrasonic backup |
| Featureless corridors | No features | Ambiguous geometry | Proprioceptive pose + ToF height |
| "Will loose sand trap me?" | Cannot know | Cannot know | Learned from wheel vibration + current |
| Wet gravel vs. dry asphalt | Visual guess | Cannot know | Learned from wheel vibration + current |
| Cost of compute + sensing | High | High | Under $30 compute |
The key insight is that terrain traversability is a tactile property, not a visual one. A rover can only truly know that gravel is gravel by driving on it. Grit therefore fuses two complementary information sources into a single, co-registered map:
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ TWO KINDS OF KNOWLEDGE, ONE MAP │
├───────────────────────────────────────┬────────────────────────────────────────────────┤
│ GEOMETRY ("what shape is it?") │ SEMANTICS ("what is it made of?") │
│ │ │
│ Source : 8x8 VL53L8CX ToF (+ US-100) │ Source : IMU vibration + wheel speed + motor │
│ Where : AHEAD of the rover │ current, through a 1xK Conv2d CNN │
│ Method : ray casting + 1D Kalman │ Where : UNDER the wheel tracks │
│ height fusion per cell │ Method : per-cell Bayesian log-odds over │
│ Output : elevation + variance │ tile / asphalt / gravel-sand / │
│ │ grass / lifted │
├───────────────────────────────────────┴────────────────────────────────────────────────┤
│ Both land in the SAME 400 x 400 grid -> .ply (3D) and .csv (tabular) │
└────────────────────────────────────────────────────────────────────────────────────────┘
| Property | Value |
|---|---|
| Sensing philosophy | 100% camera-free; no scanning LiDAR |
| Map type | 2.5D probabilistic elevation + semantic terrain |
| Grid resolution | 5 cm x 5 cm |
| Arena | 20 m x 20 m (radius > 10 m) = 400 x 400 = 160,000 cells |
| Terrain classes | tile, asphalt, gravel/sand, grass, lifted |
| Real-time MCU | ESP32-S3 (N16R8), ESP-IDF v6.1, C++20, FreeRTOS |
| Inference / mapping SoC | Luckfox Pico Pro (Rockchip RV1106), Linux Buildroot, RKNPU2 |
| Inter-chip link | 921,600-baud UART1, COBS framing + CRC-16-CCITT |
| IMU sample rate | 2 kHz (ICM-42688-P) |
| Motor control | 200 Hz closed-loop PID |
| NN input tensor | (1, 5, 1, 256) INT8 |
| NN inference time | ~1 ms per window |
| Compute hardware cost | < $30 |
| Onboard OS storage | 256 MB SPI NAND (vibration-immune) |
| Map export storage | FAT32 microSD, with automatic SPI NAND fallback |
- Co-Registered 2.5D Elevation + Tactile Semantics. Forward-looking 8x8
VL53L8CXToF ray casting (1D Kalman height fusion) is combined with wheel-track Bayesian log-odds terrain classification (tile,asphalt,gravel/sand,grass,lifted) into a single.ply/.csvworld grid. - Asymmetric Dual-Chip Partitioning. Hard real-time 2 kHz acquisition,
esp-dspSIMD filtering, and 200 Hz PID control live on the ESP32-S3. Zero-copy INT8 neural inference (~1 ms/window) and 160,000-cell spatial mapping live on the Luckfox Pico Pro (RV1106). Neither chip does the other's job. - Speed- and Current-Conditioned CNN. Vibration amplitude scales with speed, so a naive classifier confuses "fast on tile" with "slow on gravel". Grit feeds wheel speed and smoothed motor current as extra input channels, so the network can learn the conditional signature:
(ax_hp, ay_hp, az_hp, wheel speed, smoothed motor current). - Vibration-Immune Storage Split. The OS,
neuma_daemon,librknnmrt.so, and.rknnmodel run from soldered 256 MB SPI NAND, which cannot suffer microSD contact bounce on gravel or steps. Map exports go to a replaceable FAT32 microSD, with automatic fallback to SPI NAND. - Zero-Leakage Experimental Rigor. 1-second endpoint trimming, run-ID grouped cross-validation, held-out unseen physical locations, and a lifted-wheel motor-noise baseline.
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ GRIT - PHYSICAL SYSTEM VIEW │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ SENSE (no cameras) COMPUTE PERSIST / OUTPUT │
│ │
│ ┌──────────────────────────┐ ┌────────────────────┐ ┌──────────────────┐ │
│ │ PROPRIOCEPTIVE (body) │ │ ESP32-S3 (N16R8) │ │ 256 MB SPI NAND │ │
│ │ ICM-42688-P IMU 2 kHz ├──►│ real-time │ │ OS + daemon │ │
│ │ Wheel encoders (PCNT) ├──►│ front-end │ │ + .rknn model │ │
│ │ Dual INA226 motor amps ├──►│ │ └────────▲─────────┘ │
│ │ MMC5983MA magnetometer ├──►│ Core 1: hard RT │ │ │
│ └──────────────────────────┘ │ Core 0: comms │ UART1 ┌───────┴──────────┐ │
│ │ │ 921,600 │ Luckfox Pico Pro │ │
│ ┌──────────────────────────┐ │ ├══════════►│ (RV1106) │ │
│ │ EXTEROCEPTIVE (active) │ │ │◄══════════╡ NPU + 2.5D mapper│ │
│ │ VL53L8CX 8x8 ToF 15 Hz ├──►│ │ classes └───────┬──────────┘ │
│ │ US-100 ultrasonic ├──►│ │ │ │
│ └──────────────────────────┘ └─────────┬──────────┘ ▼ │
│ │ PWM ┌──────────────────┐ │
│ ▼ │ FAT32 microSD │ │
│ ┌────────────────────┐ │ .ply / .csv │ │
│ │ Motor drivers + │ │ map exports │ │
│ │ drive motors │ └──────────────────┘ │
│ └────────────────────┘ │
│ │
│ Mode 1 only: ESP32-S3 ~~ Wi-Fi SoftAP, UDP :9999 ~~► Ubuntu workstation (training) │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
The split follows one rule: anything with a hard deadline stays on the microcontroller; anything that needs memory, an OS, or a neural accelerator moves to the Linux SoC.
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ ESP32-S3 (N16R8) - REAL-TIME FRONT-END - FreeRTOS - ESP-IDF v6.1 (C++20) │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ CORE 1 (hard real-time, never blocked by Wi-Fi or UART) │
│ │
│ ┌────────────────────────┐ ┌────────────────────────┐ ┌────────────────────────┐ │
│ │ ICM-42688-P IMU │ │ Wheel encoders │ │ Closed-loop PID │ │
│ │ 6-axis @ 2 kHz │ │ HW PCNT, X4 decode │ │ 200 Hz motor control │ │
│ │ raw accel samples │ │ wheel speed │ │ speed -> PWM │ │
│ └───────────┬────────────┘ └───────────┬────────────┘ └────────────────────────┘ │
│ ▼ │ │
│ ┌────────────────────────┐ │ ┌────────────────────────┐ │
│ │ esp-dsp SIMD │ │ │ Pose estimator │ │
│ │ 5 Hz Butterworth HPF │ ├──────────────►│ IMU + encoders + mag │ │
│ │ -> ax_hp ay_hp az_hp │ │ │ POSE @ 100 Hz │ │
│ └───────────┬────────────┘ │ └────────────────────────┘ │
│ ▼ ▼ │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ Window builder: 256 samples x 5 channels │ │
│ │ (ax_hp, ay_hp, az_hp, wheel speed, smoothed current) │ -> WINDOW @ 15.6 Hz │
│ └──────────────────────────────────────────────────────┘ │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ CORE 0 (communications and ranging) │
│ │
│ ┌────────────────────────┐ ┌────────────────────────┐ ┌────────────────────────┐ │
│ │ VL53L8CX 8x8 ToF │ │ US-100 ultrasonic │ │ INA226 x2 (current) │ │
│ │ 15 Hz, 64 zones │ │ acoustic backup range │ │ MMC5983MA (heading) │ │
│ └────────────────────────┘ └────────────────────────┘ └────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────┐ ┌──────────────────────────────────────┐ │
│ │ MODE 1: Wi-Fi SoftAP + UDP :9999 │ │ MODE 2: UART1 @ 921,600 baud │ │
│ │ raw 2 kHz telemetry to workstation │ │ COBS + CRC-16 link to Luckfox │ │
│ └──────────────────────────────────────┘ └──────────────────────────────────────┘ │
└───────────────────────────────────────────┬────────────────────────────────────────────┘
│
POSE 100 Hz · TOF 15 Hz · WINDOW 15.6 Hz · STATUS 1 Hz
│
▼
▲
│
CLASS 15.6 Hz (reverse)
│
┌───────────────────────────────────────────┴────────────────────────────────────────────┐
│ LUCKFOX PICO PRO (Rockchip RV1106) - AI + 2.5D MAPPING BACK-END - Linux Buildroot │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ SCHED_FIFO threads │
│ │
│ ┌──────────────────────────────┐ ┌──────────────────────────┐ ┌─────────────────┐ │
│ │ Prio 85 UART decoder │ │ Prio 75 RKNPU2 INT8 │ │ Prio 60 Mapper │ │
│ │ COBS decode + CRC-16 check ├──►│ zero-copy inference ├──►│ 2.5D Kalman + │ │
│ │ dispatch POSE/TOF/WINDOW │ │ ~1 ms / window │ │ log-odds grid │ │
│ └──────────────────────────────┘ └──────────────────────────┘ └─────────────────┘ │
│ │
│ Storage: SPI NAND (OS, daemon, model) FAT32 microSD (.ply / .csv exports) │
└────────────────────────────────────────────────────────────────────────────────────────┘
| Subsystem | Part | Role in Grit |
|---|---|---|
| Real-time MCU | ESP32-S3 (N16R8) | 2 kHz acquisition, DSP, PID, pose, comms (16 MB flash / 8 MB PSRAM) |
| Linux + NPU SoC | Luckfox Pico Pro (RV1106) | INT8 CNN inference, 2.5D mapping, map export |
| IMU | ICM-42688-P | 2 kHz vibration + motion sensing |
| Forward ranging | VL53L8CX (8x8 ToF) | 64-zone height sampling ahead of the rover at 15 Hz |
| Backup ranging | US-100 ultrasonic | Acoustic range when IR is unreliable |
| Current sensing | INA226 (x2) | Motor current draw: an input channel to the CNN |
| Magnetometer | MMC5983MA | Heading reference for the pose estimator |
| Wheel feedback | Quadrature encoders | Speed via hardware PCNT in X4 mode |
| OS storage | 256 MB SPI NAND | Soldered; immune to contact bounce |
| Map storage | 32 GB Class 10 / U1 / U3 SD | FAT32, volume label NEUMA_MAPS |
| Mode selector | Hardware switch on GPIO 3 |
Selects Mode 1 (collect) or Mode 2 (live map) |
Bench-test safety. Before mounting the chassis and motors, enable
kBenchTestNoMotorsinesp32s3/components/robot_common/include/robot_config.hpp. This lets you verify every sensor over USB power without triggering motor PWM or low-voltage lockouts.
Grit is one firmware image with two personalities, selected by a hardware switch on GPIO 3.
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ MODE SELECTION │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────┐ │
│ │ ESP32-S3 running │ │
│ └──────────┬──────────┘ │
│ ▼ │
│ ◇ GPIO 3 switch state ◇ │
│ ┌──────────────────┴───────────────────┐ │
│ LOW │ │ HIGH │
│ ▼ ▼ │
│ ┌──────────────────────────────┐ ┌──────────────────────────────────┐ │
│ │ MODE 1 : DATA COLLECTION │ │ MODE 2 : LIVE VISIONLESS MAPPING │ │
│ ├──────────────────────────────┤ ├──────────────────────────────────┤ │
│ │ Start Wi-Fi SoftAP │ │ Enable UART1 @ 921,600 baud │ │
│ │ SSID : NEUMA_ROVER_AP │ │ Stream POSE / TOF / WINDOW / │ │
│ │ IP : 192.168.4.1 │ │ STATUS to Luckfox │ │
│ │ Stream raw 2 kHz telemetry │ │ Receive CLASS (15.6 Hz) back │ │
│ │ over non-blocking UDP :9999 │ │ Luckfox runs NPU + 2.5D mapper │ │
│ └──────────────┬───────────────┘ └────────────────┬─────────────────┘ │
│ ▼ ▼ │
│ ┌──────────────────────────────┐ ┌──────────────────────────────────┐ │
│ │ Ubuntu workstation │ │ Map exports (.ply / .csv) │ │
│ │ udp_logger -> .npz dataset │ │ -> microSD (or SPI NAND) │ │
│ │ PyTorch train + calibrate │ │ -> MeshLab / browser viewer │ │
│ └──────────────────────────────┘ └──────────────────────────────────┘ │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
Mode 1 (LOW) |
Mode 2 (HIGH) |
|
|---|---|---|
| Purpose | Build the training dataset | Run the robot |
| Link | Wi-Fi SoftAP, UDP port 9999 |
Wired UART1, 921,600 baud |
| Data sent | Raw 2 kHz telemetry | Compact POSE / TOF / WINDOW / STATUS frames |
| Who computes | Workstation (offline) | Luckfox NPU (online) |
| Output | .npz dataset, trained CNN, .rknn model |
.ply / .csv terrain maps |
| Core | Responsibility | Why it is isolated |
|---|---|---|
| Core 1 | IMU @ 2 kHz, PCNT wheel encoders, 200 Hz PID, esp-dsp 5 Hz Butterworth HPF, pose estimator |
Wi-Fi and UART stacks can stall for milliseconds. A missed IMU sample corrupts the window, and a late PID tick destabilizes the motors. |
| Core 0 | VL53L8CX + US-100 ranging, INA226 + MMC5983MA, Wi-Fi SoftAP / UDP (Mode 1), UART1 link (Mode 2) | Slow, bursty, and I/O-bound. It may block without hurting control. |
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ VIBRATION SIGNAL CHAIN (runs on ESP32 Core 1) │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ICM-42688-P │
│ raw accel │
│ ax, ay, az @ 2 kHz │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────────┐ │
│ │ esp-dsp SIMD biquad: 5 Hz Butterworth HPF │ removes gravity + slow tilt, so │
│ │ (one filter per axis) │ only terrain-induced vibration │
│ └──────────────────────┬───────────────────────┘ remains │
│ ▼ │
│ ax_hp ay_hp az_hp │
│ │ │ │ │
│ │ │ │ wheel speed ─────┐ smoothed motor current ─┐ │
│ │ │ │ (PCNT encoders) │ (INA226, low-passed) │ │
│ ▼ ▼ ▼ ▼ ▼ │
│ ┌────────────────────────────────────────────────────────────────────────────────┐ │
│ │ ring buffer -> 256-sample window x 5 channels │ │
│ │ │ │
│ │ ch0 ax_hp ░▒▓█▓▒░░▒▓█▓▒░░▒▓█▓▒░ ... (256 samples) │ │
│ │ ch1 ay_hp ░░▒▓█▓▒░░▒▓█▓▒░░▒▓█▓▒ ... │ │
│ │ ch2 az_hp ▒▓█▓▒░░▒▓█▓▒░░▒▓█▓▒░ ... │ │
│ │ ch3 speed ▁▁▂▂▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃ ... │ │
│ │ ch4 current ▂▂▂▃▃▃▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ... │ │
│ └───────────────────────────────────────┬────────────────────────────────────────┘ │
│ ▼ │
│ COBS + CRC-16 -> WINDOW frame @ 15.6 Hz │
│ ▼ │
│ UART1 -> Luckfox Pico Pro │
│ │
│ 256 samples / 2000 Hz = 128 ms per window -> 2000 / 256 = 15.625 windows per sec │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
Two properties of this chain matter for correctness:
- The window rate falls out of the sample rate. 256 samples at 2 kHz is 128 ms, so one new window every 128 ms is 15.625 Hz, matching the
WINDOW (15.6 Hz)andCLASS (15.6 Hz)rates on the link. The windows are non-overlapping. - Speed and current are part of the tensor. Without them, the network sees vibration amplitude and cannot tell whether it came from the ground or from driving faster. See Section 9.
The pose estimator fuses IMU, wheel encoders, and the MMC5983MA magnetometer and publishes POSE at 100 Hz. The Luckfox mapper uses this pose to place every ToF ray and every wheel-track classification in the world grid.
| Parameter | Value |
|---|---|
| Physical | UART1 on ESP32-S3 <-> /dev/ttyS3 on Luckfox |
| Baud rate | 921,600 |
| Framing | COBS (Consistent Overhead Byte Stuffing), zero-delimited |
| Integrity | CRC-16-CCITT over each frame |
| Why COBS | A 0x00 delimiter gives self-resynchronization after any dropped byte or noise burst |
| Why CRC-16 | A corrupted vibration window must be rejected, never classified |
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ ON-THE-WIRE FRAME │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────┬──────────────────────────────────────────────────────────┬──────┐ │
│ │ 0x00 │ COBS-ENCODED ( payload || CRC-16 ) │ 0x00 │ │
│ └──────┴──────────────────────────────────────────────────────────┴──────┘ │
│ delim contains no 0x00 byte by construction delim │
│ │
│ Before COBS encoding: │
│ │
│ ┌──────────────┬────────────────────────────────────────────┬───────────────┐ │
│ │ msg type │ payload │ CRC-16-CCITT │ │
│ │ POSE/TOF/... │ message-specific fields │ (2 bytes) │ │
│ └──────────────┴────────────────────────────────────────────┴───────────────┘ │
│ │
│ Receiver: read to 0x00 -> COBS decode -> verify CRC -> dispatch on msg type │
│ CRC fail -> drop frame, wait for next 0x00 (instant resync) │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
Exact field widths and ordering are defined by the link sources in
esp32s3/main/(ESP32 side) andluckfox_picopro/neuma_luckfox_daemon/(Luckfox side). The diagram shows the concept only.
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ MESSAGE DIRECTIONS │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ESP32-S3 LUCKFOX PICO │
│ ┌────────┐ ┌─────────────┐ │
│ │ │ POSE 100 Hz robot pose (x, y, heading) │ │ │
│ │ ├─────────────────────────────────────────────────►┤ │ │
│ │ │ TOF 15 Hz 8x8 range frame (64 zones) │ │ │
│ │ REAL- ├─────────────────────────────────────────────────►┤ AI + 2.5D │ │
│ │ TIME │ WINDOW 15.6 Hz 5 x 256 vibration window │ MAPPING │ │
│ │ ├─────────────────────────────────────────────────►┤ │ │
│ │ │ STATUS 1 Hz health / mode / counters │ │ │
│ │ ├─────────────────────────────────────────────────►┤ │ │
│ │ │ │ │ │
│ │ │ CLASS 15.6 Hz terrain label per window │ │ │
│ │ ┤◄─────────────────────────────────────────────────├ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ └────────┘ └─────────────┘ │
└────────────────────────────────────────────────────────────────────────────────────────┘
| Message | Direction | Rate | Meaning |
|---|---|---|---|
POSE |
ESP32 -> Luckfox | 100 Hz | Fused robot pose for placing measurements in the world |
TOF |
ESP32 -> Luckfox | 15 Hz | 8x8 VL53L8CX range frame (64 zones) |
WINDOW |
ESP32 -> Luckfox | 15.6 Hz | One 5-channel, 256-sample vibration/speed/current window |
STATUS |
ESP32 -> Luckfox | 1 Hz | Health, mode, and diagnostic counters |
CLASS |
Luckfox -> ESP32 | 15.6 Hz | Terrain class result for the window just inferred |
The 921,600-baud 8N1 link carries at most 921,600 / 10 = 92,160 bytes/s. A rough budget for the dominant stream:
WINDOW payload assumption |
Bytes per window | x 15.625 Hz | Share of link |
|---|---|---|---|
| INT8 samples (5 x 256) | 1,280 | ~20 kB/s | ~22 % |
| 16-bit samples (5 x 256) | 2,560 | ~40 kB/s | ~43 % |
Either way, WINDOW plus POSE, TOF, and COBS overhead (at most 1 byte per 254, plus delimiters) fits with headroom. These are budgeting estimates, not measurements.
Vibration energy depends on what the wheels roll over and how fast they roll. A classifier trained on vibration alone confuses the two:
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ WHY SPEED AND CURRENT ARE INPUTS │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ vibration │
│ energy │
│ ▲ · gravel/sand │
│ │ · · │
│ │ · · │
│ │ · · ░ ░ tile (fast) │
│ │ · · ░ ░ │
│ │ · · ░ ░ │
│ │ · · ░ ░ │
│ │ · · ░ ░ │
│ │ · · ░ ░ │
│ └──────────────────────────────────────────────────────────────► wheel speed │
│ │
│ A slow ride on gravel and a fast ride on tile can look the SAME in raw vibration. │
│ With speed (and motor current, a proxy for rolling resistance) as extra channels, │
│ the network learns the *conditional* signature and the confusion disappears. │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
Motor current adds a second, independent cue: soft ground (sand, grass) draws more current at the same speed than a hard surface.
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ CNN INPUT (1, 5, 1, 256) - INT8 │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ N C H W │
│ ┌─┐ ┌─┐ ┌─┐ ┌───┐ │
│ │1│ │5│ │1│ │256│ batch=1 | 5 channels | height=1 | 256 time samples │
│ └─┘ └┬┘ └─┘ └───┘ │
│ │ │
│ ├── C0 ax_hp 5 Hz high-passed accel X │
│ ├── C1 ay_hp 5 Hz high-passed accel Y │
│ ├── C2 az_hp 5 Hz high-passed accel Z │
│ ├── C3 wheel speed from PCNT X4 encoders │
│ └── C4 smoothed motor current from INA226 │
│ │
│ The height dimension is 1, so every Conv2d uses a 1 x K kernel: it slides along │
│ TIME only. It never mixes "rows" because there is only one. │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ INFERENCE PATH ON THE RV1106 │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ WINDOW frame zero-copy buffer RKNPU2 result │
│ (from UART) (input tensor memory) INT8 execution │
│ │
│ ┌──────────┐ ┌──────────────────┐ ┌───────────────────┐ ┌───────────┐ │
│ │ decoded ├───────►│ (1,5,1,256) INT8 ├────►│ 1xK Conv2d CNN ├──►│ 5 class │ │
│ │ window │ write │ in NPU-visible │ run │ terrain_cnn_ │ │ scores │ │
│ │ │ direct │ memory │ │ rv1106.rknn │ │ │ │
│ └──────────┘ └──────────────────┘ └───────────────────┘ └─────┬─────┘ │
│ │ │
│ no memcpy between decode and inference ▼ │
│ ┌────────────────┐ │
│ │ argmax -> CLASS│ │
│ │ + feed mapper │ │
│ └────────────────┘ │
│ │
│ Budget: ~1 ms inference vs 128 ms window period -> < 1 % NPU duty cycle │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
| Class | Physical meaning | Mapping consequence |
|---|---|---|
tile |
Hard, smooth, indoor-type surface | Traversable, low vibration |
asphalt |
Hard, textured outdoor surface | Traversable |
gravel/sand |
Loose, deformable, high-vibration or high-drag | Trap risk; the reason Grit exists |
grass |
Soft, compliant vegetation | Traversable with higher current draw |
lifted |
Wheels off the ground | Not terrain; flags wheel-slip / pick-up events and supplies the motor-noise baseline |
| Choice | Reason |
|---|---|
| INT8 quantization | RV1106's RKNPU2 is an integer accelerator. A small 1D-style CNN quantizes well. |
| Zero-copy | Avoids copying every 5 x 256 window between buffers on a memory-constrained SoC. |
1 x K kernels |
Maps a temporal convolution onto the NPU's 2D conv engine without reshaping tricks. |
| Calibration set | The trainer exports a calibration dataset (rknn_calib/) used by the converter to choose INT8 scales. |
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ MAP GRID GEOMETRY │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ 20 m │
│ ◄──────────────────────────────────────────────────────────────────────────► │
│ ┌──────────────────────────────────────────────────────────────────────────┐ ▲ │
│ │ │ │ │
│ │ │ │ │
│ │ │ │ │
│ │ · · · │ │ │
│ │ · · radius > 10 m │ │ │
│ │ · ROVER · │ 20 m │
│ │ · (origin)· │ │ │
│ │ · · · │ │ │
│ │ │ │ │
│ │ │ │ │
│ │ │ │ │
│ └──────────────────────────────────────────────────────────────────────────┘ ▼ │
│ │
│ Zoom on 4 x 4 cells: Each cell stores: │
│ │
│ ┌─────┬─────┬─────┬─────┐ - elevation estimate (Kalman mean) │
│ │ 5cm │ │ │ │ - elevation variance (Kalman uncertainty) │
│ ├─────┼─────┼─────┼─────┤ - terrain log-odds per class (5 classes) │
│ │ │ │ │ │ │
│ ├─────┼─────┼─────┼─────┤ 20 m / 5 cm = 400 cells per side │
│ │ │ │ │ │ 400 x 400 = 160,000 cells │
│ ├─────┼─────┼─────┼─────┤ │
│ │ │ │ │ │ This is "2.5D": one height per (x, y) cell, │
│ └─────┴─────┴─────┴─────┘ not a full volumetric 3D voxel map. │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ HOW GEOMETRY AND SEMANTICS REACH THE GRID │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ STREAM A : GEOMETRY (looks ahead) STREAM B : SEMANTICS (feels beneath) │
│ │
│ TOF 8x8 frame @ 15 Hz WINDOW @ 15.6 Hz │
│ │ │ │
│ ▼ ▼ │
│ POSE-synchronised ray casting CNN -> class probabilities │
│ (64 rays -> world-frame hit points) │ │
│ │ ▼ │
│ ▼ project wheel-track footprint │
│ hit point -> grid cell (x, y) from POSE onto the grid │
│ │ │ │
│ ▼ ▼ │
│ 1D KALMAN update, per cell: BAYESIAN LOG-ODDS update, per cell: │
│ predict: P <- P + Q l_k <- clip( l_k + log-evidence_k ) │
│ gain : K = P / (P + R) posterior = normalise( l ) │
│ update : h <- h + K (z - h) │
│ P <- (1 - K) P │
│ │ │ │
│ └───────────────────┬───────────────────────┘ │
│ ▼ │
│ ┌──────────────────────────────────────────┐ │
│ │ CO-REGISTERED 2.5D GRID (400 x 400) │ │
│ │ height h, variance P, class posterior │ │
│ └────────────────────┬─────────────────────┘ │
│ ▼ │
│ periodic export: .ply and .csv │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
The Kalman and log-odds equations above are the standard formulations the mapper is built around. Noise parameters (
Q,R), clipping bounds, and evidence weighting live in the daemon source underluckfox_picopro/neuma_luckfox_daemon/.
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ TOP-DOWN VIEW OF ONE ROVER POSITION │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ direction of travel ────► (+x) │
│ │
│ ╱ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ │
│ ╱ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ 8x8 ToF field │
│ ╱ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ of view: HEIGHT │
│ ╱ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ measured AHEAD, │
│ ● ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ before the rover │
│ ╲ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ arrives │
│ ╲ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ │
│ ╲ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ │
│ ╲ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ │
│ │
│ ════════════╗ │
│ ▓▓▓▓▓▓▓▓▓▓▓▓║◄── wheel track : CLASS painted here, AFTER driving over it │
│ ┌───────────────┐ │
│ │ ROVER │ │
│ └───────────────┘ │
│ ▓▓▓▓▓▓▓▓▓▓▓▓║◄── wheel track : CLASS painted here, AFTER driving over it │
│ ════════════╝ │
│ │
│ Geometry is a prediction about the ground AHEAD. Semantics is a measurement of the │
│ ground JUST TRAVERSED. The map joins them cell by cell as the rover moves on. │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
neuma_daemon is a cross-compiled C++20 program running under Linux Buildroot. It uses three SCHED_FIFO real-time threads whose priorities encode the data flow: the thread that must never miss a byte outranks the one that consumes its output.
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ neuma_daemon - THREAD AND DATA FLOW │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ /dev/ttyS3 @ 921,600 │
│ │ bytes │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ THREAD 1 SCHED_FIFO prio 85 UART decoder │ │
│ │ read -> split on 0x00 -> COBS decode -> CRC-16 verify │ │
│ │ dispatch by msg type │ │
│ └──────┬──────────────────┬──────────────────────┬─────────────┘ │
│ │ WINDOW │ POSE │ TOF │
│ ▼ │ │ │
│ ┌──────────────────────┐ │ │ │
│ │ THREAD 2 prio 75 │ │ │ │
│ │ RKNPU2 INT8 inference│ │ │ │
│ │ zero-copy, ~1 ms │ │ │ │
│ └──────┬───────────────┘ │ │ │
│ │ class probs │ │ │
│ │ │ CLASS ────┼──────────────► back to ESP32 over UART │
│ ▼ ▼ ▼ ▼ │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ THREAD 3 SCHED_FIFO prio 60 2.5D mapper │ │
│ │ ToF ray cast + per-cell 1D Kalman (height) │ │
│ │ wheel-track Bayesian log-odds (terrain class) │ │
│ │ periodic .ply / .csv export │ │
│ └──────────────────────────────────┬───────────────────────────┘ │
│ ▼ │
│ microSD or SPI NAND fallback │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
| Thread | Priority | Why this priority |
|---|---|---|
| UART decoder | 85 | A starved UART buffer drops bytes and forces a resync; it must always run first. |
| NPU inference | 75 | Latency-sensitive (CLASS goes back to the ESP32) but short (~1 ms). |
| 2.5D mapper | 60 | The heaviest loop (160,000-cell grid) but tolerant of small delays, since the map is eventually consistent. |
Rovers on gravel and steps shake. A microSD card's spring contacts can momentarily open under vibration, which can corrupt a running filesystem, so Grit keeps anything the system needs off the card.
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ STORAGE SPLIT BY ROLE │
├───────────────────────────────────────────────┬────────────────────────────────────────┤
│ 256 MB SPI NAND (soldered, vibration-immune)│ FAT32 microSD (replaceable, "NEUMA_ │
│ │ MAPS", 32 GB Class 10 / U1 / U3) │
│ / Linux Buildroot OS │ │
│ /root/neuma/neuma_daemon │ /mnt/sdcard/neuma_maps/ │
│ /root/neuma/lib/librknnmrt.so │ neuma_map_*.ply │
│ /root/neuma/terrain_cnn_rv1106.rknn │ neuma_map_*.csv │
│ /root/neuma/start_neuma.sh │ │
│ /root/neuma/maps/ (fallback exports) │ Pulled off by hand, card swapped │
│ │ in seconds, no SSH required │
├───────────────────────────────────────────────┴────────────────────────────────────────┤
│ If the card bounces or is missing, the robot still boots and still maps. │
└────────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ start_neuma.sh - STORAGE SELECTION │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌───────────────────────────┐ │
│ │ boot -> start_neuma.sh │ │
│ └─────────────┬─────────────┘ │
│ ▼ │
│ ◇ /dev/mmcblk0p1 present ? ◇ │
│ ┌─────────────────────┴──────────────────────┐ │
│ YES│ │NO │
│ ▼ ▼ │
│ ┌─────────────────────────────────┐ ┌─────────────────────────────────────┐ │
│ │ mount /dev/mmcblk0p1 │ │ use /root/neuma/maps (SPI NAND) │ │
│ │ -> /mnt/sdcard/neuma_maps │ │ │ │
│ │ out dir = /mnt/sdcard/neuma_maps│ │ DISABLE periodic 5-second writes │ │
│ │ periodic 5 s exports ENABLED │ │ (protects NAND write endurance) │ │
│ └───────────────┬─────────────────┘ └──────────────────┬──────────────────┘ │
│ └──────────────────┬───────────────────────┘ │
│ ▼ │
│ ┌────────────────────────────────┐ │
│ │ launch neuma_daemon │ │
│ │ --model terrain_cnn_*.rknn │ │
│ │ --out <chosen directory> │ │
│ └────────────────────────────────┘ │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
Rates are specified by the design; the derived columns are simple arithmetic from them.
| Signal / task | Rate / size | Period / count |
|---|---|---|
| IMU acquisition | 2 kHz | 500 us |
| Motor PID loop | 200 Hz | 5 ms |
POSE frames |
100 Hz | 10 ms |
| ToF frames | 15 Hz (8x8 = 64 zones) | ~66.7 ms, 960 zones/s |
| CNN window | 256 samples @ 2 kHz | 128 ms (15.625 Hz) |
| CNN inference | ~1 ms | < 1 % of window period |
STATUS |
1 Hz | 1 s |
| Map grid | 400 x 400 | 160,000 cells |
| Map area per cell | 5 cm x 5 cm | 25 cm^2 |
| Periodic map write (microSD) | every 5 s | disabled on NAND fallback |
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ ONE 128 ms WINDOW PERIOD, ON A TIMELINE │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ t = 0 ms t = 128 ms │
│ ├──────────────────────────────────────────────────────────────────────────────┤ │
│ IMU │││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││ │
│ 256 samples (one every 0.5 ms) │
│ PID │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ ~25 ticks (one every 5 ms) │
│ POSE │ │ │ │ │ │ │ │ │
│ ~12-13 updates (one every 10 ms) │
│ TOF │ │ │ │
│ ~2 frames (one every 66.7 ms) │
│ WINDOW ▲ │
│ emitted at 128 ms │
│ NPU █ │
│ ~1 ms burst, then idle │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
grit/
├── .gitignore # Excludes build artifacts, .venv, datasets, and cloned SDKs
├── README.md # Project documentation & setup guide
│
├── esp32s3/ # ESP-IDF v6.1 (C++20) real-time firmware
│ ├── CMakeLists.txt
│ ├── partitions.csv # 1 MB SPIFFS partition for calibration constants
│ ├── sdkconfig.defaults # Reproducible ESP-IDF configuration
│ ├── dependencies.lock # Locked ESP-IDF Component Manager versions
│ ├── components/ # Custom drivers
│ │ ├── icm42688/ # IMU
│ │ ├── ina226/ # current sensor
│ │ ├── mmc5983ma/ # magnetometer
│ │ ├── us100/ # ultrasonic
│ │ ├── motors/ # motor drive + PID
│ │ └── robot_common/ # shared config, constants, model_calib_constants.hpp
│ └── main/ # FreeRTOS tasks, esp-dsp filter, pose estimator, UDP & UART links
│
└── luckfox_picopro/ # Linux/NPU back-end & Ubuntu ML suite
├── neuma_laptop_suite/ # Mode 1 UDP logger, PyTorch CNN trainer, RKNN converter, Three.js viewer
│ ├── udp_logger_and_npz_converter.py
│ ├── train_baselines_and_cnn.py
│ ├── convert_to_rknn_rv1106.py
│ └── viewer/index.html
├── neuma_luckfox_daemon/ # Cross-compiled C++20 NPU + 2.5D terrain mapper daemon
└── sdks/ # [IGNORED BY GIT] Cloned Luckfox & Rockchip SDKs (see Section 15)
The component folder names under
esp32s3/components/are shown by role. Check the directory for exact names.
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ WORKSTATION SETUP ROADMAP │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ [1] apt packages ──► [2] clone SDKs ──► [3] register toolchain ──► [4] venv │
│ build tools, luckfox-pico, add cross-compiler to PyTorch, │
│ cross-compile rknn-toolkit2, PATH in ~/.bashrc ONNX, │
│ libs, SSH rknn_model_zoo RKNN wheel │
│ │
│ Then independently: [5] install ESP-IDF v6.1 (Section 16) │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
sudo apt update && sudo apt install -y \
python3-venv python3-full python3-pip python-is-python3 \
git ssh make gcc gcc-multilib g++-multilib module-assistant expect g++ gawk \
texinfo libssl-dev bison flex fakeroot cmake unzip gperf autoconf \
device-tree-compiler libncurses5-dev pkg-config bc passwd openssl \
openssh-server openssh-client vim file cpio rsync dosfstools partedThird-party SDKs are multi-gigabyte repositories excluded by .gitignore. Clone them into luckfox_picopro/sdks/:
mkdir -p ~/grit/luckfox_picopro/sdks
cd ~/grit/luckfox_picopro/sdks
# 1. Official Luckfox Pico SDK + ARM uClibc Cross-Compiler Toolchain
git clone https://github.com/LuckfoxTECH/luckfox-pico.git
# 2. Rockchip RKNN-Toolkit2 (Python wheels + RV1106 librknnmrt.so runtime)
git clone https://github.com/airockchip/rknn-toolkit2.git --depth 1
# 3. Rockchip RKNN Model Zoo (RV1106 zero-copy C++ reference examples)
git clone https://github.com/airockchip/rknn_model_zoo.git --depth 1| SDK | Provides | Used for |
|---|---|---|
luckfox-pico |
ARM uClibc cross-compiler, board SDK | Building neuma_daemon |
rknn-toolkit2 |
Python wheels, librknnmrt.so runtime |
ONNX -> .rknn conversion; on-device NPU runtime |
rknn_model_zoo |
RV1106 zero-copy C++ examples | Reference for the daemon's inference path |
echo 'export LUCKFOX_TOOLCHAIN="$HOME/grit/luckfox_picopro/sdks/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin"' >> ~/.bashrc
echo 'export PATH="$LUCKFOX_TOOLCHAIN:$PATH"' >> ~/.bashrc
source ~/.bashrc
# Verify the toolchain is active
arm-rockchip830-linux-uclibcgnueabihf-g++ --versioncd ~/grit/luckfox_picopro/neuma_laptop_suite
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install numpy scipy scikit-learn torch torchvision onnx onnxruntimeInstall the RKNN-Toolkit2 wheel matching your active Python version (e.g., cp312 for Python 3.12 on Ubuntu 24.04):
PY_VER=$(python3 -c "import sys; print(f'cp{sys.version_info.major}{sys.version_info.minor}')")
pip install ~/grit/luckfox_picopro/sdks/rknn-toolkit2/rknn-toolkit2/packages/x86_64/rknn_toolkit2-*-${PY_VER}-${PY_VER}-manylinux_2_17_x86_64.manylinux2014_x86_64.whlRequires ESP-IDF v6.1 installed and sourced (get_idf or source ~/esp/esp-idf/export.sh).
cd ~/grit/esp32s3
# Set target chip (ESP32-S3 N16R8)
idf.py set-target esp32s3
# Build firmware (automatically fetches managed_components from dependencies.lock)
idf.py build
# Flash and open serial monitor (replace /dev/ttyACM0 with your port)
idf.py -p /dev/ttyACM0 flash monitor┌────────────────────────────────────────────────────────────────────────────────────────┐
│ FIRMWARE BRING-UP FLOW │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────────┐ │
│ │ source ESP-IDF v6.1 │ │
│ └──────────┬───────────┘ │
│ ▼ │
│ ┌──────────────────────┐ ┌───────────────────────────────────────────┐ │
│ │ idf.py set-target │ │ BENCH TEST (no chassis, USB power): │ │
│ │ esp32s3 │ │ kBenchTestNoMotors = enabled │ │
│ └──────────┬───────────┘ │ verify IMU, ToF, US-100, INA226, MMC5983 │ │
│ ▼ │ no motor PWM, no low-voltage lockout │ │
│ ┌──────────────────────┐ └───────────────────▲───────────────────────┘ │
│ │ idf.py build │ │ │
│ │ (fetch components) │ │ first flash │
│ └──────────┬───────────┘ │ │
│ ▼ │ │
│ ┌──────────────────────┐ │ │
│ │ idf.py -p PORT ├────────────────────────────┘ │
│ │ flash monitor │ │
│ └──────────┬───────────┘ │
│ ▼ │
│ ◇ all sensors report sane values ? ◇ │
│ YES │ │ NO -> see Troubleshooting (Section 21) │
│ ▼ │
│ disable kBenchTestNoMotors, mount chassis + motors, re-flash │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
cd ~/grit/luckfox_picopro/neuma_laptop_suite
source .venv/bin/activate
# 1. Collect Mode 1 live UDP telemetry (or pass --generate-synthetic for pipeline verification)
python3 udp_logger_and_npz_converter.py --out-dir ./dataset_npz
# 2. Train RF/SVM baselines + 1xK Conv2d CNN, export ONNX, calibration set & ESP32 header
python3 train_baselines_and_cnn.py --data-dir ./dataset_npz --out-dir ./artifacts
# 3. Sync the generated INT8 quantization constants to the ESP32-S3 firmware
cp ./artifacts/model_calib_constants.hpp ~/grit/esp32s3/components/robot_common/include/
# 4. Convert ONNX -> RV1106 INT8 .rknn model
python3 convert_to_rknn_rv1106.py \
--onnx ./artifacts/terrain_cnn.onnx \
--dataset ./artifacts/rknn_calib/calib_dataset.txt \
--out-rknn ./artifacts/terrain_cnn_rv1106.rknnStep 3 changes firmware inputs. After copying
model_calib_constants.hpp, rebuild and re-flash the ESP32-S3 (Section 16) so the front-end uses the same constants the model was calibrated with.
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ END-TO-END ML PIPELINE (workstation) │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌───────────────────┐ │
│ │ ROVER, Mode 1 │ Wi-Fi SoftAP NEUMA_ROVER_AP, UDP :9999 │
│ │ drives real terrain├──────────────────────────────┐ │
│ └───────────────────┘ ▼ │
│ ┌──────────────────────────────────┐ │
│ (or --generate-synthetic) │ [1] udp_logger_and_npz_converter │ │
│ ───────────────────────────►│ raw packets -> dataset_npz/ │ │
│ └────────────────┬─────────────────┘ │
│ ▼ │
│ ┌──────────────────────────────────┐ │
│ │ [2] train_baselines_and_cnn │ │
│ │ RF + SVM baselines │ │
│ │ 1xK Conv2d CNN (PyTorch) │ │
│ └──┬──────────────┬─────────────┬──┘ │
│ │ │ │ │
│ terrain_cnn.onnx │ rknn_calib/│ │ model_calib_ │
│ │ calib_ │ │ constants.hpp │
│ │ dataset.txt│ │ │
│ ▼ ▼ ▼ │
│ ┌───────────────────────────────┐ ┌───────────────────┐ │
│ │ [4] convert_to_rknn_rv1106 │ │ [3] cp to ESP32 │ │
│ │ ONNX -> INT8 .rknn │ │ robot_common/ │ │
│ └───────────────┬───────────────┘ │ include/ │ │
│ ▼ └─────────┬─────────┘ │
│ terrain_cnn_rv1106.rknn ▼ │
│ │ rebuild + re-flash │
│ ▼ ESP32-S3 firmware │
│ deploy to Luckfox │
│ (Section 18) │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
| Script | Input | Output |
|---|---|---|
udp_logger_and_npz_converter.py |
Live UDP telemetry (or --generate-synthetic) |
dataset_npz/*.npz |
train_baselines_and_cnn.py |
dataset_npz/ |
RF/SVM baselines, terrain_cnn.onnx, rknn_calib/calib_dataset.txt, model_calib_constants.hpp |
convert_to_rknn_rv1106.py |
terrain_cnn.onnx + calibration dataset |
terrain_cnn_rv1106.rknn |
The RF and SVM baselines exist for honesty: if the CNN does not clearly beat classical models on the same grouped splits, the network is not earning its place.
cd ~/grit/luckfox_picopro/neuma_luckfox_daemon
rm -rf build && mkdir build && cd build
cmake ..
make -j$(nproc)
# Verify ARM uClibc binary and staged NPU runtime
file neuma_daemon
ls -lh lib/librknnmrt.soConnect the Luckfox Pico Pro via USB-C (default RNDIS IP: 172.32.0.93):
ssh root@172.32.0.93 "mkdir -p /root/neuma/lib /root/neuma/maps"
scp ~/grit/luckfox_picopro/neuma_luckfox_daemon/build/neuma_daemon root@172.32.0.93:/root/neuma/
scp ~/grit/luckfox_picopro/neuma_luckfox_daemon/build/lib/librknnmrt.so root@172.32.0.93:/root/neuma/lib/
scp ~/grit/luckfox_picopro/neuma_laptop_suite/artifacts/terrain_cnn_rv1106.rknn root@172.32.0.93:/root/neuma/┌────────────────────────────────────────────────────────────────────────────────────────┐
│ DEPLOYMENT LAYOUT │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ UBUNTU WORKSTATION LUCKFOX PICO PRO (SPI NAND) │
│ │
│ neuma_luckfox_daemon/build/ /root/neuma/ │
│ neuma_daemon ──────────────────── scp ─────────► neuma_daemon │
│ lib/librknnmrt.so ─────────────── scp ─────────► lib/librknnmrt.so │
│ │
│ neuma_laptop_suite/artifacts/ │
│ terrain_cnn_rv1106.rknn ───────── scp ─────────► terrain_cnn_rv1106.rknn │
│ maps/ (created by ssh) │
│ start_neuma.sh │
│ │
│ link: USB-C (RNDIS), Luckfox IP 172.32.0.93 │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
Use a 32 GB Class 10 / U1 (or U3) microSD card formatted to FAT32 (NEUMA_MAPS) for .ply and .csv map exports. When inserted into the Luckfox Pico Pro, /root/neuma/start_neuma.sh automatically mounts /dev/mmcblk0p1 to /mnt/sdcard/neuma_maps. If no card is present it falls back to /root/neuma/maps on SPI NAND, with periodic 5-second writes disabled to protect NAND lifespan. See the flow in Section 12.1.
ssh root@172.32.0.93
cd /root/neuma
export LD_LIBRARY_PATH=/root/neuma/lib:$LD_LIBRARY_PATH
# Run hardware NPU + 2.5D mapper self-test
./neuma_daemon --model ./terrain_cnn_rv1106.rknn --out /root/neuma/maps --self-test
# Launch live Mode 2 UART daemon (ESP32-S3 <-> /dev/ttyS3 @ 921600 baud)
./start_neuma.shPull exported .ply and .csv maps from the microSD card (or via scp from the Luckfox Pico Pro) and open them in MeshLab or the bundled browser viewer (luckfox_picopro/neuma_laptop_suite/viewer/index.html):
scp root@172.32.0.93:/mnt/sdcard/neuma_maps/neuma_map_*.ply .| Format | Best for |
|---|---|
.ply |
3D inspection in MeshLab or the Three.js browser viewer |
.csv |
Per-cell analysis in Python, spreadsheets, or evaluation scripts |
Terrain classifiers on time-series data are easy to make look good and hard to make honest. Adjacent windows from one drive are nearly identical, so a random train/test split quietly lets the model memorize runs instead of learning terrain. Grit closes each leak explicitly.
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ ZERO-LEAKAGE VALIDATION PIPELINE │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ raw runs (each with a unique run ID) │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────────────────────┐ │
│ │ GUARD 1: 1-second endpoint trimming │ │
│ │ drop the first and last 1 s of every run (start/stop transients, hand │ │
│ │ placement, acceleration ramps that are not steady-state terrain signal) │ │
│ └──────────────────────────────────────┬───────────────────────────────────────┘ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────────────────────┐ │
│ │ GUARD 2: run-ID grouped cross-validation │ │
│ │ all windows from one run stay together in either train or validation, │ │
│ │ so near-duplicate neighbouring windows never straddle the split │ │
│ └──────────────────────────────────────┬───────────────────────────────────────┘ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────────────────────┐ │
│ │ GUARD 3: held-out unseen physical locations │ │
│ │ whole sites are reserved for test only, so the model cannot learn "this │ │
│ │ particular patch of gravel" instead of "gravel" │ │
│ └──────────────────────────────────────┬───────────────────────────────────────┘ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────────────────────┐ │
│ │ GUARD 4: lifted-wheel motor-noise baseline │ │
│ │ run the motors with wheels off the ground: measures the vibration the │ │
│ │ drivetrain itself injects, so it is not mistaken for terrain texture │ │
│ └──────────────────────────────────────┬───────────────────────────────────────┘ │
│ ▼ │
│ report on held-out data: CNN vs RF vs SVM │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
| Leak | Failure it prevents | Guard |
|---|---|---|
| Endpoint transients | Model learns start/stop signatures instead of terrain | 1-second trimming |
| Neighbouring-window duplication | Inflated accuracy from near-identical train and test windows | Run-ID grouped CV |
| Location memorization | Model recognizes a place, not a surface | Held-out unseen locations |
| Drivetrain noise | Motor hum read as surface texture | Lifted-wheel baseline (lifted class) |
| Speed confound | Speed read as surface roughness | Speed + current as CNN channels |
Reporting guidance: quote results from the held-out-location test only. Cross-validation scores on seen locations are a development tool, not a headline number.
| Symptom | Likely cause | Fix |
|---|---|---|
idf.py flash cannot open /dev/ttyACM0 |
No serial permission, or wrong port | sudo usermod -aG dialout $USER, log out/in, check ls /dev/ttyACM* |
idf.py not found |
ESP-IDF environment not sourced | source ~/esp/esp-idf/export.sh (or get_idf) |
| Motors do not spin on bench | kBenchTestNoMotors is enabled |
Disable it in robot_config.hpp, rebuild, re-flash |
arm-rockchip830-linux-uclibcgnueabihf-g++ not found |
Toolchain not on PATH |
Redo Section 15.4 and source ~/.bashrc |
pip install of RKNN wheel finds no match |
Python tag mismatch | Re-run the PY_VER snippet; use the wheel whose tag matches (cp312 on Ubuntu 24.04) |
pip install fails with "externally managed environment" |
Installing outside a venv (PEP 668) | Activate .venv first (source .venv/bin/activate) |
error while loading shared libraries: librknnmrt.so |
Runtime not on loader path | export LD_LIBRARY_PATH=/root/neuma/lib:$LD_LIBRARY_PATH |
Cannot ssh root@172.32.0.93 |
RNDIS link not up | Re-plug USB-C, check the host sees a new network interface |
| No maps appear on the card | Card missing or not FAT32, so the daemon fell back to NAND | Check /root/neuma/maps; reformat card as FAT32 labelled NEUMA_MAPS |
| Maps only appear on exit, not every 5 s | Running in NAND-fallback mode (periodic writes disabled) | Insert a valid microSD card and restart start_neuma.sh |
| Frequent UART CRC errors | Loose wiring, long leads, or baud mismatch | Shorten and shield the link, confirm 921,600 baud on both ends |
| Classifier output looks random on the robot | Front-end constants out of sync with the model | Re-copy model_calib_constants.hpp, rebuild + re-flash, redeploy the matching .rknn |
| No UDP data in Mode 1 | Workstation not joined to the SoftAP | Connect to NEUMA_ROVER_AP; the ESP32 is at 192.168.4.1, logger listens on port 9999 |
Current limitations
- 2.5D, not volumetric. One height per cell: overhangs, bridges, and tunnels cannot be represented.
- Semantics are earned by driving. A cell is only classified after a wheel crosses it. Unvisited ground has geometry but no tactile class.
- Short-range IR. 8x8 ToF sensing degrades in strong sunlight and on very dark or glossy surfaces, which is why the ultrasonic backup exists.
- Dead-reckoning drift. Pose comes from IMU, encoders, and magnetometer with no external reference; long runs accumulate map misregistration. Magnetometer quality depends on the local magnetic environment.
- Closed class set. Five terrain classes; novel surfaces are forced into the nearest known class.
Natural extensions
- Predict semantics ahead of the rover by learning the correlation between ToF-measured micro-roughness and tactile class.
- Add loop-closure or scan-matching on the 2.5D grid to bound drift.
- Feed the traversability map into a path planner that avoids
gravel/sandand prefers firm surfaces. - Expose live map streaming from the Luckfox to the browser viewer.
Developed as a Final Year Mechatronics Engineering Project (Grit). Open-source third-party SDKs (esp-idf, luckfox-pico, rknn-toolkit2, rknn_model_zoo) remain under their respective upstream licenses.