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
Parent:
44:b4a00fbab06b
Child:
46:df2c2d25c070
--- 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;