David's line following code from the LVBots competition, 2015.
Dependencies: GeneralDebouncer Pacer PololuEncoder mbed
Fork of DeadReckoning by
Diff: main.cpp
- Revision:
- 32:83a13b06093c
- Parent:
- 31:739b91331f31
- Child:
- 33:58a0ab6e9ad2
--- a/main.cpp Tue Mar 04 03:04:00 2014 +0000 +++ b/main.cpp Tue Mar 04 04:32:51 2014 +0000 @@ -38,13 +38,13 @@ // Test routines //testMotors(); //testEncoders(); - testLineSensors(); + //testLineSensors(); //testReckoner(); //testButtons(); //testDriveHome(); //testFinalSettleIn(); //testCalibrate(); - //testLineFollowing(); + testLineFollowing(); //testAnalog(); //testSensorGlitches(); @@ -56,7 +56,6 @@ setLeds(0, 1, 0, 0); findLine(); - //findLineAndCalibrate(); //setLeds(1, 1, 0, 0); //turnRightToFindLine(); @@ -72,12 +71,22 @@ void loadCalibration() { + /** QTR-3RC **/ + lineTracker.calibratedMinimum[0] = 100; + lineTracker.calibratedMinimum[1] = 94; + lineTracker.calibratedMinimum[2] = 103; + lineTracker.calibratedMaximum[0] = 792; + lineTracker.calibratedMaximum[1] = 807; + lineTracker.calibratedMaximum[2] = 1000; + + /** QTR-3A lineTracker.calibratedMinimum[0] = 34872; lineTracker.calibratedMinimum[1] = 29335; lineTracker.calibratedMinimum[2] = 23845; lineTracker.calibratedMaximum[0] = 59726; lineTracker.calibratedMaximum[1] = 60110; - lineTracker.calibratedMaximum[2] = 58446; + lineTracker.calibratedMaximum[2] = 58446; + **/ } void updateReckonerFromEncoders() @@ -139,21 +148,6 @@ } } -// Returns true if each line sensor has one third of a volt of difference between the -// maximum seen value and the minimum. -bool calibrationLooksGood() -{ - for(uint8_t s = 0; s < LINE_SENSOR_COUNT; s++) - { - uint16_t contrast = lineTracker.calibratedMaximum[s] - lineTracker.calibratedMinimum[s]; - if (contrast < 9929) // 0xFFFF*0.5/3.3 = 9929 - { - return false; - } - } - return true; -} - void waitForSignalToStart() { while(!button1DefinitelyPressed()) @@ -219,42 +213,6 @@ } } -// THIS IS DEPRECATED. Instead we are using loadCalibrationAndFindLine. -void findLineAndCalibrate() -{ - Timer timer; - timer.start(); - - Timer goodCalibrationTimer; - bool goodCalibration = false; - - while(1) - { - lineTracker.read(); - lineTracker.updateCalibration(); - updateReckonerFromEncoders(); - updateMotorsToDriveStraight(); - - if (goodCalibration) - { - if(goodCalibrationTimer.read_ms() >= 300) - { - // The calibration was good and we traveled for a bit of time after that, - // so we must be a bit over the line. - break; - } - } - else - { - if(calibrationLooksGood()) - { - goodCalibration = true; - goodCalibrationTimer.start(); - } - } - } -} - void turnRightToFindLine() { while(1)