Donkey Car Initial Setup for Windows

Handy Kurniawan
7 min readMay 17, 2021

--

by Handy Kurniawan, supervisor: Naveed Muhammad, Ardi Tampuu

In this tutorial, we will learn how to prepare the Donkey Car in Windows.

If you are interested with the project but doesn’t have the car yet, you can visit Donkey Store

Software Installation

Step 1: Install Software on Host PC

When controlling your Donkey via behavioural cloning, you will need to set up a host pc to train your machine learning model from the data collected on the robot. Choose a setup that matches your computer OS. In my case, it was Windows.

mkdir projects
cd projects
  • Get the latest donkeycar from Github.
git clone https://github.com/autorope/donkeycar.git 
cd donkey
  • If this is not your first install, update Conda and remove old donkey
conda update -n base -c defaults conda
conda env remove -n donkey
  • Create the Python anaconda environment
conda env create -f envs/windows.yml
conda activate donkey
pip install -e .
  • Install Tensorflow
pip install tensorflow
  • Install donkey source and create your local working dir
pip install -e .[pc]
donkey createcar --path ~/d2

Step 2: Setup Raspberry Pi

In this tutorial, I am using Raspberry Pi. If you are using another SBC type, you can see the documentation here.

Flash operating system
  • Choose the operating system and use the Raspian Lite that we download from above.
  • Choose your SD card as the storage.
  • Review your selection and click “Write” to begin writing data to SD Card.

Step 3: Setup the WiFi for the first boot

Open your text editor and copy-paste the following code into it.

country=EE 
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="<your network name>"
psk="<your password>"
}
  • The country defines allowed wifi channels, ensure to set it properly to your location and hardware. Check your country code here.
  • Replace <your network name> with the ID of your network.
  • Replace <your password> with your password, leaving it surrounded by quotes.
  • Save this file to the root of boot partition with the filename wpa_supplicant.conf. On first boot, this file will be moved to /etc/wpa_supplicant/wpa_supplicant.conf where it may be edited later. Make sure it doesn’t have a .txt at the end.
Boot directory to put the config

Step 4: Enable SSH on boot

Put a file named ssh in the root of your boot partition.

Step 5: Connecting to the Pi

If you followed the above instructions to add wifi access, your Pi should now be connected to your wifi network. Now you need to find its IP address so you can connect to it via SSH.

Now, check all the assigned IP address in the network. You will find the hostname Raspberry

arp -a

If the above way doesn’t work, you can go to the router admin panel and find the IP address there.

Once you have found the IP address, open the command prompt and use SSH command to connect with the car

ssh -l pi <your pi ip address>
  • Username: pi
  • Password: raspberry
  • Hostname: <your pi IP address>

Step 6: Update and Upgrade

Once connected to the Raspberry, we need to do the update and upgrade.

sudo apt-get update sudo apt-get upgrade

Step 7: Raspi-config

sudo raspi-config
  • change default password for pi
  • change hostname
  • enable Interfacing Options - I2C
  • enable Interfacing Options - Camera
  • select Advanced Options - Expand Filesystem so you can use your whole sd-card storage

Choose <Finish> and hit enter.

Step 8: Install Dependencies

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

Step 10: Setup Virtual Env

This needs to be done only once:

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

Modifying your .bashrc this way will automatically enable this environment each time you log in. To return to the system python you can type deactivate.

Step 11: Install Donkeycar Python Code

  • Create and change to a directory you would like to use as the head of your projects.
mkdir projects
cd projects
  • Get the latest donkeycar from Github.
git clone https://github.com/autorope/donkeycar
cd donkeycar
git checkout master
pip install -e .[pi]
pip install numpy --upgrade
pip install tensorflow

You can validate your tensorflow install with

python -c "import tensorflow"

Step 12: Create your car application.

donkey createcar --path ~/d2 [--template complete]

Step 13: Configure options

Look at myconfig.py in your newly created directory, ~/mycar

cd ~/mycar
nano myconfig.py

Each line has a comment mark. The commented text shows the default value. When you want to make an edit to over-write the default, uncomment the line by removing the # and any spaces before the first character of the option.

