Radu Trambitas - 2010/2011
Computer Vision Guidance of a Line Following Robot

Abstract
The purpose of this report is to describe the implementation of a computer vision guided line following robot. The Motorola XT720 running Android will be used to capture video, run the line following algorithm and maintain the robot within the line by communicating motor speeds via Bluetooth to the robot base. An Arduino Uno microcontroller will be used to drive the robot.
Hardware
Hardware Setup
The Arduino Uno board is used to drive the two motors. It does so by receiving wireless commands from the Motorola XT720 phone through the WRL-08550 Bluetooth module. An SN754410 H-Bridge is used to control the direction and speed of each motor.
Here is a diagram showing how the h-bridge and the Bluetooth module are connected to the Arduino Uno microcontroller. For exact pin connections please see the arduino_control source code at the bottom of this page.

The SN754410 h-bridge is used for a differential drive system. Below is the schematic showing how it is wired.

Software
There are two software components to the line following robot.
1) An Android application called LineTracker implements a line following algorithm along with a PID algorithm that controls motor speeds.
The following algorithm runs on each frame:
First we grab a frame from the camera video feed and covert it from YUV format to grayscale. At same time the image is also thresholded with pixels below the threshold turning black and pixels above set to white. This is then passed onto the line following algorithm. We scan the image from top to bottom and look for the largest cluster of black pixels in a line that is also closest to the middle of the screen. We assume this to be our black line that we must follow. Then we take the middle of this cluster and subtract it from the center of the screen. This value becomes our error value which is passed into the PID algorithm. The PID algorithm calculates the motor speeds such that the robot moves in a smooth fashion around our black line circuit. The motor speeds are then sent to the Arduino microcontroller via Bluetooth.
In order to communicate with the Arduino microcontroller we use another Android application called Amarino. This is a toolkit which allows us to interface the phone and Arduino using Bluetooth. For more details on how it works please visit the link.
2) The code running on our Arduino microcontroller listens for commands from the phone by implementing the Amarino MeetArduino library. When a command is received we update each motor's speed and direction. This happens about 10 times a second.
Video
Here are a couple of videos showing the line following robot in action:
Source
Arduino Control - Arduino application
LineTracker - Android application
References
http://arduino.cc/en/Main/ArduinoBoardUno
http://www.amarino-toolkit.net/
http://itp.nyu.edu/physcomp/Labs/DCMotorControl
http://en.wikipedia.org/wiki/PID_controller
http://www.arduino.cc/en/Tutorial/PWM
http://www.scribd.com/doc/49813253/Building-Autonomous-Line-Followers-using-Arduino-and-PID
http://www.stanford.edu/class/ee368/Android/Tutorial-1-Basic-Android-Setup-Linux-SCIEN.pdf