David's line following code from the LVBots competition, 2015.
Dependencies: GeneralDebouncer Pacer PololuEncoder mbed
Fork of DeadReckoning by
Diff: main.cpp
- Revision:
- 26:7e7c376a7446
- Parent:
- 25:73c2eedb3b91
- Child:
- 27:2456f68be679
--- a/main.cpp Fri Feb 28 01:26:18 2014 +0000 +++ b/main.cpp Fri Feb 28 01:40:39 2014 +0000 @@ -176,10 +176,6 @@ lineTracker.calibratedMaximum[1] = 60110; lineTracker.calibratedMaximum[2] = 58446; - Timer foundLineTimer; - foundLineTimer.start(); - bool foundLine = false; - GeneralDebouncer lineStatus(10000); while(1) { @@ -189,21 +185,9 @@ updateMotorsToDriveStraight(); lineStatus.update(lineTracker.getLineVisible()); - if (foundLine) + if(lineStatus.getState() == true && lineStatus.getTimeInCurrentStateMicroseconds() > 100000) { - if(foundLineTimer.read_ms() >= 500) - { - // We found the line and traveled for a bit more, so now we can be done. - break; - } - } - else - { - if(lineStatus.getState() == true && lineStatus.getTimeInCurrentStateMicroseconds() > 150000) - { - foundLine = true; - foundLineTimer.start(); - } + break; } } } @@ -263,6 +247,9 @@ void followLineToEnd() { + Timer timer; + timer.start(); + GeneralDebouncer lineStatus(10000); const uint32_t lineDebounceTime = 100000; const int followLineStrength = 300; @@ -275,14 +262,8 @@ lineStatus.update(lineTracker.getLineVisible()); bool lostLine = lineStatus.getState() == false && - lineStatus.getTimeInCurrentStateMicroseconds() > lineDebounceTime; - - if(lostLine) - { - break; - } - - if(lineTracker.getLineVisible()) + lineStatus.getTimeInCurrentStateMicroseconds() > lineDebounceTime; + if(lostLine && timer.read_us() >= 300000) { break; }