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:
42:96671b71aac5
Parent:
41:3ead1dd2cc3a
Child:
43:0e985a58f174
--- a/test.cpp	Thu Jul 25 03:20:41 2019 +0000
+++ b/test.cpp	Sat Jul 27 20:58:46 2019 +0000
@@ -208,7 +208,7 @@
     
     Pacer reportPacer(200000);
     
-    loadCalibration();
+    loadLineCalibration();
     uint16_t loopCount = 0;
     while(1)
     {
@@ -290,6 +290,8 @@
 
 void testReckoner()
 {
+    doGyroCalibration();
+    led1 = 1;
     Pacer reportPacer(100000);
     while(1)
     {
@@ -311,26 +313,32 @@
 void testTurnSensor()
 {
     pc.printf("Test turn sensor\r\n");
-    Pacer reportPacer(200000);
-    TurnSensor turnSensor;
+    led1 = 1;
+    doGyroCalibration();
+    //Pacer reportPacer(200000);  // 0.2 s
+    Pacer reportPacer(10000000);  // 10 s
+    Timer timer;
+    led2 = 1;
+    timer.start();
     turnSensor.start();
     while(1)
     {
         turnSensor.update();
         if (reportPacer.pace())
         {
-            pc.printf("%d\r\n", turnSensor.getAngleDegrees());
+            pc.printf("%u, %d, %d\r\n",
+              timer.read_ms(),
+              turnSensor.getAngleDegrees(),
+              turnSensor.getAngleMillidegrees());
         }
     }
 }
 
-void testL3gAndCalibrate()
+void testL3gAndShowAverage()
 {
     wait_ms(2000);
     Pacer reportPacer(750000);
     Pacer readingPacer(2000);
-    Timer timer;
-    timer.start();
     int32_t total = 0;
     int32_t readingCount = 0;
     while(1)
@@ -384,7 +392,7 @@
             reportedReading = false;
             if (gz > 100 || gz < -100)
             {
-                pc.printf("%d, %d\r\n", timer.read_us(), gz); 
+                pc.printf("%u, %d\r\n", timer.read_us(), gz); 
                 reportedReading = true;
             }
         }
@@ -395,7 +403,7 @@
 
         if (reportPacer.pace() && !reportedReading)
         {
-            pc.printf("%d, %d\r\n", timer.read_us(), gz);
+            pc.printf("%u, %d\r\n", timer.read_us(), gz);
             reportedReading = true;
         }
     }