I’m about to make a line-following robot, but I can’t get my QTR-8RC sensor to work. I’ve read the datasheet but still don’t understand how it works.
So the sequence for reading the senors would be something like
In/out line -output/high
Wait a cpl of us
Measure time for the capacitor to discharge waiting for the I/O line to go low.
I do understand the first three steps, but the 4 gives me troubles…
I supose that the measured time depends on the surface the sensors is reading, and therefore the time it takes for the capacitor to discharge would indicate if the robot is in the correct position or not. But then what should I compare the time with the calibrated value or what?
If you are writing the line-sensing code yourself, then yes, I’d recommend that you first run your robot through a calibration phase where you learn what the discharge time is for a white surface (ideally the floor of the actual line course) and what it is for a black surface (ideally the line itself). You can then use these two calibration points to “normalize” an arbitrary reading to a value between, for example, 0 and 1000, where 0 is the highest reflectance you expect to receive on that particular course and 1000 is the lowest reflectance you expect to see on that particular course. When your sensor is only partially over the line, you’ll get normalized values between 0 and 1000. Does this make sense?
If you’re using one of our Orangutan robot controllers, you can use the QTR portion of the Pololu AVR library instead of implementing the above algorithm yourself. It even has a function to convert the readings of all eight sensors into a single “line position” value on which can be used in a PID loop to keep your bot on the line. If you are using an AVR or some other microcontroller that can be programmed in C, you can use the source code from the library as a starting point for your own code.
I’m writing the code and i’ve thought about the calibration part but at this point i have not any code for it.
And what you write makes senses. Might try someting similiar. At this point the robot is able to detect the line and so on but it’s a bit slow(at determine black/white), but hopefully some kind of calibration will do the trick. So I’ll try that, thanks alot for the tip.
One thing to note is that low reflectance will result in a slow capacitor discharge rate, which means that if you time how long it takes for the sensor output to go low while over a dark surface, your main loop will run slowly. A trick you can use is to stop waiting for the sensor output to go low and just classify the output as “black” after a certain amount of time has elapsed. Calibrating the sensors ahead of time can give you a good idea of what to set this timeout value to so that your main loop can run quickly while still letting you differentiate well between white and black.
Oh I did notice that, while the sensors were over a plain white paper the discharge rate was just a cpl of us while a black surface was over 255us. And the trick you mention, it sounds good, will definitively try that out. Im using a atmega644 btw…
About the sensor app, I can’t even find it on that link?
The library code is written for the mega48/168/328, so you might need to make a few alterations before it works on the 644. It’s also mainly intended for processors running at 20 MHz, so you might need to make some changes if your MCU runs at a different frequency.