example:

# STEERING_LEFT_PWM = 460

becomes:

STEERING_LEFT_PWM = 500

when edited. You will adjust these later in the calibrate section.

Robo HAT MM1 Setup

If you are using the Donkey Car like above, the car is using the Robo Hat. So you need to set HAVE_ROBOHAT = True in your myconfig.py. Also, set the following variables according to your setup. Most people will be using the below values, however, if you are using a Jetson Nano, please set MM1_SERIAL_PORT = '/dev/ttyTHS1'

#ROBOHAT MM1
HAVE_ROBOHAT = True # set to true when using the Robo HAT MM1 from Robotics Masters. This will change to RC Control.
MM1_STEERING_MID = 1500 # Adjust this value if your car cannot run in a straight line
MM1_MAX_FORWARD = 2000 # Max throttle to go fowrward. The bigger the faster
MM1_STOPPED_PWM = 1500
MM1_MAX_REVERSE = 1000 # Max throttle to go reverse. The smaller the faster
MM1_SHOW_STEERING_VALUE = False
# Serial port
# -- Default Pi: '/dev/ttyS0'
# -- Jetson Nano: '/dev/ttyTHS1'
# -- Google coral: '/dev/ttymxc0'
# -- Windows: 'COM3', Arduino: '/dev/ttyACM0'
# -- MacOS/Linux:please use 'ls /dev/tty.*' to find the correct serial port for mm1
# eg.'/dev/tty.usbmodemXXXXXX' and replace the port accordingly
MM1_SERIAL_PORT = '/dev/ttyS0' # Serial Port for reading and sending MM1 data (raspberry pi default)
# adjust controller type as Robohat MM1
CONTROLLER_TYPE='MM1'
# adjust drive train for web interface
DRIVE_TRAIN_TYPE = 'MM1'

You may need to enable the hardware serial port on your Raspberry Pi. On your Raspberry Pi…

  1. Run the command sudo raspi-config
  2. Navigate to the 5 — Interfacing options section.
  3. Navigate to the P6 — Serial section.
  4. When asked: Would you like a login shell to be accessible over serial? NO
  5. When asked: Would you like the serial port hardware to be enabled? YES
  6. Close raspi-config
  7. Restart

Step 14: Joystick setup

If you plan to use a joystick, take a sidetrack over to here.

If the above step is not working for you, follow this step here. If you are using this step, then we need to configure the joystick config.

Joystick Wizard

This command-line wizard will walk you through the steps to create a custom/customized controller.

Usage:

donkey createjs
  • Run the command from your ~/mycar dir
  • First, make sure the OS can access your device. The utility jstest can be useful here. Installed via: sudo apt install joystick You must pass this utility the path to your controller's device. Typically this is /dev/input/js0 However, it if is not, you must find the correct device path and provide it to the utility. You will need this for the createjs command as well.
  • Run the command donkey createjs and it will create a file named my_joystick.py in your ~/mycar folder, next to your manage.py
  • Modify myconfig.py to set CONTROLLER_TYPE="custom" to use your my_joystick.py controller

Step 15: Calibrate your car

Please see this documentation for the calibration.

Ready for driving

After finishing all the step above, now we are ready to drive.

Driving with Web Controller

Start your car

Open your car’s folder and start your car.

cd ~/mycar
python manage.py drive

This script will start the drive loop in your car which includes a part that is a web server for you to control your car. You can now control your car from a web browser at the URL: <your car's hostname.local>:8887

Driving with Physical Joystick Controller

Start car

cd ~/mycar
python manage.py drive --js

If you want joystick used to be sticky and don’t want to add the --jseach time, modify your myconfig.py so that USE_JOYSTICK_AS_DEFAULT = True

sudo nano myconfig.py

References

--

--

Handy Kurniawan
Handy Kurniawan

Written by Handy Kurniawan

Tere! My name is Handy Kurniawan. I am a Master Student at the University of Tartu, Estonia. Highly interested in Quantum Computing and Quantum AI.

No responses yet