What is a Tub?
A tub is Donkeycar’s data storage format that records:- Camera images (as JPG files)
- Steering and throttle inputs
- Sensor data (IMU, GPS, odometry)
- Timestamps
- Metadata
Tub Structure
Collecting Training Data
Basic Data Collection
Start your car in user mode to collect data:http://<your-car-ip>:8887:
- Start Recording - Click the recording button or toggle via joystick
- Drive Manually - Use keyboard, gamepad, or web interface
- Stop Recording - Click recording button again when done
Recording Controls
Keyboard (Web UI):i/k- Throttle forward/backwardj/l- Steer left/rightr- Toggle recording
- Configure buttons in
myconfig.py - Default: Right bumper toggles recording
Auto-Recording
Enable automatic recording when throttle is applied:Data Collection Best Practices
Quality Over Quantity
Good driving data:- Smooth, consistent steering
- Varied track positions (center, left, right)
- Recovery examples (moving from edge back to center)
- Multiple laps with different lighting
- Jerky, erratic steering
- Stopped or very slow sections
- Crashes or off-track driving
- Excessive overfitting to one line
How Much Data?
| Track Complexity | Recommended Frames | Drive Time (20 FPS) |
|---|---|---|
| Simple oval | 5,000-10,000 | 4-8 minutes |
| Medium circuit | 10,000-20,000 | 8-17 minutes |
| Complex track | 20,000-40,000 | 17-33 minutes |
Diverse Examples
Collect data showing:- Centerline driving - Smooth laps staying centered
- Recovery maneuvers - Moving from edges back to center
- Different positions - Left side, right side of track
- Various speeds - Fast straightaways, slow corners
TubWriter Class
Donkeycar’sTubWriter part handles data recording:
base_path- Directory to store tub datainputs- List of data keys to recordtypes- Data types for each inputrun_condition- Only runs when condition is True
image_array- Numpy arrays saved as JPGfloat- Floating point numbersint- Integersstr- Stringsboolean- Boolean valueslist,vector- Lists of values
Writing Records
The TubWriter automatically saves records each frame:Managing Tubs
View Tub Data
Inspect tub contents:Clean Bad Data
Remove problematic frames:- View images and telemetry
- Delete individual frames
- Remove ranges of frames
- Filter by criteria
Combine Multiple Tubs
Merge tubs for training:Tub Commands
Tub Format (V2)
Donkeycar uses an efficient tub format: meta.json:- Reduces JSON file size
- Enables efficient image loading
- Supports lazy loading during training
Data Quality Tips
Lighting Conditions
- Collect data in similar lighting to race conditions
- If lighting varies, collect examples in multiple conditions
- Avoid extreme shadows or glare
Track Coverage
- Drive both directions if track is reversible
- Include all turns and track sections
- Don’t over-represent easy sections
Recovery Examples
20% of data should show recovery:- Position car near track edge
- Start recording
- Steer back toward center
- Stop recording
- Repeat at different locations
Throttle Consistency
For best results:- Maintain consistent speed throughout laps
- Match training speed to desired race speed
- Consider using constant throttle mode
Advanced: Custom Data Recording
Recording Additional Sensors
Filtering During Recording
Only record when conditions are met:Next Steps
Train Deep Learning Model
Use collected data to train a neural network autopilot
Data Augmentation
Learn how to augment data during training
