[3pi] Follow line of specific reflectance

Hey Pololu,

I want to build a line following robot, but the catch is, I want to it follow a line that has certain reflectance.

For example, lets say I have a maze with grey lines and black lines. Is there a way that I can have it only follow the black line, and the not less “intense” grey line?

Is this possible with a 3pi?


It might be possible for you to detect the difference between a gray and a black line if their IR reflectivity is different. You probably would need to figure out the thresholds between the line and the surface for each case, then compare those values to the raw QTR sensor values on your 3pi. We do not have any specific code examples that we can point you to, but if you get stuck while writing your code, I would be glad to take a look and offer some suggestions.

- Amanda

Hey Amanda,

This is my first time using the 3pi or QTR Sensors. Could you possibly give me a high level description of the system, or advise me towards the psuedo code for it?

I can’t really give you psuedo code or an overview of how your specific system will work, since there many ways you could approach the problem, and what one you use will depend on lots of factors, like the specifics of your maze. Here are a few suggestions to get you started though.

First, you will probably need to find the difference between the IR reflectivity of a gray line and black line based on the QTR sensor readings. If you are using the Arduino IDE to work with the 3pi, you can run the QTRRCRawValueExamples example code and see the raw sensor values from the IDE’s Serial Monitor when traversing over a gray or black line. You can find that example under the “examples” folder on the qtr-sensors-arduino GitHub page. (To configure your Arduino IDE to work with the 3pi, see the “Programming Orangutans and the 3pi Robot from the Arduino Environment”.)

If you are not using the Arduino IDE to program your 3pi, you can run the sample routine under the “Reading the Sensors” section of the Pololu AVR C/C++ Library User’s Guide, but you would need to make some modification if you want to display the sensor values.

Second, you might want to look at the source code for the qtr_calibrate and qtr_read_calibrated functions to see how they collect several readings, store them, and then compare the sensor readings obtained later to the stored values to determine if the sensor is over a light or dark surface. For more information about those function, see the Pololu AVR Library Command Reference.

- Amanda