Skip to main content
Sensor parts provide additional data about your vehicle’s state and environment.

IMU (Inertial Measurement Unit)

Measures acceleration, rotation, and orientation. Location: donkeycar/parts/imu.py:9

Supported Sensors

  • MPU6050: 6-axis (accelerometer + gyroscope)
  • MPU9250: 9-axis (accelerometer + gyroscope + magnetometer)
Installation:
Enable I2C:
Usage:
Outputs:
  • Accelerometer (m/s²): Linear acceleration on X, Y, Z axes
  • Gyroscope (rad/s): Angular velocity on X, Y, Z axes
  • Temperature (°C): Die temperature
  • Magnetometer (MPU9250 only, μT): Magnetic field on X, Y, Z axes
Digital Low-Pass Filter:
Testing:

GPS

Global positioning from NMEA-compatible GPS modules. Location: donkeycar/parts/gps.py

GpsNmeaPositions

Converts NMEA sentences to UTM coordinates.
Outputs:
  • List of (timestamp, x, y) tuples
  • x, y in UTM coordinates (meters)

GpsPosition

Combined GPS reader that returns the latest position. Location: donkeycar/parts/gps.py:54
NMEA Parsing: Supports GPRMC and GNRMC sentences:
Parsed to:
  • Latitude/Longitude in degrees
  • Converted to UTM (x, y) in meters
  • Timestamp from sentence
Hardware Setup:
Installation:
Testing:

Encoders

Measure wheel rotation for odometry and velocity. Note: The encoder.py module is deprecated. Use tachometer.py and odometer.py instead.

Rotary Encoder (Legacy)

Location: donkeycar/parts/encoder.py:128 GPIO-based rotary encoder (deprecated in favor of donkeycar.parts.tachometer.Tachometer).
Requires: pigpio
Calibration:
  1. Measure wheel circumference (C) in mm
  2. Count encoder ticks per revolution (T)
  3. Set mm_per_tick = C / T
Outputs:
  • velocity (m/s): Current speed
  • distance (m): Total distance traveled

Tachometer (Modern)

For current speed measurement, use:

Odometer (Modern)

For distance measurement:

Ultrasonic Sensors

For obstacle detection and distance measurement. Location: Custom implementation needed

LIDAR

For 2D/3D environment scanning. Location: donkeycar/parts/lidar.py (if available)

Configuration

In myconfig.py:

Data Recording

Add sensor outputs to TubWriter:

Using Sensor Data in Models

For IMU-augmented models:

Common Issues

IMU Not Detected

GPS No Fix

  • Ensure antenna has clear view of sky
  • Wait 30-60 seconds for initial fix (cold start)
  • Check NMEA output: cat /dev/ttyUSB0
  • Verify GPS LED is blinking

Encoder Not Counting

  • Check GPIO pin connections
  • Verify pigpio daemon is running: sudo systemctl status pigpiod
  • Test with multimeter or oscilloscope
  • Check for proper pull-up/pull-down resistors

Serial Port Permission Denied

Next Steps