Overview
Calibration is the process of finding the correct PWM (Pulse Width Modulation) pulse values that make your car’s steering servo and ESC (Electronic Speed Controller) respond properly to commands. Without proper calibration, your car may not steer correctly or may have incorrect throttle response.Why Calibration Matters
- Steering accuracy: Ensures the car steers the correct amount for each input
- Throttle control: Sets proper stopped, forward, and reverse speeds
- Safety: Prevents unexpected behavior during autonomous driving
- Training quality: Accurate control produces better training data
Understanding PWM Values
What is PWM?
PWM controls servos and ESCs using electrical pulses:- Standard servo pulses: 1ms (full reverse) to 2ms (full forward)
- Neutral position: 1.5ms (centered/stopped)
- Frequency: Typically 50-60Hz (every 16-20ms)
PWM in Donkeycar
Donkeycar uses 12-bit PWM values (0-4095) based on the PCA9685 controller:- Typical range: 200-500 for most servos/ESCs
- Neutral: ~370 (varies by hardware)
- Left/Forward: ~460-500
- Right/Reverse: ~220-290
Calibration Methods
Donkeycar provides two calibration approaches:- Command-line calibration (
donkey calibrate): Test individual channels - Web-based calibration (
calibrate.py): Real-time adjustment with visual feedback
Method 1: Command-Line Calibration
For PCA9685 Motor Controller
This is the most common setup for Donkeycar.--channel=<0-15>: PCA9685 channel number (0 for throttle, 1 for steering)--address=<0x40>: I2C address (default: 0x40)--bus=<1>: I2C bus number (default: autodetect)--pwmFreq=<60>: PWM frequency in Hz (default: 60)init PCA9685 on channel 1 address 0x40 bus 1
Using PWM freq: 60
Enter a PWM setting to test ('q' for quit) (0-1500):
370 # Start at neutral (should be centered)
460 # Test left - wheels should turn fully left
290 # Test right - wheels should turn fully right
# If 460 is too far left, try:
450
440
# Keep adjusting until you find the exact full-left position
Put your car on a stand or hold it so the wheels don’t touch the ground during throttle calibration!
370 # Start at neutral - wheels should NOT spin
400 # Gradually increase - note when wheels start moving
500 # Test forward - wheels should spin forward
220 # Test reverse - wheels should spin backward
PWM_STEERING_THROTTLE = {
"PWM_STEERING_PIN": "PCA9685.1:40.1",
"PWM_STEERING_SCALE": 1.0,
"PWM_STEERING_INVERTED": False,
"PWM_THROTTLE_PIN": "PCA9685.1:40.0",
"PWM_THROTTLE_SCALE": 1.0,
"PWM_THROTTLE_INVERTED": False,
"STEERING_LEFT_PWM": 460, # Your calibrated value
"STEERING_RIGHT_PWM": 290, # Your calibrated value
"THROTTLE_FORWARD_PWM": 500, # Your calibrated value
"THROTTLE_STOPPED_PWM": 370, # Your calibrated value
"THROTTLE_REVERSE_PWM": 220, # Your calibrated value
}
For Direct PWM Pins
If using Raspberry Pi GPIO pins directly:RPI_GPIO.BOARD.33: Board pin numberingRPI_GPIO.BCM.13: BCM (Broadcom) numberingPIGPIO.BCM.13: Using pigpio daemon
For Arduino
Method 2: Web-Based Calibration
The web interface provides real-time calibration with visual feedback.- Left Arrow: Test left steering
- Right Arrow: Test right steering
Configuration for Other Drive Trains
I2C_SERVO (Legacy PCA9685)
Older configuration style:MM1 (RoboHat MM1)
Differential Drive
For tank-style steering, calibrate each motor separately:Calibration Tips
Steering
- Start conservative: Begin with small steering angles
- Check mechanical limits: Don’t force the servo past its physical limits
- Test both directions: Ensure equal response left and right
- Watch for binding: Wheels should move freely without catching
Throttle
- Find true neutral: Wheels should not move at all when stopped
- Gradual acceleration: Find the minimum PWM where wheels just start moving
- ESC calibration: Some ESCs need their own calibration procedure (check manual)
- Reverse setup: Test that reverse works after enabling it
Common PWM Ranges
Steering servo (typical):- Left: 420-500
- Center: 350-380
- Right: 220-300
- Forward: 400-550
- Neutral: 350-380
- Reverse: 200-280
Testing Calibration
Test steering
http://<your-car>.local:8887
- Set mode to User
- Move the steering slider left/right
- Verify wheels turn to full lock in both directions
- Check that center position is straight
Test throttle
- Lift car off ground
- Set mode to User
- Gradually increase throttle slider
- Verify:
- Wheels don’t spin at zero throttle
- Smooth acceleration forward
- Reverse works (if equipped)
Troubleshooting
Servo jitters or buzzes
Cause: Stopped PWM value not at true neutral Solution: Fine-tuneTHROTTLE_STOPPED_PWM in smaller increments:
Steering reversed
Solution: Swap the PWM values:Throttle reversed
Solution: Swap forward/reverse or use invert flag:Limited steering range
Check:- Servo arm is properly attached (perpendicular at center)
- Mechanical linkages aren’t binding
- PWM values are at servo’s actual limits
ESC not responding
Check:- ESC is powered (battery connected)
- Correct channel (usually 0)
- ESC is properly initialized (some need a startup sequence)
- PWM frequency matches ESC (typically 60Hz)
Throttle works but reverse doesn’t
ESCs require reverse activation:- Set to neutral (stopped PWM)
- Set to full reverse for 1-2 seconds
- Return to neutral
- Reverse should now work
Advanced: PWM Frequency Scaling
If using non-standard PWM frequency:scale = 50/60 = 0.833
For 75Hz: scale = 75/60 = 1.25
Next Steps
Once calibration is complete:- Test drive: Learn to drive and collect data
- Collect training data: Drive manually and record good laps
- Train your model: Use collected data to train an autopilot
