QTR 8RC White line detection

I am using a qtr8-rc sensor array on a line following robot, When I use it on a black line on a white surface it works but when i try to use it on a black surface with white line i can’t get correct results, i have extracted the following code from my robot to test it separately but no matter what i do i can not get it to detect white line on a black surface…

#include "PololuQTRSensors.h"

PololuQTRSensorsRC qtr;

void setup(){
  Serial.begin(9600);
  qtr.init((unsigned char[]) {2,3,4,5,6,7,9}, 7);

  int i;  
  for (i = 0; i < 250; i++){  // make the calibration take about 5 seconds  
    qtr.calibrate(QTR_EMITTERS_ON);
    delay(20);
  }
}

void loop(){

  unsigned int val[7];
  qtr.readCalibrated(val);
  int line = qtr.readLine(val,QTR_EMITTERS_ON,true);

  Serial.print(line);
  Serial.print(" R< ");
  Serial.print(val[0]); Serial.print(" ");
  Serial.print(val[1]); Serial.print(" ");
  Serial.print(val[2]); Serial.print(" ");
  Serial.print(val[3]); Serial.print(" ");
  Serial.print(val[4]); Serial.print(" ");
  Serial.print(val[5]); Serial.print(" ");
  Serial.print(val[6]); Serial.print(" ");
  Serial.print(val[7]); Serial.print(" ");
  Serial.println(" >L ");

}

Some sample reading I am getting,

3200 R< 553 473 397 113 120 533 304 104  >L 
3432 R< 567 514 474 113 120 393 82 104  >L 
3494 R< 572 625 544 94 100 487 69 104  >L 
3418 R< 543 421 506 88 93 305 64 104  >L 
3407 R< 529 403 487 69 73 290 50 104  >L 
3403 R< 524 397 480 62 67 284 46 104  >L 
3506 R< 538 561 474 37 40 264 27 104  >L 
3503 R< 538 543 455 18 20 248 13 104  >L 
3519 R< 558 567 474 44 46 269 32 104  >L 
3537 R< 577 590 500 69 73 290 50 104  >L 
3545 R< 577 614 532 94 100 310 69 104  >L 
3466 R< 611 497 397 94 100 310 69 104  >L 
3534 R< 572 584 500 62 67 284 46 104  >L 
3534 R< 572 584 500 62 67 284 46 104  >L 

All numbers are way too close so readLine does not return a correct position. One of the pins on my arduino does not work so I skipped connecting one of the sensors(sensor 7)

Hello,

Including a bad sensor in your list is not a good idea. But anyway, did you actually calibrate the sensors by moving your robot over white and black areas during the calibration period? Where was the line when you collected the sample data?

-Paul

Last night I did some more testing, also removed the bad sensor from calculations, it works on some black surfaces but does not work on all some black surface reveals good reading some dont.

While calibrating line is perpendicular to the robot I swipe the robot over it all sensor go over white And black surfaces multiple times.

My stupidty is I have never done testing on black used white surface during tests thinking it would just work now I have one day to contest.

Wow, one day to the contest? Try to shield your sensors from any ambient light (even a bit of paper to form a “skirt” around your robot can help) and get them down as low as possible. Those are the only two really general tips I can think of…otherwise, you need to test, test, test. Good luck!

-Paul

Hello.

Are you being careful to calibrate your sensors at their mounted height? For example, lifting your robot off the ground while it’s calibrating could throw the calibrations off. Also, if you calibrate your sensors on a black course with a white line, do you get different results?

- Ben

my problem is everything works when using black line on white surface it follows the line perfectly. I assumed just setting readline whitefollow to true would work. am I missing something?

I am not lifting the robot while calibrating and sensors are approx 3 mm high for white it works but for black surfaces different surfaces reveals different results

when I calibrate and run my robot on a white surface with black line it works as expected but when calibrate and run on a black surface with a white line I get the results I posted above but for some black surfaces it gives correct results.

From the data you provide, I suspect the calibration isn’t working quite right. If properly calibrated, sensors directly over the white line should read close to 0 and sensors entirely over black should read close to 1000. Can you output calibration results and the raw sensor values to see if something strange is going on?

Also, what do you mean when you say that “for some black surfaces it gives correct results”? Can you give us some details about the surfaces it works on and the surfaces it fails on? Does the material of the surfaces differ?

- Ben

when calibrated on black cardboard I got the results posted but when calibrated on black vinyl it does work as expected.