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
Revision 45:81dd782bc0b4, committed 2019-07-28
- Comitter:
- DavidEGrayson
- Date:
- Sun Jul 28 01:52:34 2019 +0000
- Parent:
- 44:b4a00fbab06b
- Child:
- 46:df2c2d25c070
- Commit message:
- Calibrate the line sensors. Add testLineSensorsAndCalibrate. Unfortunately, testLineFollowing is not working though.
Changed in this revision
--- a/main.cpp Sun Jul 28 01:22:01 2019 +0000 +++ b/main.cpp Sun Jul 28 01:52:34 2019 +0000 @@ -53,19 +53,18 @@ buttonsInit(); // Test routines - //testMotors(); + //testButtons(); //testEncoders(); + //testMotors(); //testMotorSpeed(); - //testLineSensors(); //testL3g(); //testL3gAndShowAverage(); //testTurnSensor(); //testReckoner(); - //testButtons(); - testDriveHome(); - //testFinalSettleIn(); - //testCalibrate(); - //testLineFollowing(); + //testDriveHome(); + //testFinalSettleIn(); // doesn't really work + //testLineSensorsAndCalibrate(); + testLineFollowing(); //testTurnInPlace(); //testCloseness(); //testLogger(); @@ -137,13 +136,22 @@ void loadLineCalibration() { - /** 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-3RC calibration from contest in 2014. + //lineTracker.calibratedMinimum[0] = 100; + //lineTracker.calibratedMaximum[0] = 792; + //lineTracker.calibratedMinimum[1] = 94; + //lineTracker.calibratedMaximum[1] = 807; + //lineTracker.calibratedMinimum[2] = 103; + //lineTracker.calibratedMaximum[2] = 1000; + + // QTR-3RC calibration from David's home setup, 2019-07-27. + // Generated with testLineSensorsAndCalibrate(). + lineTracker.calibratedMinimum[0] = 210; + lineTracker.calibratedMaximum[0] = 757; + lineTracker.calibratedMinimum[1] = 197; + lineTracker.calibratedMaximum[1] = 1000; + lineTracker.calibratedMinimum[2] = 203; + lineTracker.calibratedMaximum[2] = 746; } void updateReckoner()
--- a/test.cpp Sun Jul 28 01:22:01 2019 +0000 +++ b/test.cpp Sun Jul 28 01:52:34 2019 +0000 @@ -325,34 +325,30 @@ } } -void testLineSensors() +void testLineSensorsAndCalibrate() { led1 = 1; Pacer reportPacer(100000); - Pacer clearStatsPacer(2000000); - uint16_t min[LINE_SENSOR_COUNT]; - uint16_t max[LINE_SENSOR_COUNT]; - - bool const printBarGraph = true; + const uint16_t * values = lineTracker.rawValues; + const uint16_t * min = lineTracker.calibratedMinimum; + const uint16_t * max = lineTracker.calibratedMaximum; + + const bool printBarGraph = true; while (1) - { - if (clearStatsPacer.pace()) + { + lineTracker.read(); + + // Hold down button 1 and expose the line sensor to its typical + // values to do calibration. + if (button1DefinitelyPressed()) { - for(uint8_t i = 0; i < LINE_SENSOR_COUNT; i++) - { - min[i] = 0xFFFF; - max[i] = 0; - } + led2 = 1; + lineTracker.updateCalibration(); } - - uint16_t values[3]; - readSensors(values); - - for(uint8_t i = 0; i < LINE_SENSOR_COUNT; i++) + else { - if (values[i] > max[i]){ max[i] = values[i]; } - if (values[i] < min[i]){ min[i] = values[i]; } + led2 = 0; } if (reportPacer.pace()) @@ -375,50 +371,6 @@ } } -// Values from David's office Values from dev lab, -// in the day time, 2014-02-27: 2014-02-27: -// # calmin calmax -// 0 34872 59726 0 40617 60222 -// 1 29335 60110 1 36937 61198 -// 2 23845 58446 2 33848 58862 -void testCalibrate() -{ - Timer timer; - timer.start(); - - Pacer reportPacer(200000); - - bool doneCalibrating = false; - - led1 = 1; - - while(1) - { - lineTracker.read(); - if(!doneCalibrating) - { - lineTracker.updateCalibration(); - } - - led3 = doneCalibrating; - led4 = lineTracker.getLineVisible(); - - if (button1DefinitelyPressed()) - { - doneCalibrating = true; - } - - if (reportPacer.pace()) - { - pc.printf("\x1B[0;0H"); // VT100 command for "go to 0,0" - for(uint8_t s = 0; s < LINE_SENSOR_COUNT; s++) - { - pc.printf("%-2d %5d %5d %5d\r\n", s, lineTracker.calibratedMinimum[s], lineTracker.rawValues[s], lineTracker.calibratedMaximum[s]); - } - } - } -} - void testMotorSpeed() { led1 = 1;
--- a/test.h Sun Jul 28 01:22:01 2019 +0000 +++ b/test.h Sun Jul 28 01:52:34 2019 +0000 @@ -1,17 +1,16 @@ #pragma once +void __attribute__((noreturn)) testButtons(); void __attribute__((noreturn)) testEncoders(); void __attribute__((noreturn)) testMotors(); void __attribute__((noreturn)) testMotorSpeed(); -void __attribute__((noreturn)) testLineSensors(); void __attribute__((noreturn)) testL3g(); void __attribute__((noreturn)) testL3gAndShowAverage(); void __attribute__((noreturn)) testTurnSensor(); void __attribute__((noreturn)) testReckoner(); -void __attribute__((noreturn)) testButtons(); void __attribute__((noreturn)) testDriveHome(); +void __attribute__((noreturn)) testLineSensorsAndCalibrate(); void __attribute__((noreturn)) testFinalSettleIn(); -void __attribute__((noreturn)) testCalibrate(); void __attribute__((noreturn)) testLineFollowing(); void __attribute__((noreturn)) testTurnInPlace(); void __attribute__((noreturn)) testCloseness();