Skip to main content
High-quality training data is essential for creating effective deep learning autopilots. Donkeycar stores driving data in tubs - directories containing sensor readings, images, and control inputs.

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:
Navigate to the web interface at http://<your-car-ip>:8887:
  1. Start Recording - Click the recording button or toggle via joystick
  2. Drive Manually - Use keyboard, gamepad, or web interface
  3. Stop Recording - Click recording button again when done

Recording Controls

Keyboard (Web UI):
  • i/k - Throttle forward/backward
  • j/l - Steer left/right
  • r - Toggle recording
Gamepad:
  • 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
Avoid:
  • Jerky, erratic steering
  • Stopped or very slow sections
  • Crashes or off-track driving
  • Excessive overfitting to one line

How Much Data?

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’s TubWriter part handles data recording:
Key parameters:
  • base_path - Directory to store tub data
  • inputs - List of data keys to record
  • types - Data types for each input
  • run_condition - Only runs when condition is True
Supported types:
  • image_array - Numpy arrays saved as JPG
  • float - Floating point numbers
  • int - Integers
  • str - Strings
  • boolean - Boolean values
  • list, vector - Lists of values

Writing Records

The TubWriter automatically saves records each frame:
Each record contains:

Managing Tubs

View Tub Data

Inspect tub contents:

Clean Bad Data

Remove problematic frames:
This opens an interface to:
  • 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:
manifest.json:
Images stored separately:
  • 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:
  1. Position car near track edge
  2. Start recording
  3. Steer back toward center
  4. Stop recording
  5. 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