nn-3pi.zip (5443Bytes)
I’ve long been fascinated by the concept of artificial intelligence and its application to robotics. Being somewhat math challenged but an accomplished copy/paste programmer, I decided the best way to learn was to find someone else who had implemented what I was interested in and try to adapt their program to my robot, a Pololu 3pi, to solve a line following problem.
In my quest, I came across the following sites and books - thanks to the various authors:
- http://www.ai-junkie.com/ - great conceptual overviews and source code in C++, Delphi, and Visual Basic
- Artificial Intelligence for Games
- AI Techniques for Game Programming - especially Chapter 7 and the Smart Minesweepers project
- AI Game Engine Programming
- A neural network for Java Lego robots - I’ve ported the Java class discussed here to C++ for the 3pi robot
The neural net described in the Java Lego article needs to be “trained” with input and expected output data sets (see page 2 of the article above for an explanation of how the “backpropagation” algorithm works). In operation in my robot the “brain” takes an array of three binary inputs and responds with an array of two binary outputs according to the table below (readLine() is a Pololu library function for reading the 3pi’s reflectance sensors):
Rule | Input 1 |
Input 2 |
Input 3 |
Output 1 |
Output 2 |
readLine() < 1000 - turn left | 0 |
0 |
1 |
0 |
1 |
readLine() < 3000 - over line | 0 |
0 |
0 |
1 |
1 |
otherwise turn right | 1 |
0 |
0 |
1 |
0 |
The source code for the neural network and my Arduino test sketch for the 3pi are attached. Also attached is a short video of my testing the robot with a simple square line pattern. Happy Halloween!