Tuesday 27 August 2019

Self Driving RC Car

In this post, I will outline how I got my RC car to drive by itself using deep learning. The RC car has a camera to see whats in front of it, for example a road that it can follow. Images from the camera are then used as input to a deep learning model which outputs a steering direction, such that the RC car will steer depending on what it sees, very much similar to how humans steer a car. This type of problem is called a computer vision problem which is a field primarily concerned with using visual data such as a video feed or images to perform tasks.

The task for the RC car is to follow the road. The road is made up of paper sheets laid down to form a track. I decided to use paper since I could create different tracks easily, rather than painting road lines.



What is deep learning?

The goal of machine learning is to enable machines to act on information. This is achieved by creating a model which takes some form of input data and gives an output. Deep learning models are a specific class of models based on the perceptron which will be used for this task. Before that a brief explanation of supervised learning is required.

Supervised learning

To introduce deep learning, I will start off by talking about supervised learning. Supervised learning is when we provide the output we want the model to give, along with the input that is generated by it. As a result, the model will be only as good as the data we provide to it.

Perceptron

A perceptron aims to mimic a neuron in the brain as it has some inputs and provides a single output. Neurons take in electrical impulses as input and then in turn output another electrical signal.

The perceptron has parameters which describe it and these parameters can be learnt by using the data. This is the process of training. These parameters are adjusted depending on if the output is correct or not, correct meaning it it the same as the provided output. If an output is incorrect then we would like to adjust the parameters so that the model will output the correct value.


Perceptron Model

Multi layer perceptron

The issue with just normal perceptrons is that it is unable to model complex tasks, by stacking many of them together, we can get them to model more interesting problems.

Training the model

Previously, I had introduced a ps3 controlled RC car and is the main system used for training. Training data is collected by manually controlling the car and collecting images along with steering angle. The steering angle is tied to how much the analog sticks are moved.

The training data is then given to the deep learning model to adjust its parameters. A basic method to perform this is called gradient descent.

Control

After the model has been trained, the RC car will stream images to the computer. The computer then processes these images using the model, and output a steering angle. This was done to utilize the GPU of the computer which is able to train and use deep learning much more quickly than the CPU of the raspberry pi. The computer then sends the steering angle back to the RC car such that it can steer itself.

Improvements

One main problem with this method is that it requires a good connection between the RC car and the computer to send large amounts of image data. Ideally, it should be processed locally on the raspberry pi, however the raspberry pi is too slow for that sort of data processing. Alternatively a more powerful system could be used such as Nvidia's Jetson.

Nvidia Jetson

Different deep learning architectures could also be considered in the future. In particular, a flavor of deep learning called the convolutional neural network is designed especially for image data.

Finally more data usually works better for deep learning models as it helps with a problem called over-fitting. This occurs when the model is trained too much on the training data and is unable to generalize to other new data it has not seen before.