Tub (v2)
The primary datastore class for recording and reading driving data. Constructor:str
Path to tub directory
list
default:"[]"
List of input channel names (e.g., [‘cam/image_array’, ‘user/angle’])
list
default:"[]"
List of data types corresponding to inputs (e.g., [‘image_array’, ‘float’])
list
default:"[]"
List of metadata key:value pairs
int
default:"1000"
Maximum catalog size before flushing
bool
default:"false"
Open tub in read-only mode
'float': Floating point numbers'int': Integers'str': Strings'boolean': Boolean values'image_array': NumPy image arrays (saved as JPEG)'gray16_array': 16-bit grayscale images (saved as PNG)'nparray': Generic NumPy arrays (saved as list)'list'or'vector': Lists of values
(record: dict) -> None
Write a single record to the tub
(record_indexes: list) -> None
Delete specific records by index
(n: int) -> None
Delete the last N records
(record_indexes: list) -> None
Restore previously deleted records
() -> None
Close the tub and flush data
() -> Iterator
Iterate over all records in the tub
() -> int
Get number of records in the tub
TubWriter
Donkeycar part for writing records to a tub. Constructor:str
Path to tub directory
list
List of input channel names
list
List of data types
list
Metadata key:value pairs
(*args) -> int
Donkeycar part interface. Accepts values matching inputs list and writes record. Returns current record index.
() -> None
Close the tub
TubHandler
Helper class for managing multiple tubs. Constructor:str
Base path containing tubs
(path: str) -> list
Get list of tub directories
(path: str) -> int
Get next available tub number
() -> str
Create a new tub path with incremented number and date
(inputs, types, user_meta) -> TubWriter
Create a new TubWriter with auto-generated path
TubWiper
Part for deleting recent records during recording (delete bad data on the fly). Constructor:Tub or TubWriter
Tub to operate on
int
default:"20"
Number of records to delete when triggered
(is_delete: bool) -> None
Delete records when trigger switches from False to True (debounced)
Legacy Tub (v1)
Older tub implementation (deprecated, use Tub v2 instead). Constructor:Record Structure
Record Format
Each record contains:- User-defined fields (inputs)
- Private metadata:
_timestamp_ms: Timestamp in milliseconds_index: Record index_session_id: Recording session ID
Example Record
Tub Directory Structure
Manifest File
The manifest.json contains:- Input channel names and types
- Metadata
- Current index
- Session information
- Record catalog
Configuration
Typical datastore configuration inmyconfig.py:
Integration Example
From templates likecomplete.py:
