OHMC2019 Software instructions
Contents
Overview
From a software perspective, the DonkeyCar (Raspberry Pi) is self-contained ... driving, data acquisition (for training) and ultimately self-driving are all performed with on-board software. The provided micro-SD card already has all the required software pre-installed, as well as two pre-training A.I / Machine Learning models. The DonkeyCar software includes a web-server that provides a web interface that works on both desktop and mobile web browsers (great for driving).
Your laptop will be required to perform training of the Neural Network ... using the data acquired on the DonkeyCar. This means that Python software will need to be installed, e.g TensorFlow (Machine Learning framework).
Software installation: Laptop / Desktop
Extensive DonkeyCar documentation
- apt-get install -y virtualenv # Note: You may be using a different software installer
- mkvirtualenv donkeycar -p python3
- pip install tensorflow==1.8.0 # Note: Probably requires Python 3.5 or 3.6. People are having problems with Python 3.7
(if you get errors, you can try (re-) installing pip: python -m pip install --upgrade pip )
- cd $HOME
- git clone https://github.com/autorope/donkeycar
- pip install -e ./donkeycar
Note: You can manually install Python 3.6 as follows, but then you can't use mkvirtualenv ...
- yum install python36
- python3.6 -m venv ~/virtualenvs/donkeycar
- source ~/virtualenvs/donkeycar/bin/activate
Software installation: Raspberry Pi
Your DonkeyCar (Raspberry Pi) is already pre-installed. This section is for reference only.
Extensive DonkeyCar documentation
- sysctl -w net.ipv6.conf.all.disable_ipv6=1 # Reconnect via ssh afterwards
- sysctl -w net.ipv6.conf.default.disable_ipv6=1
- apt-get update
- apt-get upgrade
- apt-get install -y vim git mosquitto-clients
- apt-get install -y virtualenv build-essential python3-dev gfortran libhdf5-dev libatlas-base-dev libopenjp2-7-dev libtiff5
- apt-get install -y i2c-tools
- i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: 70 -- -- -- -- -- -- --
- mv env env.donkeycar
- virtualenv env -p python3
- pip install tensorflow==1.8.0
- pip install adafruit-pca9685
- pip install picamera
Finding your car on the network
Your DonkeyCar (Raspberry Pi) has been pre-configured to connect to the LCA2019 network. But, which IP address ?
Every car has a unique hostname, from ohmc_01 to ohmc_32. The micro-SD card adapter is labeled with your car name.
However, that still isn't enough to find your car.
So, there is a cron job that every minute sends an MQTT message to test.mosquitto.org with your car's name, IP address and a timestamp.
Install an MQTT client, as follows ...
- apt-get install mosquitto-clients
Use the following command to read the MQTT messages ...
- mosquitto_sub -h test.mosquitto.org -t 'ohmc/#' -v
ohmc/ohmc_01 10.193.2.69 Mon 11 Jun 07:08:01 UTC 2018
Driving the car manually
Caution: Put your car "on blocks" (wheels off the ground) the first time you try driving it
Extensive DonkeyCar documentation
IP_ADDRESS=xxx.xxx.xxx.xxx # Found as above
- ssh pi@$IP_ADDRESS # Note: Raspberry Pi default username: pi and password: raspberry
- cd ohmc_car
- python manage.py drive
loading config file: /home/pi/play/roba_car/config.py config loaded PiCamera loaded.. .warming camera Starting Donkey Server... You can now go to http://xxx.xxx.xxx.xxx:8887 to drive your car.
With a desktop web browser, the user interface provides a virtual joystick (right-hand frame) that you can use to drive the car ... altering the steering and throttle values.
The mobile web browser, the user interface allows you to drive by tilting the phone left-right for steering and forwards-backwards for throttle. For safety, you must press the [Start Vehicle] / [Stop Vehicle] toggle button to enable control.
Steering and throttle calibration
To save time at the workshop, you won't need to calibrate your car's steering and/or throttle.
However, you may get better results and can perform calibration when you have time ... by following the DonkeyCar instructions
Data acquisition for the Neural Network
Once you are driving your car confidently around a track ... it is time to acquire training data for the Neural Network. DonkeyCar operates at 10 frames per second, capturing a 160x120 image, along with steering angle and throttle value. This is all stored in the $HOME/ohmc_car/tub/ directory.
Before training, it is a good idea to clean out previous data. Don't just remove all the files in the tub/ directory ! The tub/meta.json file is important.
Extensive DonkeyCar documentation
Perform the same commands as for manual driving ...
- ssh pi@$IP_ADDRESS
- cd ohmc_car
- python manage.py drive
Then via the web browser press the [Start Recording] button ... drive the car around a track ... then press the [Stop Recording] button.
It is recommended that you collect between 5K and 20K frames. At 10 frames per second, that is between 500 and 2,000 seconds of driving. Make sure that you drive clockwise and anti-clockwise.
When finished acquisition, then transfer the data from the DonkeyCar (Raspberry Pi) to your laptop / desktop for training the Neural Network.
- scp -pr tub $USERNAME@$HOSTNAME:$HOME/tub_$DATE
Training the Neural Network
Once training data has been copied to your laptop / desktop, you can begin training the Neural Network.
Extensive DonkeyCar documentation
Use these commands every time you want to train the Neural Network ...
- workon donkeycar # For those who have set-up a virtualenv
- cd ohmc_car
- python manage.py train --tub ./tub --model ./models/model_$DATE.hdf5