Share on facebook
Share on twitter
Share on linkedin

How to build a self-driving robot race car

A Cloud Guru News
A Cloud Guru News

Learn how our Robocar Rally racing team built an autonomous model car in 12 hours from start to finish

“When you put the helmet on, it doesn’t matter if you are woman or man … the important thing is your ability, your intelligence and your determination.”
— Milka Duno, Professional Race Car Driver

During the recent AWS re:Invent conference, I had the opportunity to represent Verizon’s cloud engineering efforts at our expo hall booth and share my insights on how we develop and deploy large-scale solutions on AWS.

As part of the conference experience, our friends at A Cloud Guru invited me to participate in the Robocar Rally — a two-day hackathon focused on deep learning, IoT, and artificial intelligence to build and race a 1/16th scale autonomous car.

Over the course of 2-days, I partnered with Anne-Jeanette from Capital One Tech as the only women participants — customizing and training a scale-model autonomous car to compete in the time trials on the re:Invent Circuit.

After 12 hours of hacking over a couple of days, we built a competitive driverless model race car that drove awareness for Women Who Code and the AWS ‘We Power Tech’ diversity program.

If you’re interested in creating your own autonomous model car or just want to learn from our experience, the steps below will guide you through the process for getting your car up and running.

A “Donkey Car” is the starting kit model used by most novices — it costs about $200 and take a few hours to put together. Donkey is the name of the Python library that supports the self-driving car.

Why the name Donkey?
Donkey’s were one of the first domesticated pack animals, they’re notoriously stubborn, and they are kid safe. Until the car can navigate from one side of a city to the other, we’ll hold off naming it after some celestial being.

Step 1: Building the Car

You’ll need to build the car chassis, then equip it with a Raspberry Pi and camera. The parts lists and instructions available on the donkeycar site —you can either print the parts, or there is an option to purchase them.

Build a car – Donkey Car — Attaching the camera is a little tricky, the M2 screws can be screwed into the plastic but it is a little hard. I — docs.donkeycar.com

Step 2: Setup the software environment

To get started, you’ll want to install the 64-bit versions of both git and miniconda Python 3.6 on the host operating system of your choice.

wroscoe/donkey — donkey – self driving car — github.com

  • First, you’ll want to git clone the repo and cd into the root folder.
git clone https://github.com/wroscoe/donkey
cd donkey
  • Next, start up the Anaconda management system.
conda env create -f envs/mac.yml
source activate donkey
  • The pip command below is used to install Python packages. In this case, we’ll be using it to install TensorFlow—an open-source machine learning library created by Google used to analyze the images and data collected from from our car’s camera.
pip install https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.3.0-py3-none-any.whl
  • We will also use pip to install the remaining packages.
pip install -e .
  • And finally, you’re going to need to create your car’s data path.
donkey createcar — path ~/d2

Congratulations! The setup is complete.

Step 3: Configure the Raspberry Pi

In the first step, you attached the Raspberry Pi and camera to the chasis of the the car. At this point, your robocar should be completely assembled.

Before ‘ssh’ing into our pi, we’ll need to make the SD card into a startup disk so it can help boot up the pi. For the easy version, you can install Etcher or Noobs — both provide graphical interface utilities for writing to the SD card.

For developers like myself that prefer the command line, open a terminal window and type:

diskutil list
  • Find the partition of your SD card — it’s probably called disk4
  • Replace <name of disk> with your SD card disk name
diskutil unmountDisk /dev/<name of disk>

Now we need to download the handy disk image that the donkeycar team created. The current version is 22, but I’d recommending checking the docs at the donkeycar site to get the latest version.

  • Next, install that downloaded image on the SD card. This might take some time, so be patient.
sudo dd bs=1m if=<image/path/image.img> of=/dev/rdisk<disk# from diskutil> conv=sync
  • If your image went into the downloads folder and your SD card is disk4, the command would be:
sudo dd bs=1m if=~/Downloads/donkey_v22/donkey_v22.img of=/dev/rdisk4 conv=sync

ProTip

You can drink and autonomously drive!

Step 4: Connecting your pi to wifi

To transfer the collected driving data from the Raspberry Pi for training on your local hosts, we’ll need to make sure the devices are on same wifi network.

