What are Templates?
Templates are complete working applications located indonkeycar/templates/. Each template:
- Assembles parts into a functional vehicle
- Configures the drive loop
- Provides command-line interfaces
- Includes configuration options
- Serves as examples for building custom vehicles
Available Templates
1. Complete Template (complete.py)
Purpose: Full-featured autonomous car with machine learning autopilot
Location: donkeycar/templates/complete.py
Features:
- Camera input (multiple types supported)
- Web and joystick control
- ML model inference (Keras, PyTorch, TensorFlow Lite)
- Data recording (TubWriter)
- Autopilot mode with model hot-reloading
- Drivetrain control (servo, ESC, differential drive)
- Optional sensors (IMU, LIDAR, odometry, GPS)
- LED status indicators
- Simulator support (Donkey Gym)
- Telemetry publishing
- FPV video streaming
complete.py:50-576:
cfg_complete.py):
The complete template is the most commonly used. It includes everything you need for collecting training data and running an autopilot.
2. Basic Template (basic.py)
Purpose: Minimal car for manual driving and data collection
Location: donkeycar/templates/basic.py
Features:
- Camera input
- Web or joystick control
- Simple data recording
- Optional autopilot
- Minimal dependencies
basic.py:51-204:
3. Path Follow Template (path_follow.py)
Purpose: Follow a recorded path using odometry or GPS
Location: donkeycar/templates/path_follow.py
Features:
- Path recording and playback
- Cross-track error (CTE) calculation
- PID steering control
- Odometry/pose estimation (wheel encoders)
- Optional Intel RealSense T265 tracking
- Optional GPS positioning
- Path visualization
- Save/load/reset paths via buttons
path_follow.py:74-442:
cfg_path_follow.py):
- Drive manually to record a path
- Press save button to save path
- Reset car to start position
- Switch to autopilot mode
- Car follows recorded path using PID control
4. Computer Vision Control (cv_control.py)
Purpose: Drive using computer vision (line following, object detection)
Location: donkeycar/templates/cv_control.py
Features:
- Real-time computer vision processing
- PID-based steering control
- Configurable CV algorithm (plug in your own)
- No ML training required
- Live image overlay showing detection
cv_control.py:37-260:
cfg_cv_control.py):
5. Simulator Template (simulator.py)
Purpose: Run in Donkey Gym simulator
Location: donkeycar/templates/simulator.py
Features:
- Connects to Donkey Gym simulator
- Same API as physical car
- Records simulated sensor data
- Test models in simulation
- Includes brake control
- Optional sensor recording (lidar, IMU, velocity)
simulator.py:36-423:
cfg_simulator.py):
The simulator template allows you to develop and test without physical hardware. Models trained in simulation can be transferred to real cars, though performance may vary.
Template Selection Guide
Common Template Structure
All templates follow a similar pattern:Customizing Templates
1. Copy Template to Your Project
manage.py based on the complete template.
2. Modify manage.py
Add custom parts:3. Adjust Configuration
Editmyconfig.py:
Helper Functions
Templates use helper functions for common setup:add_camera()
Fromcomplete.py:832-901:
add_user_controller()
Fromcomplete.py:687-760:
add_drivetrain()
Fromcomplete.py:942-1148:
Creating Your Own Template
Best Practices
- Start with existing template: Modify rather than create from scratch
- Use helper functions: Reuse
add_camera(),add_drivetrain(), etc. - Keep configuration in myconfig.py: Don’t hardcode values
- Document changes: Add comments explaining modifications
- Test incrementally: Add one part at a time and test
- Version control: Track changes to manage.py
Next Steps
- Learn about the Architecture that templates build on
- Understand the Vehicle Loop that runs templates
- Study Parts to create custom components
- Explore the Memory system for data flow
