4
\$\begingroup\$

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)

\$\endgroup\$
  • \$\begingroup\$ how you connect qtr senzor to your microcontroler ? \$\endgroup\$ – user3058 Feb 17 '11 at 13:55
3
\$\begingroup\$

I haven't used the QTR sensors myself, but I noticed that the main difference between your code and the examples I found floating around is that you are calling readCalibrated(val) before readLine and the examples don't. I looked through the source for the libary and readLine calls readCalibrated in the first couple of lines anyway. Maybe pre-loading val is with the calibration values is causing the problem?

Also, are you passing the sensor over both the white and black surfaces during the calibration? A trick could be to get the bot to slowly spin on the spot during calibration, while sitting on the line, allowing the sensor to see both the line and the surrounding area.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.