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 32:83a13b06093c, committed 2014-03-04
- Comitter:
- DavidEGrayson
- Date:
- Tue Mar 04 04:32:51 2014 +0000
- Parent:
- 31:739b91331f31
- Child:
- 33:58a0ab6e9ad2
- Commit message:
- getting line sensors to work again;
Changed in this revision
--- a/line_sensors.cpp Tue Mar 04 03:04:00 2014 +0000 +++ b/line_sensors.cpp Tue Mar 04 04:32:51 2014 +0000 @@ -10,9 +10,9 @@ **/ DigitalInOut lineSensorsDigital[LINE_SENSOR_COUNT] = { - DigitalInOut(p18), // brown wire, left-most sensor + DigitalInOut(p18), // white wire, left-most sensor DigitalInOut(p19), // orange wire, middle sensor - DigitalInOut(p20), // blue wire, right-most sensor + DigitalInOut(p20), // brown wire, right-most sensor }; void readSensors(uint16_t * values)
--- 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)
--- a/main.h Tue Mar 04 03:04:00 2014 +0000 +++ b/main.h Tue Mar 04 04:32:51 2014 +0000 @@ -16,7 +16,6 @@ void updateReckonerFromEncoders(); float determinant(); float dotProduct(); -bool calibrationLooksGood(); extern Reckoner reckoner; extern LineTracker lineTracker;
--- a/motors.cpp Tue Mar 04 03:04:00 2014 +0000 +++ b/motors.cpp Tue Mar 04 04:32:51 2014 +0000 @@ -15,6 +15,9 @@ DigitalOut motorLeftDir(p25); DigitalOut motorRightDir(p23); +int16_t motorLeftSpeed = 0;; +int16_t motorRightSpeed = 0; + void motorsInit() { //PwmOut(p26).period_us(100); @@ -45,8 +48,11 @@ LPC_PWM1->TCR = (1 << 0) | (1 << 3); // Enable the PWM counter and enable PWM. } -void motorsSpeedSet(int16_t motorLeftSpeed, int16_t motorRightSpeed) +void motorsSpeedSet(int16_t newMotorLeftSpeed, int16_t newMotorRightSpeed) { + motorLeftSpeed = newMotorLeftSpeed; + motorRightSpeed = newMotorRightSpeed; + if (motorLeftSpeed < 0) { motorLeftSpeed = -motorLeftSpeed;
--- a/motors.h Tue Mar 04 03:04:00 2014 +0000 +++ b/motors.h Tue Mar 04 04:32:51 2014 +0000 @@ -2,3 +2,5 @@ void motorsInit(); void motorsSpeedSet(int16_t motorLeftSpeed, int16_t motorRightSpeed); + +extern int16_t motorLeftSpeed, motorRightSpeed; \ No newline at end of file
--- a/test.cpp Tue Mar 04 03:04:00 2014 +0000 +++ b/test.cpp Tue Mar 04 04:32:51 2014 +0000 @@ -183,16 +183,18 @@ if (lineVisiblePrevious != lineTracker.getLineVisible()) { - pc.printf("%5d ! %1d %4d | %4d %4d %4d | %5d %5d %5d\r\n", + pc.printf("%5d ! %1d %4d | %5d %5d | %4d %4d %4d\r\n", loopCount, lineTracker.getLineVisible(), lineTracker.getLinePosition(), - lineTracker.calibratedValues[0], lineTracker.calibratedValues[1], lineTracker.calibratedValues[2], - lineTracker.rawValues[0], lineTracker.rawValues[1], lineTracker.rawValues[2] + motorLeftSpeed, motorRightSpeed, + lineTracker.calibratedValues[0], lineTracker.calibratedValues[1], lineTracker.calibratedValues[2] ); } if (reportPacer.pace()) { - pc.printf("%5d %1d %4d | %4d %4d %4d\r\n", loopCount, lineTracker.getLineVisible(), lineTracker.getLinePosition(), + pc.printf("%5d %1d %4d | %5d %5d | %4d %4d %4d\r\n", + loopCount, lineTracker.getLineVisible(), lineTracker.getLinePosition(), + motorLeftSpeed, motorRightSpeed, lineTracker.calibratedValues[0], lineTracker.calibratedValues[1], lineTracker.calibratedValues[2] ); } @@ -341,7 +343,6 @@ lineTracker.updateCalibration(); } - led2 = calibrationLooksGood(); led3 = doneCalibrating; led4 = lineTracker.getLineVisible(); @@ -357,14 +358,6 @@ { pc.printf("%-2d %5d %5d %5d\r\n", s, lineTracker.calibratedMinimum[s], lineTracker.rawValues[s], lineTracker.calibratedMaximum[s]); } - if (calibrationLooksGood()) - { - pc.puts("Good. \r\n"); - } - else - { - pc.puts("Not good yet.\r\n"); - } } } }