Overview
GPS autopilot allows your car to:- Record paths by driving manually
- Save waypoints as GPS coordinates (converted to local meters)
- Follow paths autonomously using cross-track error (CTE) and PID control
- Navigate outdoors on large courses
- GPS module (serial NMEA interface)
- Open sky for GPS signal
- Odometry sensors (optional, but recommended)
- Intel RealSense T265 (optional, for visual-inertial odometry)
Template Setup
The path following template is available atdonkeycar/templates/path_follow.py:
System Architecture
The GPS autopilot system consists of:- Position Sources: GPS, wheel odometry, or T265 camera
- Path Recording: Store (x,y) waypoints with throttle values
- Cross-Track Error: Calculate distance from path
- PID Control: Steer back toward path
- Visualization: Real-time map display
Configuration
Configure GPS navigation inmyconfig.py:
GPS Module
Supported GPS
Any GPS module with NMEA serial output:- u-blox NEO-M8N
- Adafruit Ultimate GPS
- Generic USB GPS receivers
GPS Connection
GPS Data Flow
- Latitude: 38.115381° N
- Longitude: -122.594060° W
- UTM: (551234.56, 4219876.54) meters
Position Sources
Different ways to get position (x, y): 1. GPS only:Path Recording
The path is recorded as a sequence of (x, y, throttle) waypoints.Path Classes
CsvThrottlePath - Records waypoints with throttle values:Recording Workflow
- Start car:
python manage.py drive - Begin recording: Press ‘R’ on web UI or configured button
- Drive path: Drive the desired route manually
- Stop recording: Press ‘R’ again
- Save path: Press SAVE_PATH_BTN (default: ‘R1’)
- Path saved: Waypoints saved to
PATH_FILENAME
Origin Management
Manage coordinate origin for consistent path following:- Start path at known position
- Align path after loading
- Recover from GPS drift
Cross-Track Error (CTE)
CTE calculates perpendicular distance from current position to nearest path segment.CTE Algorithm
look_ahead: Waypoints ahead of closest point to include in segmentlook_behind: Waypoints behind closest point to include in segmentnum_pts: Maximum waypoints to search (optimization for long paths)
PID Control
PID controller converts CTE into steering commands.PID Pilot
PID Tuning
Tuning guide:-
Start with P only: Set P=0.1, I=0, D=0
- Too low: Doesn’t reach path
- Too high: Oscillates
-
Add D term: Increase D to dampen oscillations
- D=0.01 to 0.05 typically
-
Add I term (optional): Eliminates steady-state error
- Usually not needed for path following
- GPS only: P=0.2, I=0.0, D=0.02
- T265: P=0.3, I=0.0, D=0.03
- Odometry: P=0.25, I=0.0, D=0.025
Path Visualization
Real-time map display of path and position.Visualization Parts
- Red line: Recorded path
- Green dot: Current position (user mode)
- Blue dot: Current position (autopilot mode)
GPS Playback
Replay recorded GPS data for testing:- Test path following indoors
- Replay actual GPS signal
- Debug without GPS module
Complete Workflow
1. Setup Hardware
- Connect GPS module to serial port
- (Optional) Install wheel encoders
- (Optional) Mount Intel T265 camera
2. Configure Car
3. Record Path
4. Follow Path
5. Tune Performance
- Adjust PID gains using increment/decrement buttons
- Modify PATH_LOOK_AHEAD/BEHIND for smoother/tighter following
- Change PATH_MIN_DIST for more/fewer waypoints
Advanced Features
Variable Speed
Follow path at recorded speeds:- Speed up on straights (where you drove fast)
- Slow down on curves (where you drove slow)
Waypoint Detection
Detect when reaching specific waypoints:Differential Drive
Path following works with differential drive:Troubleshooting
GPS not working:- Check serial port:
ls /dev/ttyUSB*or/dev/ttyACM* - Verify baudrate matches GPS module
- Ensure GPS has clear view of sky
- Wait for GPS fix (can take 30+ seconds)
- Check PID gains (start with P only)
- Increase PATH_LOOK_AHEAD for smoother following
- Verify origin is reset at path start
- Check CTE signs (may need to invert)
- Use T265 for better accuracy
- Fuse wheel odometry with T265
- Reduce PATH_MIN_DIST for more waypoints
- Drive slower during recording
- Reduce P gain
- Increase D gain
- Check for mechanical play in steering
Next Steps
- Deep Learning Models - Combine GPS with neural networks
- Computer Vision - Alternative CV-based navigation
- Odometry - Configure wheel encoders
- Sensors - Add IMU and other sensors
