Overview
Path following provides:- GPS waypoint recording - Capture paths by driving manually
- Autonomous navigation - Follow recorded paths with PID control
- Pure pursuit - Look-ahead path tracking algorithm
- Cross-track error - Distance from desired path
- Variable throttle - Replay recorded speeds or use constant throttle
- Real-time tuning - Adjust PID parameters while driving
System Requirements
- Position source: GPS, Intel T265, wheel encoders, or simulator
- Odometry: For pose estimation from encoders
- Controller: Joystick or web interface for path commands
Configuration
Configure path following inmyconfig.py:
donkeycar/templates/cfg_path_follow.py:637-675.
Position Sources
GPS
Intel RealSense T265
Wheel Encoders
Path Recording
TheCsvThrottlePath part records waypoints:
donkeycar/templates/path_follow.py:203-204.
Implementation
Fromdonkeycar/parts/path.py:80-94:
Save and Load
donkeycar/templates/path_follow.py:221-252.
Path file format (CSV):
x, y, throttle
Cross-Track Error
TheCTE part calculates distance from path:
donkeycar/templates/path_follow.py:280-281.
Algorithm
Fromdonkeycar/parts/path.py:406-432:
PID Control
ThePID_Pilot converts CTE to steering:
donkeycar/templates/path_follow.py:284-286.
Implementation
Fromdonkeycar/parts/path.py:435-458:
PID Tuning
Adjust PID parameters in real-time:donkeycar/templates/path_follow.py:288-388.
Tuning Guidelines
P (Proportional)- Controls steering strength in response to error
- Too high: oscillation and overshoot
- Too low: slow response, large tracking error
- Start: -0.5, adjust by ±0.25
- Eliminates steady-state error
- Usually keep at 0 for path following
- Can cause instability if too high
- Dampens oscillation and overshoot
- Too high: sensitive to noise
- Too low: overshoot and oscillation
- Start: -0.3, adjust by ±0.25
Visualization
Display path on web interface:donkeycar/templates/path_follow.py:270-438.
Origin Reset
Handle coordinate system drift:donkeycar/templates/path_follow.py:189-263.
This allows repositioning the car at the start point without restarting.
Complete Example
Typical path following workflow:Advanced Features
GPS Playback
Replay GPS NMEA sentences for testing:donkeycar/templates/path_follow.py:463-469.
Search Optimization
Limit search range for performance:Variable Throttle
Replay recorded throttle values:Best Practices
- Close the loop - Make start and end points close
- Smooth driving - Record at steady speed for best results
- Tune progressively - Start with low gains, increase slowly
- Test in stages - Verify recording, then test following
- Monitor CTE - Enable logging to debug tracking issues
- Reset origin - If coordinates drift, reset before running
Troubleshooting
Path Not Saving
Poor Tracking
- Increase P gain for stronger correction
- Increase D gain to reduce oscillation
- Lower throttle to allow more reaction time
- Verify position source accuracy
Oscillation
- Decrease P gain
- Increase D gain
- Lower throttle
- Increase PATH_LOOK_AHEAD
Wrong Path Section
- Decrease PATH_SEARCH_LENGTH
- Avoid crossing paths
- Use RESET_ORIGIN at start
Next Steps
- Use kinematics for encoder-based positioning
- Add telemetry to monitor CTE and PID values
- Test in simulator before real-world deployment
