David's dead reckoning code for the LVBots competition on March 6th. Uses the mbed LPC1768, DRV8835, QTR-3RC, and two DC motors with encoders.
Dependencies: PololuEncoder Pacer mbed GeneralDebouncer
Diff: test.cpp
- Revision:
- 46:df2c2d25c070
- Parent:
- 45:81dd782bc0b4
diff -r 81dd782bc0b4 -r df2c2d25c070 test.cpp --- a/test.cpp Sun Jul 28 01:52:34 2019 +0000 +++ b/test.cpp Sun Jul 28 22:20:12 2019 +0000 @@ -108,19 +108,18 @@ // This also tests the LineTracker by printing out a lot of data from it. void testLineFollowing() { + loadLineCalibration(); doGyroCalibration(); turnSensor.start(); - led1 = 1; - while(!button1DefinitelyPressed()) + led1 = 1; + while (!button1DefinitelyPressed()) { updateReckoner(); } - led2 = 1; Pacer reportPacer(200000); - loadLineCalibration(); uint16_t loopCount = 0; while(1) { @@ -131,6 +130,10 @@ loopCount += 1; + led2 = lineTracker.calibratedValues[0] > 500; + led3 = lineTracker.calibratedValues[1] > 500; + led4 = lineTracker.calibratedValues[2] > 500; + if (lineVisiblePrevious != lineTracker.getLineVisible()) { pc.printf("%5d ! %1d %4d | %5d %5d | %4d %4d %4d\r\n", @@ -327,30 +330,36 @@ void testLineSensorsAndCalibrate() { - led1 = 1; Pacer reportPacer(100000); const uint16_t * values = lineTracker.rawValues; const uint16_t * min = lineTracker.calibratedMinimum; const uint16_t * max = lineTracker.calibratedMaximum; + const uint16_t * calValues = lineTracker.calibratedValues; + + // Comment this out, and hold down button 1 while exposing the line sensor + // to its typical surfaces to do calibration. + loadLineCalibration(); const bool printBarGraph = true; while (1) { lineTracker.read(); - // Hold down button 1 and expose the line sensor to its typical - // values to do calibration. if (button1DefinitelyPressed()) { - led2 = 1; + led1 = 0; lineTracker.updateCalibration(); } else { - led2 = 0; + led1 = 1; } + led2 = calValues[0] > 500; + led3 = calValues[1] > 500; + led4 = calValues[2] > 500; + if (reportPacer.pace()) { if (printBarGraph)