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: main.cpp
- Revision:
- 42:96671b71aac5
- Parent:
- 41:3ead1dd2cc3a
- Child:
- 43:0e985a58f174
diff -r 3ead1dd2cc3a -r 96671b71aac5 main.cpp --- a/main.cpp Thu Jul 25 03:20:41 2019 +0000 +++ b/main.cpp Sat Jul 27 20:58:46 2019 +0000 @@ -58,7 +58,7 @@ //testMotorSpeed(); //testLineSensors(); //testL3g(); - //testL3gAndCalibrate(); + //testL3gAndShowAverage(); testTurnSensor(); //testReckoner(); //testButtons(); @@ -72,7 +72,8 @@ //testCloseness(); //testLogger(); - loadCalibration(); + loadLineCalibration(); + doGyroCalibration(); doDeadReckoning(); } @@ -126,8 +127,17 @@ } } +void doGyroCalibration() +{ + wait_ms(1000); // Time for the robot to stop moving. + while (!l3gCalibrateDone()) + { + l3gCalibrate(); + wait_ms(2); + } +} -void loadCalibration() +void loadLineCalibration() { /** QTR-3RC **/ lineTracker.calibratedMinimum[0] = 100; @@ -136,15 +146,6 @@ 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; - **/ } void updateReckonerFromEncoders()