DonkeyCar for Pi-Setup Raspberry Pi

From Waveshare Wiki
Jump to: navigation, search

Guide of DonkeyCar

Step 1. Install libraries

Please make sure that you have installed the image and it could start normally. Open the terminal and install the libraries as below

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential python3 python3-dev python3-pip python3-virtualenv python3-numpy python3-picamera 
sudo apt-get install python3-pandas python3-rpi.gpio i2c-tools avahi-utils joystick libopenjp2-7-dev libtiff5-dev gfortran 
sudo apt-get install libatlas-base-dev libopenblas-dev libhdf5-serial-dev git ntp

Step 2. Install libraries for OpenCV

sudo apt-get install libilmbase-dev libopenexr-dev libgstreamer1.0-dev libjasper-dev libwebp-dev 
sudo apt-get install libatlas-base-dev libavcodec-dev libavformat-dev libswscale-dev libqtgui4 libqt4-test

Step 3. Setup virtual environment

python3 -m virtualenv -p python3 env --system-site-packages
echo "source env/bin/activate" >> ~/.bashrc
source ~/.bashrc

Note: Here we modify .bashrc for auto-entering the virtual environment, if you want to back to normal environment, please use command deactivate.

Step 4. Install Donkeycar Python codes

  • Create a project directory
mkdir projects
cd ~/projects
  • Clone donkeycar codes from Github (Use the commands of next one if you buy the pro version)
git clone https://github.com/waveshare/donkeycar
cd donkeycar
git checkout master
pip install -e .[pi]
pip install tensorflow==1.13.1
pip install numpy --upgrade

You can verify your TensorFlow installation using:

python -c "import tensorflow"

If there are no errors then the installation is normal and the following warning is normal.

r_util' does not match runtime version 3.5
  return f(*args, **kwds)
/home/pi/env/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: builtins.type size changed, may indicate binary incompatibility. Expected 432, got 412
  return f(*args, **kwds)

Step 5. Install OpenCV

  • Install OpenCV
sudo apt install python3-opencv
  • If you fail at the last command, please use this command to install OpenCV again
pip install opencv-python
  • Check if the OpenCV is installed successfully
python -c "import cv2"

If there are no errors, then you have installed OpenCV!

Note: If prompted with __atomic_fetch_add_8 undefined error. first, exit the virtual environment with the deactivate command, run the following command, and then retest.

deactivate
echo "export LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1 " >> ~/.bashrc
source ~/.bashrc

Step 6. Install Service of OLED Display

  • Use command belows to install service for OLED displaying. The OLED onboard can be used to display IP address, Voltage and current, etc.
cd ~
git clone https://github.com/waveshare/pi-display
cd pi-display
sudo ./install.sh

Step 7. Create DonkeyCar

  • Create donkeycar example
cd ~/projects/donkeycar
donkey createcar --path ~/mycar

After runing, files will be generated and saved in the directly ~/mycar