Skip to content
pilotpalaiPublic

About

theappthough

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Pilot Pal

AI-powered driving coach that watches how you drive, gives real-time audio feedback, and generates post-drive analysis with video clips.

Pilot Pal turns your phone into a dashcam with a brain. Mount it below your rearview mirror and let the AI observe your driving in real time. It combines computer vision with onboard sensor data (gyroscope, accelerometer, GPS) to track braking behavior, turning smoothness, speed compliance, and safety violations. When you do something wrong, it tells you out loud. When the drive ends, it gives you a full breakdown with specific clips showing what happened.


How It Works

  1. Mount your phone under the rearview mirror facing the road
  2. Start a drive session in the app
  3. Drive normally. Pilot Pal runs continuous analysis in the background
  4. Get real-time audio warnings if you exceed the speed limit, brake too hard, or commit a safety violation
  5. End the drive (auto-detected when the car enters park mode)
  6. Review your summary: an AI-generated driving report with scores, specific feedback, and flagged video clips

Core Features

Real-Time Vision Analysis

A vision model processes the live camera feed to detect lane positioning, traffic signs (including speed limit signs), traffic lights, pedestrians, following distance, and turn execution. Combined with phone GPS speed, the system cross-references visual speed estimation against actual speed and posted limits.

Sensor Fusion

The phone's gyroscope and accelerometer provide high-frequency data on braking force, acceleration patterns, lateral g-forces during turns, and overall vehicle stability. This data is fused with the vision pipeline to produce a unified picture of driving behavior.

Driving Metrics Index

Every drive session produces scored metrics:

Metric What It Measures
Braking Score How smooth and controlled your braking is. Penalizes hard stops and late braking
Turn Smoothness Lateral g-force consistency through turns. Rewards gradual, even steering input
Speed Compliance Percentage of drive time at or below the posted speed limit
Following Distance Estimated gap to the vehicle ahead using vision-based depth estimation
Lane Discipline How centered and stable you stay within your lane
Overall Safety Composite score weighted across all metrics, with violations as hard penalties

Real-Time Audio Feedback

Text-to-speech warnings triggered by:

  • Exceeding the speed limit
  • Hard braking events
  • Unsafe following distance
  • Running red lights or stop signs
  • Erratic lane behavior

Audio cues are short, direct, and non-distracting. Example: "You're 12 over the limit. Slow down."

Post-Drive Summary

When the car enters park (detected via accelerometer stillness + GPS velocity near zero), the app generates:

  • An AI-written summary of the overall drive quality
  • Per-metric scores with specific explanations
  • Flagged video clips with timestamps showing exactly what went wrong
  • Trend data if the user has previous sessions

Clip Extraction and Playback

During the drive, the app continuously records video in a rolling buffer. When a violation or notable event is detected, the surrounding clip (a few seconds before and after) is saved to memory. These clips are surfaced in the post-drive summary with annotations explaining the issue.


Technical Architecture

System Overview

┌─────────────────────────────────────────────────────┐
│                    PILOT PAL APP                    │
│                                                     │
│  ┌──────────┐  ┌──────────┐  ┌───────────────────┐ │
│  │  Camera   │  │  Sensors │  │   GPS / Speed     │ │
│  │  Feed     │  │  Gyro +  │  │   Provider        │ │
│  │  (30fps)  │  │  Accel   │  │                   │ │
│  └────┬─────┘  └────┬─────┘  └────────┬──────────┘ │
│       │              │                 │            │
│       ▼              ▼                 ▼            │
│  ┌──────────────────────────────────────────────┐   │
│  │           Sensor Fusion Engine                │   │
│  │  Synchronizes vision + IMU + GPS streams      │   │
│  └──────────────────┬───────────────────────────┘   │
│                     │                               │
│       ┌─────────────┼─────────────┐                 │
│       ▼             ▼             ▼                 │
│  ┌─────────┐  ┌──────────┐  ┌──────────┐           │
│  │ Vision  │  │ Driving  │  │  Audio   │           │
│  │ Model   │  │ Behavior │  │ Feedback │           │
│  │ (on-    │  │ Analyzer │  │ (TTS)    │           │
│  │ device) │  │          │  │          │           │
│  └────┬────┘  └────┬─────┘  └──────────┘           │
│       │            │                                │
│       ▼            ▼                                │
│  ┌──────────────────────────────────────────────┐   │
│  │           Event Logger + Clip Buffer          │   │
│  │  Rolling video buffer, event timestamps       │   │
│  └──────────────────┬───────────────────────────┘   │
│                     │                               │
│                     ▼                               │
│  ┌──────────────────────────────────────────────┐   │
│  │        Post-Drive Summary Generator           │   │
│  │  LLM-powered report + clip selection          │   │
│  └──────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────┘

Recommended Tech Stack

Mobile Framework

  • React Native with Expo for cross-platform (iOS + Android)
  • VisionCamera (react-native-vision-camera) for high-performance camera access with frame processor plugins
  • Native modules for sensor access where Expo defaults are insufficient

On-Device Vision Model

  • YOLOv8-Nano or YOLOv8-Small via CoreML (iOS) / TensorFlow Lite (Android) for real-time object detection (vehicles, signs, pedestrians, traffic lights)
  • MobileSAM or a lightweight segmentation model for lane detection
  • PaddleOCR Mobile for reading speed limit signs and other road text
  • Target: 15-30 fps inference on recent phones (iPhone 12+, Pixel 6+)

