DriveSense AI: Gradient-Based Behavioral Classification for Racing Telemetry
Inspiration
I do a lot of playing around with F1 data and a few months ago I built a telemetry animation tool to compare qualifying laps. It gave me the idea to try to build a tool that could programmatically identify where and why a driver lost time in a lap.
After discussions with an industry expert, I was encouraged to explore gradient-based analysis (using derivatives of driver inputs) to try to identify both where and why time was lost by analyzing the rate of change in steering, brake, and throttle inputs to distinguish intentional technique variations from unintended errors.
The problem: F1's publicly available data stream was ultimately too low resolution to use. With only a handful of data points per lap, calculating reliable derivatives was impossible. I haven't scrapped the idea entirely, but it's been on the backburner for several months. Without access to higher resolution data, the thresholds can't be refined enough to be useable.
The opportunity: Hack the Track. With more complete, high resolution datasets, I immediately thought this might be a great opportunity to actually try out my idea.
The insight: Stop analyzing outputs (speed). Start analyzing inputs (steering/brake/throttle derivatives) that directly correlate to speed instead. Don't ask "how fast," ask "what did the driver do, why, and to what effect?"
What It Does
DriveSense AI uses gradient-based behavioral classification to automatically distinguish between:
- Driver mistakes - detectable errors requiring mid-corner corrections
- Different racing lines - intentional technique variations
- Brake technique differences - modulation and application patterns
Instead of showing "you were 0.3s slow in Turn 5," it explains "you made a steering correction at Turn 5 apex due to late braking, with 87% confidence."
Features
Single Lap Comparison
Corner-by-corner analysis of two laps with:
- Gradient-based behavioral classification per corner
- Confidence scoring with evidence-based recommendations
- Sector time deltas and top speed comparison
- Corner telemetry overlays (steering, brake, throttle)
Multi-Lap Consistency
Stint-level performance analysis with:
- Lap time consistency scoring (coefficient of variation)
- Corner-by-corner consistency metrics
- Performance trend detection (improving/stable/declining)
- Outlier lap identification (>2σ threshold)
- Sector-level consistency tracking
Live Session Monitoring
Real-time analysis pipeline with:
- File watcher for incoming telemetry (watchdog library)
- Per-lap gradient analysis vs. baseline
- Rolling consistency metrics (updates after 3+ laps)
- Alert system for repeated mistakes or declining performance
- Flag condition filtering (excludes yellow flag laps)
- Demo mode for session replay
Technical Approach
Core Innovation: Input Derivative Analysis
Traditional analysis:
$$\Delta t = f(\text{speed}, \text{distance})$$
DriveSense approach:
$$\text{Classification} = f\left(\frac{d\theta}{ds}, \frac{d^2\theta}{ds^2}, \frac{dp_{\text{brake}}}{ds}\right)$$
Where:
- θ = steering angle
- s = distance along track
- p_brake = brake pressure
Classification Algorithm
Mistake Detection:
- High steering jerk: second derivative exceeds 2× baseline
- Asymmetric correction patterns in gradient profile
- Confidence scoring via ratio metrics
Mathematical condition:
$$\frac{d^2\theta}{ds^2} > 2 \times \text{baseline}$$
Line Differentiation:
- Different peak gradients but controlled variance
- Smooth profiles throughout corner (no spikes)
- Geometric deviation quantification
Mathematical Foundation:
Savitzky-Golay filtering for noise reduction:
$$\theta_{smooth}(s) = \sum_{n=-m}^{m} c_n \theta(s + n\Delta s)$$
Then compute first and second derivatives:
$$\frac{d\theta}{ds} = \nabla \theta_{smooth}$$
$$\frac{d^2\theta}{ds^2} = \nabla^2 \theta_{smooth}$$
Classification thresholds based on derivative ratios and consistency metrics.
How I Built It
Datasets Used
Toyota GR Cup Series 2024 Telemetry Data
Tracks:
- Barber Motorsports Park
- Indianapolis Motor Speedway
Specific Files Used:
Barber Motorsports Park:
Raw data:
- Telemetry CSV file (1.5-3GB, long format with telemetry_name/telemetry_value pairs)
- AnalysisEnduranceWithSectionsRace1.CSV
- AnalysisEnduranceWithSectionsRace2.CSV
Processed data:
- processed_data/barber/metadata.json
- processed_data/barber/[vehicle_id]R1_lap[N].csv (individual lap files)
- processed_data/barber/[vehicle_id]R2_lap[N].csv
Indianapolis Motor Speedway:
Raw data:
- Telemetry CSV file (1.5-3GB, long format with telemetry_name/telemetry_value pairs)
- AnalysisEnduranceWithSectionsRace1.CSV
- AnalysisEnduranceWithSectionsRace2.CSV
Processed data:
- processed_data/indianapolis/metadata.json
- processed_data/indianapolis/[vehicle_id]R1_lap[N].csv (individual lap files)
- processed_data/indianapolis/[vehicle_id]R2_lap[N].csv
Data parameters:
- Steering angle, brake pressure (front/rear), throttle position
- Speed, GPS coordinates, accelerations
- Distance markers (lapdist_dls)
- Lap times, sector times (S1, S2, S3), flag conditions
- Multiple vehicles per race, 2 races per track
Stack:
- Python 3.10+ (pandas, numpy, scipy)
- Streamlit for dashboard
- Savitzky-Golay filters for derivative smoothing
- Provided GR Cup telemetry data
Architecture:
- Data preprocessing - Pivot long-format telemetry to wide format, deduplicate laps
- Corner extraction - GPS + steering-based corner detection
- Gradient analysis - Calculate first and second derivatives with smoothing
- Behavioral classification - Threshold-based decision tree with confidence scoring
- Visualization pipeline - Per-corner overlays of steering/brake/throttle
Challenges Faced
1. Data Quality Issues
- Problem: Telemetry stored in long format with duplicate lap records
- Solution: Timestamp-based deduplication, dynamic pivoting, graceful degradation when columns missing
2. GPS Data Sparsity
- Problem: Only 1 of 7 tracks had complete distance and GPS telemetry
- Solution: Built aggregate lap-level analysis as fallback
3. Corner Detection Without Speed
- Problem: Traditional corner detection uses minimum speed points, which can miss high-speed corners
- Solution: Developed steering angle + brake pressure based detection, uses track-based fixed locations and GPS data
4. Gradient Noise
- Problem: Raw derivatives too noisy for reliable classification
- Solution: Savitzky-Golay filtering (window=5, polyorder=2) before gradient calculation
5. Classification Confidence
- Problem: Binary classifications aren't useful alone, we need confidence scores
- Solution: Ratio-based confidence metrics scaled 0-1 based on derivative magnitude differences
What I Learned
Technical:
- Scipy's signal processing capabilities for real-world noisy data
- Streamlit's session state management for complex multi-page apps
- The importance of graceful degradation with messy real-world datasets
Domain:
- Speed is a lagging indicator - steering/brake inputs are leading indicators
- Corner-by-corner analysis is useful, but behavioral classification is the actual value
- Engineers and drivers need "why" more than "where". Causal attribution drives improvement
What's Next
- Real-time mode: Integrate with live telemetry feeds for in-session coaching (see an example of this with the live session demo)
- Multi-lap consistency: Track behavioral pattern degradation (fatigue, tire wear)
- Setup correlation: Link behavioral patterns to setup changes (need more detailed data)
- Driver development: Build historical profiles to track skill progression
Why This Matters
Motorsport telemetry analysis hasn't fundamentally changed in 20 years. We're still drawing lines on speed traces and guessing at causality. DriveSense AI brings behavioral psychology to telemetry by understanding driver actions, not just car performance.
For drivers getting limited track time, every lap matters. And for most non-professional racing drivers, having access to a knowledgeable enough engineer to give in-the-moment feedback is a luxury. DriveSense AI fills this gap by providing the ability to know immediately how your driver inputs are impacting laptime and overall performance.
Log in or sign up for Devpost to join the conversation.