Dedicated to revolutionary open source prototyping by introducing creative design with modern resources, pursuing the next generation of technological solutions

Friday, June 11, 2010

First Robot - Line Following and Edge Detection

I used an Arduino Duemillanove with the ATMega 328. Propulsion is provided by the two Parallax Futaba Continuous Rotation Servos. My sensor is the Pololu QTR-6A IR Reflectance Sensor Array, and it is all powered off 4 rechargeable NiMH Duracell AA Batteries :)

It can follow a dark like, on a light background. In this case i used black tape on a whiteboard. It first calibrates itself for 5 seconds. You move it across the line a few times so it gets used to the difference in reflectance. After the calibration it begins moving foward. I used an algorithm to determine its error off the line. If it determines through the algorithm that it is at an extreme error, it will turn for a longer amount of time. Similarly, if the robot determines it is only a fraction of an inch off the line, it will only turn for a fraction of a second. This reduces over compensation and makes the line following a little smoother and more reliable.

This is the code I used, I started it from scratch and added the MegaServo Library. I'm aware that there is a library for the Pololu IR sensor arrays, but I encountered problems so i decided to start from scratch with the sensor reading as well. I'm using the Analog version of the Pololu sensor array, as opposed to the RC version, which outputs a digital signal. My sensors output an Analog voltage based on the reflectance of the surface. For example, if you are providing 5V to the sensors at Vcc, and you encounter a dark surface, that sensor will output a a voltage closer to 5V. Conversely, if the sensor encounters a very reflective, (white surface) it will output closer to 0V. I can read these 6 Analog outputs from my 6 sensors through the 6 Analog I/O pins on my Arduino.
In addition, my STOP algorithm uses nested if statements to check 3 times if the robot is really at the end, before it stops for 10 seconds, blinking the light. This prevents an accidental stop in the middle of the track due to inaccurate readings or glitches. During calibration, I calculated an average value of reflectance which i use later on to help with the navigation and decision making. I also printed some data to the Serial screen for testing purposes.

Code :

No comments:

Post a Comment