Neural networks control a toy car

After taking the Stanford Machine Learning class offered over the Internet last year, [David Singleton] thought he could build something really cool. We have to admit that he nailed it with his neural network controlled car. There’s not much to the build; it’s just an Android phone, an Arduino and a toy car. The machine learning part of this build really makes it special.

A neural network takes a whole bunch of inputs and represents them as a node in a network. Each node in [Davids]’s input layer corresponds to a pixel retrieved from his phone’s camera. All the inputs of the input layer are connected to 64 nodes in the ‘hidden layer’. The nodes in the hidden layer are connected to the four output nodes, namely left, right, forward and reverse.

After training the network and weighting all the connections, [David] got a toy car to drive around a track. Weird, but it works. All the code is up on github, so feel free to take a look behind the inner machinations of a neural net. Of course, you could check out the video of [David]’s car in action after the break.

EDIT: We originally credited [icebrain] as the author. Our bad, and we hope [David] doesn’t hate us now.

You could make it not look as obvious by having the car move forward a little while it thinks about the next move. You’d increase the chance of an accident, but it’s what people do while driving and talking on the cellphone.

“You may also notice in the source that I chose to pulse the forward direction for 250 ms followed by a 500 ms pause – this was done simply because the car I used was very fast and difficult to drive round a small circuit – you might like to experiment with different values or remove this altogether if you try with a slower car.”

The difference between a NN and a DAG, as I see it, is that there is no feedback (cycles) allowed in a NN. Data is only allowed to flow from inputs to the hidden layer (and possibly additional hidden layers) to the outputs.

The reasons for this, I suspect, is primarily for stability. And also to ease the calculation of the neuron input weights and optional trigger levels, during the offline backpropagation training. e.g. These are the outputs I WANT this is the inputs I HAVE, calculate the weights and trigger levels. Having feedback would make this much much much much harder and take considerably longer to do.

Actually, I am thinking of what are called “Feedforward neural network” (the only ones that I have ever used). There are <href=http://en.wikipedia.org/wiki/Recurrent_neural_networks which are similar in some ways to DAG.

the Directed and Acyclic in DAG means no feed back. Assuming you’re strictly adhering to the direction indicated on each edge, there should be no way when walking a DAG to get back to any of the nodes you visited previously.

take a look at a paper we had recently published; however to make it more like “human cognition”, we made it a FUZZY-Neural-network. Built using two Arduino Megas (and not a laptop, because that defeats the purpose of our paper) over 3 summers ago; all arduino code was created and compiled using the method described in my WikiHow on the subject: http://www.wikihow.com/Write-Arduino-Software-in-C

I’ll arrange to have everything put online(source code, etc.) if there is enough interest.

“Once I got it working, I chose to remove the PCB from the original controller housing altogether and instead of powering it with 2 x AA batteries, I fed it 3.3V from the Arduino board (so all power for this unit comes over USB from the computer).”

Careful because the maximum current limit of the FTDI chip (3.3V source) is only 50mA!

He said the car was very fast so he pulsed the mechanical operation, why not just limit the power to the motor so it travels slower but continuously (by reducing motor voltage, inserting power resistor in series with the motor, you get the idea!)

Also keeping the motor pulsing would allow the possibility for additional future outputs from the neural network “faster” (long straight) and “slower” (bends). But then there would be extra neurons required in the hidden layer.