To setup the wifi, a file is installed inside the boot partition with the configuration parameters used to connect the network at startup.

  • Make sure your SD card is still connected.
  • On your SD, there should be a /boot/ directory.
  • Inside boot, there will be a wpa_supplicant.conf file.
  • Open your favorite text editor and add your network settings.
  • We used the code below for the hackathon. Make sure to add your network name and network password — and keep the quotes!
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
 ssid=”<your network name>”
 psk=”<your password>”
}
  • Now you can remove the SD card and plug it into your Raspberry Pi. If you only have one raspberry pi on the network, you can try to find its ip address with ping raspberrypi.local
  • At the robocar rally hackathon, this wasn’t the best option for our team. We had to connect the pi to an external monitor to find its ip address.
  • If you need to do this, your username and password on version 22 of the donkeycar image file will be:
Username: pi
Password: asdfasdf
  • After you’ve logged in, type ifconfig wlan0 to see the ip address info.
  • Once your have your Raspberry Pi’s IPaddress, we can now ssh into our pi. Yay!
ssh pi@<your_pi_ip_address>

Step 5: Configure the pi

Once you are logged into your Raspberry Pi, you’ll be ready to create your car with the donkey CLI using a template provided.

donkey createcar — template donkey2 — path ~/d2
  • Change directory into the path you just specified — in this case it’s /d2/
cd ~/d2
  • And finally, start up your web server!
python manage.py drive
  • If successful, the server will be running at <your car’s IP’s address>:8887 where 8887 is our port number.
  • To make driving easier, we used our mobile phones to connect to the web server. Just make sure your cell is connected to the same wifi network as your Raspberry Pi.

Step 6: Capture data and train the models

Congrats! The robocar is now setup and you can start recording some driving data for your car — the more data, the better! Be sure to go slow; you want to push the best model possible to the car for training purposes.

The recorded data consists of a JPEG images and a corresponding JSON file with steering and throttle info. Once you’ve gathered data, you’ll transfer the data to your host operating system to create a model using TensorFlow.

  • Copy the data over from your Raspberry Pi.
rsync -r pi@<your_pi_ip_address>:~/d2/data/ ~/d2/data/
  • Train your car.
python ~/d2/manage.py train — model ~/d2/models/myPilotName
  • Once complete, push the new pilot file to your car.
rsync -r ~/d2/models/ pi@<your_ip_address>:~/d2/models/
  • SSH into your pi, and start up your server with the shiny new pilot file.
python manage.py drive — model ~/d2/models/myPilotName
  • Connect to your web server, and start using the pilot file by selecting “Local Angle” from the dropdown. This will allow you to control speed and the pilot controls steering.

Final Step: Celebrate!

Congrats! You now have a self-driving car — although probably not very coherent yet. The more data collected after each attempt, the better the models and the autonomous driving.

For even more powerful model training, you can train your models on AWS using a Deep Learning virtual machine deployed as a Docker container — a more advanced approach to training higher performing models.

And if you went to the AWS re:Invent and participated in the Robo Car Rally hackathon — you also got this awesome swag from Werner Vogels!

We Power Tech

In a room full of over 100 engineers at the Robocar Rally hackathon, Anne-Jeanette and I were the only two women developers participating in the event. I’m grateful we had the opportunity to represent Women Who Code thanks to A Cloud Guru and their partnership with AWS We Power Tech — thank you!

After participating in the hackathon and attending the conference, the path forward seems pretty clear. More opportunities like the Robocar Rally are needed for those underrepresented in tech — access to training, conferences, and hackathons that provide the advanced skills necessary to navigate the barriers to career entry and growth.

We Power Tech | A Cloud Guru — A Cloud Guru is partnering with AWS We Power Tech to see a future of tech that is every color, gender, belief, origin… — info.acloud.guru

The AWS re:invent conference was an amazing opportunity to connect, network, and learn from so many women who are leading the future of cloud computing. I’m lucky to work at a company like Verizon with leaders who actively supports diversity and inclusion in technology — and it’s encouraging to see so many other companies joining the conversation.

Together, #WePowerTech!

Recommended

Get more insights, news, and assorted awesomeness around all things cloud learning.

Get Started
Who’s going to be learning?
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!