Depth and Distance Estimation

  • Depth Anything V2 (Small) quantized to INT8 for monocular depth estimation
  • Used for following distance calculation and relative vehicle speed estimation

Sensor Processing

  • react-native-sensors or Expo Sensors API for gyroscope and accelerometer streams at 100Hz
  • Custom Kalman filter for sensor fusion (smoothing IMU noise, combining with GPS)
  • Braking detection via accelerometer z-axis spike thresholding + gyroscope pitch rate

Speed and Location

  • GPS speed from expo-location or native CLLocationManager / FusedLocationProvider
  • Speed limit data from OpenStreetMap Overpass API or HERE Maps Speed Limit API
  • Visual speed limit sign detection as a secondary cross-reference

Audio Feedback

  • Expo Speech (expo-speech) or native TTS APIs
  • Priority queue system so warnings don't overlap or spam the driver
  • Configurable cooldown between repeated warnings of the same type

Post-Drive Summary Generation

  • Claude API (Anthropic) or GPT-4o for natural language summary generation
  • Input: structured JSON of all events, scores, and timestamps from the drive session
  • Output: conversational summary with specific callouts and improvement suggestions

Data Storage

  • SQLite (via expo-sqlite) for local session history and metrics
  • AsyncStorage for user preferences and settings
  • Video clips stored in app sandbox filesystem, pruned after configurable retention period

Optional Cloud Sync

  • Supabase or Firebase for cross-device session history
  • Cloud storage (S3 / Supabase Storage) for clip backup if the user opts in

Project Structure

pilotpal/
├── app/                    # Expo Router screens
│   ├── (tabs)/             # Tab navigation (Drive, History, Settings)
│   ├── drive/              # Active drive session screen
│   ├── summary/            # Post-drive summary screen
│   └── clip/               # Clip playback screen
├── modules/
│   ├── vision/             # Vision model integration, frame processors
│   ├── sensors/            # Gyroscope, accelerometer, GPS fusion
│   ├── analysis/           # Driving behavior scoring algorithms
│   ├── audio/              # TTS feedback engine
│   ├── clips/              # Rolling buffer, clip extraction
│   └── summary/            # LLM-powered summary generation
├── models/                 # On-device ML model files (.tflite, .mlmodel)
├── assets/                 # Icons, fonts, sounds
├── lib/                    # Shared utilities, types, constants
└── scripts/                # Model conversion, data processing tools

Getting Started

Prerequisites

  • Node.js 18+
  • Expo CLI (npm install -g expo-cli)
  • Xcode 15+ (iOS) or Android Studio (Android)
  • A physical device (camera + sensors required, simulators won't work)

Install

git clone https://github.com/pilotpalai/pilotpal.git
cd pilotpal
npm install

Run

# iOS
npx expo run:ios --device

# Android
npx expo run:android --device

Environment Variables

Create a .env file in the project root:

ANTHROPIC_API_KEY=sk-ant-...       # For post-drive summary generation
HERE_API_KEY=...                    # For speed limit data (optional)
SUPABASE_URL=...                   # For cloud sync (optional)
SUPABASE_ANON_KEY=...              # For cloud sync (optional)

Model Pipeline

Task Model Format Target Latency
Object detection (cars, signs, lights, pedestrians) YOLOv8n / YOLOv8s CoreML / TFLite <30ms per frame
Lane detection Custom lightweight U-Net or MobileSAM CoreML / TFLite <40ms per frame
Speed limit sign OCR PaddleOCR Mobile CoreML / TFLite <50ms per frame
Monocular depth estimation Depth Anything V2 Small (INT8) CoreML / TFLite <60ms per frame
Post-drive summary Claude 3.5 Sonnet / GPT-4o Cloud API <5s per summary

All on-device models should be benchmarked on target hardware. If combined inference exceeds frame budget, run models on alternating frames or reduce resolution.


Scoring Algorithm (Overview)

Braking Score: Calculated from accelerometer magnitude spikes. A hard brake is defined as deceleration exceeding a configurable threshold (default: -0.4g). Score decreases proportionally to frequency and severity of hard brakes relative to total drive time.

Turn Smoothness: Lateral acceleration (gyroscope + accelerometer y-axis) is sampled through each detected turn. Jerk (rate of change of acceleration) is computed. Lower jerk means smoother turns. Scored on a 0-100 scale based on jerk distribution percentiles.

Speed Compliance: (time at or below speed limit) / (total drive time) * 100. Excess speed is weighted by magnitude (5 over is penalized less than 20 over).

Overall Safety: Weighted composite of all sub-scores with binary violation penalties (running a red light is an automatic deduction regardless of other scores).


Roadmap

  • Core camera pipeline with VisionCamera frame processors
  • Sensor fusion engine (gyro + accel + GPS)
  • YOLOv8 integration for object detection
  • Speed limit sign detection and OCR
  • Real-time TTS warning system
  • Rolling video buffer and clip extraction
  • Driving metrics scoring engine
  • Post-drive summary with LLM
  • Clip playback in summary view
  • Session history and trend tracking
  • Cloud sync (optional)
  • Onboarding and calibration flow

Contributing

Open an issue or submit a PR. If you're working on a major feature, open a discussion first so we can coordinate.


License

MIT

About

theappthough

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages