Donkey Car Setup

This is my memo to build a Donkey Car.


  • Ubuntu 16.04
  • Raspberry Pi 3B+
  • DonkeyCar 2.5.1

Prepare SD card

  1. Get Etcher to burn the image file.
  2. Get the zip image file RPi 3B and 3B+ from Donkey Car official.
  3. Burn zip image file to the SD card.

Raspberry Pi Setup

To connect WiFi when Pi boot first time, save the file “wpa_supplicant.conf” to root of boot by using your PC.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

Put SD card to Raspberry Pi and turn on the power.

Wait booting few seconds, then try to search Pi on local network from your PC.

$ ping donkeypi.local
PING donkeypi.local (x.x.x.x) 56(84) bytes of data.
64 bytes from x.x.x.x: icmp_seq=1 ttl=64 time=16.9 ms
64 bytes from x.x.x.x: icmp_seq=2 ttl=64 time=6.75 ms
64 bytes from x.x.x.x: icmp_seq=3 ttl=64 time=4.77 ms

Use ssh to connect Pi.

$ sudo ssh pi@donkeypi.local
The authenticity of host 'donkeypi.local (x.x.x.x)' can't be established.
ECDSA key fingerprint is xxxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'donkeypi.local,x.x.x.x' (ECDSA) to the list of known hosts.
pi@donkeypi.local's password:
Linux donkeypi 4.14.34-v7+ #1110 SMP Mon Apr 16 15:18:51 BST 2018 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Jul 9 19:35:35 2018 from

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

(env) pi@donkeypi:~ $

Install Donkey Car on Pi

Install donkeycar by using pip.

$ pip install donkeycar[pi]
$ python -c "import donkeycar as dk; print(dk.__version__)"
using donkey v2.5.1 ...

Create donkey project.

$ donkey createcar ~/mycar

Install donkeycar on Ubuntu

Pi doesn’t have enough CPU to calculate data setts. Therefore should setup same environment on Laptop.
Open new terminal and command below.

$ sudo apt-get install virtualenv build-essential python3-dev gfortran libhdf5-dev
virtualenv env -p python3
$ source env/bin/activate
$ pip install tensorflow==1.8.0

Make sure to clone master repository. You should install same one as Pi.

$ git clone -b master
$ cd donkey
$ pip install -e .

Create a donkey project.

$ donkey createcar ~/mycar

Test all of hardware on Pi

After setup connecting hardware, try to command below to check them.

(env) pi@donkeypi:~ $ cd ~/mycar
(env) pi@donkeypi:~/mycar $ python drive
using donkey v2.5.1 ...
/usr/lib/python3/dist-packages/h5py/ FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
loading config file: /home/pi/mycar/
config loaded
PiCamera loaded.. .warming camera
Starting Donkey Server...
/home/pi/env/lib/python3.5/site-packages/picamera/ PiCameraResolutionRounded: frame size rounded up from 160x120 to 160x128
  width, height, fwidth, fheight)))
You can now go to http://x.x.x.x:8887 to drive your car.

Access to http://x.x.x.x:8887.

Congrats. Push “Ctrl + C” on terminal to end this program.

Install Vim

(env) pi@donkeypi:~ $ sudo apt-get update
(env) pi@donkeypi:~ $ sudo apt-get upgrade
(env) pi@donkeypi:~ $ sudo apt-get install vim

Calibrate Actuators

Find suitable values of each actuators then edit “”.

(env) pi@donkeypi:~/mycar $ donkey calibrate --channel 0
(env) pi@donkeypi:~/mycar $ donkey calibrate --channel 1
(env) pi@donkeypi:~/mycar $ vim


Edit Manage File

Edit “” to divide log data.

(env) pi@donkeypi:~/mycar $ vim
from import TubGroup, TubWriter, TubHandler
V.add(clock, outputs=['timestamp'])
# multiple tubs
th = TubHandler(path=cfg.DATA_PATH)
tub = th.new_tub_writer(inputs=inputs, types=types)
# single tub
#tub = TubWriter(path=cfg.TUB_PATH, inputs=inputs, types=types)  
V.add(tub, inputs=inputs, run_condition='recording')

Record Manual driving

Drive track. It record automatically.

(env) pi@donkeypi:~/mycar $ python drive

Check the record files.

(env) pi@donkeypi:~/mycar $ cd data
(env) pi@donkeypi:~/mycar/data $ ls
(env) pi@donkeypi:~/mycar/data $ cd tub_01_18-07-09
0_cam-image_array_.jpg record_0.json

Used this track.

Train Recorded data

Open terminal on local PC, then transfer the record data to PC from Pi.

$ rsync -r pi@x.x.x.x:~/mycar/data ~/mycar

Run train program.

$ python train --tub ./data/tub_01_18-07-09 --model ./models/mypilot
using donkey v2.5.1 ...
loading config file: /home/reyes/mycar/
config loaded
tub_names ./data/tub_01_18-07-09
train: 340, validation: 85
steps_per_epoch 2
Epoch 1/100
1/2 [==============>...............] - ETA: 2s - loss: 12.4338 - angle_out_loss: 13.8038 - throttle_out_loss: 1.0407
Epoch 00001: val_loss improved from inf to 1.40054, saving model to ./models/mypilot
Epoch 00009: early stopping

Now got the models.

$ ls mycar/models

Transfer models to Pi from PC.

$ rsync -r ~/mycar/models pi@x.x.x.x:~/mycar

Trained Model

Run the drive program with the trained models. Put “a” key on the browser.

(env) pi@donkeypi:~/mycar $ python drive --model ~/mycar/models/mypilot

And chose “Local Angle”. In this branch, need to control throttle manually. Can push “I key” as forward or “K key” as backward.

Short Track Result

If the vehicle direction were changed, steering would move to other side automatically.

Change Wifi setting

$ ssh pi@donkeypi.local
$ sudo vim /media/reyes/rootfs/etc/wpa_supplicant/wpa_supplicant.conf