Skip to main content
Learn how to create custom parts to extend Donkeycar with new sensors, algorithms, and behaviors.

The Part Interface

A Donkeycar part is a Python class that implements a simple interface:

Method Reference

  • run(*args) - Synchronous execution in main loop
  • run_threaded(*args) - Returns cached values from background thread
  • update() - Runs continuously in background thread
  • shutdown() - Cleanup (close files, stop threads, release hardware)

Basic Synchronous Part

Simple parts that execute in the main vehicle loop.

Example: Throttle Limiter

Example: Data Logger

Threaded Parts

Parts that run continuously in the background for I/O operations.

Example: Distance Sensor

Example: Web API Client

Advanced Patterns

State Machine Part

Filter Part

Conditional Execution

Multi-Input/Output Parts

Example: Sensor Fusion

Testing Your Part

Unit Test Example

Standalone Testing

Packaging Your Part

Directory Structure

setup.py

Installation

Best Practices

1. Error Handling

2. Configuration

In myconfig.py:

3. Documentation

4. Type Hints

Common Patterns

Lazy Initialization

Caching Results

Debugging

Add Logging

Next Steps

  • Study existing parts in donkeycar/parts/
  • Share your parts with the community
  • Contribute to Donkeycar on GitHub
  • Join the Donkeycar Discord for help