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:
28:4374035df5e0
Parent:
24:fc01d9125d3b
Child:
29:cfcf08d8ac79
--- a/test.cpp	Sat Mar 01 01:46:35 2014 +0000
+++ b/test.cpp	Sat Mar 01 03:13:57 2014 +0000
@@ -16,6 +16,74 @@
 void __attribute__((noreturn)) infiniteReckonerReportLoop();
 void printBar(const char * name, uint16_t adcResult);
 
+void testAnalog()
+{
+    AnalogIn testInput(p18);
+    
+    uint32_t badCount = 0, goodCount = 0;
+    
+    Pacer reportPacer(1000000);
+    while(1)
+    {
+        uint16_t reading = testInput.read_u16();
+        if(reading > 100)
+        {
+            badCount += 1;
+            pc.printf("%5d %11d %11d\r\n", reading, badCount, goodCount);   
+        }
+        else
+        {
+            goodCount += 1;   
+        }
+        
+        if (reportPacer.pace())
+        {
+            pc.printf("Hello\r\n");   
+        }
+    }
+}
+
+// This also tests the LineTracker by printing out a lot of data from it.
+void testLineFollowing()
+{
+    led1 = 1;   
+    while(!button1DefinitelyPressed())
+    {
+        updateReckonerFromEncoders();
+    }
+    led2 = 1;
+    
+    Pacer reportPacer(200000);
+    
+    loadCalibration();
+    uint16_t loopCount = 0;
+    while(1)
+    {
+        updateReckonerFromEncoders();
+        bool lineVisiblePrevious = lineTracker.getLineVisible();
+        lineTracker.read();
+        updateMotorsToFollowLine();
+        
+        loopCount += 1;
+        
+        if (lineVisiblePrevious != lineTracker.getLineVisible())
+        {
+            pc.printf("%5d ! %1d %4d | %4d %4d %4d | %5d %5d %5d\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]
+                );
+        }
+        
+        if (reportPacer.pace())
+        {
+            pc.printf("%5d   %1d %4d | %4d %4d %4d\r\n", loopCount, lineTracker.getLineVisible(), lineTracker.getLinePosition(),
+                lineTracker.calibratedValues[0], lineTracker.calibratedValues[1], lineTracker.calibratedValues[2]
+                );
+        }
+    }
+}
+
 void testDriveHome()
 {
     led1 = 1;