This is my memo to build a Donkey Car.
Environment
- Ubuntu 16.04
- Raspberry Pi 3B+
- DonkeyCar 2.5.1
Prepare SD card
- Get Etcher to burn the image file.
- Get the zip image file RPi 3B and 3B+ from Donkey Car official.
- 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.
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid=""
psk=""
}
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 x.x.x.x
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 ...
2.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 https://github.com/wroscoe/donkey
$ 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 manage.py drive
using donkey v2.5.1 ...
/usr/lib/python3/dist-packages/h5py/__init__.py:34: 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.py
config loaded
PiCamera loaded.. .warming camera
Starting Donkey Server...
/home/pi/env/lib/python3.5/site-packages/picamera/encoders.py:544: 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 “config.py”.
(env) pi@donkeypi:~/mycar $ donkey calibrate --channel 0
(env) pi@donkeypi:~/mycar $ donkey calibrate --channel 1
(env) pi@donkeypi:~/mycar $ vim config.py
...
#STEERING
STEERING_CHANNEL = 1
STEERING_LEFT_PWM = 460
STEERING_RIGHT_PWM = 340
#THROTTLE
THROTTLE_CHANNEL = 0
THROTTLE_FORWARD_PWM = 410
THROTTLE_STOPPED_PWM = 360
THROTTLE_REVERSE_PWM = 335
...
Edit Manage File
Edit “manage.py” to divide log data.
(env) pi@donkeypi:~/mycar $ vim manage.py
...
from donkeycar.parts.datastore 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 manage.py drive
Check the record files.
(env) pi@donkeypi:~/mycar $ cd data
(env) pi@donkeypi:~/mycar/data $ ls
tub_01_18-07-09
(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 manage.py train --tub ./data/tub_01_18-07-09 --model ./models/mypilot
using donkey v2.5.1 ...
loading config file: /home/reyes/mycar/config.py
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
mypilot
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 manage.py 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
SD Card
$ sudo vim /media/reyes/rootfs/etc/wpa_supplicant/wpa_supplicant.conf
Direct on Pi
$ sudo vim /etc/wpa_supplicant/wpa_supplicant.conf