Pitwall:
Real-Time AI
Race Coach
— On Device.
Move beyond the reactive post-session debrief of Garmin Catalyst or AiM Solo. Pitwall runs entirely on Pixel 10 via Termux — no cell coverage required. Sub-50ms hot-path coaching grounded in Ross Bentley's pedagogy, adapting to your skill level in real time.
Live Telemetry · Lap Delta
Domain Expertise Layer
9 pedagogical vectors drawn from Ross Bentley's Performance Driving Illustrated. T-Rod Sonoma transcript encoded as canonical phrases. Per-corner doctrine for all 12 turns at Sonoma Raceway.
Split-Brain Engine
Hot path (sonic model + RuleCoach) fires in <50ms — zero LLM calls during driving. Warm path (Gemma 4 E2B via LiteRT-LM) provides tactical depth in 2–4s. CoachArbiter holds 78% of cues. Silence is coaching.
Private & Offline
Zero cloud dependency for the core coaching loop. All telemetry persists in local DuckDB on-device. Bridge binds to 127.0.0.1 only. Optional cloud Gemini debrief sends aggregate stats only — never raw frames.
Validated Cue Distribution
Sourced from 11,737 real Sonoma telemetry frames · BMW M3 E46
Architecture Breakdown
Hot Path · <50ms
Sonic model + RuleCoach deterministic engine. Zero LLM calls during driving. Grip tones, shift indicators, brake approach alerts. Pure TPU compute.
Warm Path · 2–4s
Gemma 4 E2B on-device via LiteRT-LM (MediaPipe Genai). Paddock brief & debrief. System prompt contains Bentley pedagogy + Sonoma corner doctrine.
Cold Path · 8–15s (Optional)
Cloud Gemini post-session debrief. Requires GEMINI_API_KEY. Sends aggregate stats only — zero raw telemetry frames. Graceful no-op without key.
Data Flow · End-to-End
Trust Gates · CoachArbiter Logic
Priority Levels
P3 Safety · P2 Technique
P1 Strategy · P0 Flavor
State Machine
OPEN → DELIVERING
→ COOLDOWN → BLACKOUT
Arbiter prevents LLM suggestions from overriding safety-critical deterministic grip tones. P0 safety always preempts any LLM output.
Latency Budget · Wall-Clock
| Component | Budget | Source |
|---|---|---|
| CAN frame → DuckDB row | < 5ms | can_reader.py |
| Hot path: sonic cue | < 50ms | ADR-002 |
| RuleCoach (in-process) | < 100ms | coach_engine.py |
| LiteRT-LM Gemma 4 E2B | 2–4s | ADR-012 |
| Capability recompute | < 200ms | ADR-015 |
| Cloud Gemini debrief | 8–15s | Optional |
| Smoke: 8,273 frames + 50 endpoints | ~12s | smoke_test.py |
Google Stack · On-Device First
| Layer | Component | Model / ID | Where |
|---|---|---|---|
| Hot | Sonic Model | Rule engine (no LLM) | sonic_model.py |
| Warm | LiteRT-LM + MediaPipe Genai | gemma-4-E2B-it.litertlm | LitertCoach |
| Warm | Pixel 10 TPU / AiCore | com.google.ai.edge | validate_litert.py |
| Cold | Gemini Debrief | gemini-2.5-flash (optional) | pitwall_bridge.py |
| Store | DuckDB + Parquet | Local-only, no sync | pitwall_bridge.py |
Bentley Curriculum · Pedagogical Vectors
| Vector | Condition | Beginner | Advanced |
|---|---|---|---|
| Weight Xfer | gLong/gLat spike | "Smooth it out" | "Load rate exceeded" |
| Trail Brake | Brake >10% + gLat >0.4g | "Carry brake in" | "Trail to apex" |
| Coasting | No throttle >30 km/h | "Leaving time out" | "6.3% lap in coast" |
| Braking | Overshoot | "Brake earlier" | "Compress zone 1" |
| Line | Early apex | "Wait to turn" | "Deepen entry" |
| Throttle | Post-apex hesitation | "Squeeze sooner" | "Verify traction" |
Sonoma Corner Doctrine
12 corners · 4,258m · 49m elevation range · OSM-derived GPS centerline
Late apex hairpin. Commitment to trail brake past the apex curb separates laps.
Double-apex. Trail brake past first apex. Commitment is everything. Common mistake: rushing throttle on exit → understeer.
Second apex of the Carousel. Patience on throttle — exit feeds the long back straight.
High-speed sweeper. Balance throttle through full arc. Trust the grip — coasting here loses 0.4s/lap.
Medium-speed, decreasing radius. Trail brake to hold mid-corner speed. Early throttle creates understeer.
Elevation change complicates braking. Use the curb on entry. T-Rod: "Distance is king" — don't compromise exit speed.
Off-camber. Use the curb — it's there for a reason. T-Rod: "Trust the curb." Entry commitment sets up T12 exit.
Last corner onto the main straight. Wide entry, late apex. Maximize throttle at apex — exit speed compounds onto the straight.
Analytics Surface
50 REST endpoints · 11 post-session analysers · DuckDB local
Technical Stack · As Shipped
| Layer | Technology | Details |
|---|---|---|
| Edge Compute | Pixel 10 + Termux | runit supervisor · Termux:Boot · Doze-safe via wake lock |
| On-Device LLM | Gemma 4 E2B · LiteRT-LM | MediaPipe Genai · gemma-4-E2B-it.litertlm · warm path only |
| CAN Ingest | python-can + cantools | USB-CAN adapter (CANable Pro / Macchina M2) · 29 signals · 9 messages · pitwall.dbc |
| Persistence | DuckDB + Parquet | Local-only · wide table (11 signals) + tall sink (any signal) · user-driven export |
| Bridge API | Flask · 50 routes | pitwall_bridge.py · 127.0.0.1:8765 · adb reverse tunnel for dev |
| Frontend | Vue 3 + Vite + Tailwind | GBA retro aesthetic · PWA manifest · pixel-art frames · in-progress (ADR-016) |
| Track Data | Sonoma JSON · OSM GPS | 139 KB · 12 corners · real GPS centerline · gold-standard lap · marker thumbnails |
| ML Models | LSTM v1 + v3 | Speed delta prediction · validated on 8,273 Sonoma frames |
| Testing | pytest · smoke suite | 289 passing · 0 skipped · 51 smoke assertions · virtual CAN bus (no kernel modules) |
Architecture Decision Records
17 ADRs · docs/adr/index.md
Split-Brain + Message Arbiter
Hot/warm/cold separation with priority queue. CoachArbiter holds 78% of cues.
Gemma 4 as Edge LLM
Gemma 4 E2B via LiteRT-LM for warm path. No cloud required for coaching loop.
Pedagogical Vector Retrieval
9 Bentley vectors encoded as retrieval keys. Every cue traces back to curriculum.
Graceful Degradation Protocol
Bridge dies → sonic_model fallback. LLM timeout → cached phrases. Network drops → Antigravity pipeline.
Universal Telemetry Sink
Wide table (11 canonical signals) + tall sink (any signal). 54-entry OBD2 signal registry. Any car, any feed.
Three-Tier Coach Architecture
Hot (no LLM) / Warm (Gemma 4 E2B) / Cold (optional Gemini). Audio-first with HUD fallback.
USB-CAN Ingest + Vue PWA
Pivot from BLE+Flutter to USB-CAN+Vue 3. GBA retro aesthetic. Same Flask backend bridges both.
Sensor Fusion · Racelogic + OBD
ASOF + lerp interpolation. Axis switching (GPS / lap-distance / signal-name). Uniform-grid resampling.
Mission Lifecycle · Day at Sonoma
Arrive
5 MIN
Hardware pair. GET /health. USB-CAN connect.
Pre-Brief
2–4 MIN
Set 1–3 goals. Gemma 4 reads weather, picks focus corners.
Out-Lap
1 LAP
P3 safety cues only. Sonic model at 50% volume. Sensor calibrate.
Hot Laps
4–8 LAPS
Full co-pilot. Audio + HUD. Cue volume scales with lap-time delta to goal.
Cool-Down
1 LAP
Chimes only. No coaching. Driver builds mental model.
Debrief
5–15 MIN
POST /coach/debrief. Lap table, friction circle, corner A–F grades.
Engineering & Pedagogy Team
Team 2 · Intermediate · BMW M3 E46
Hemanth HM
Tech Lead · Platform Arch
Simon Margolis
Edge · Telemetry
Taha Bouhsine
AGY Pipeline
Vijay Vivekanand
Data Reasoning
Aileen Villanueva
UX · Frontend
50 endpoints account_tree Architecture school Pedagogy
Bentley curriculum