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:
46:df2c2d25c070
Parent:
31:739b91331f31
--- a/line_tracker.cpp	Sun Jul 28 01:52:34 2019 +0000
+++ b/line_tracker.cpp	Sun Jul 28 22:20:12 2019 +0000
@@ -24,20 +24,20 @@
 
 void LineTracker::updateCalibratedValues()
 {
-    for(uint8_t s = 0; s < LINE_SENSOR_COUNT; s++)
+    for (uint8_t s = 0; s < LINE_SENSOR_COUNT; s++)
     {
         uint16_t calmin = calibratedMinimum[s];
         uint16_t calmax = calibratedMaximum[s];
         uint16_t denominator = calmax - calmin;
         int32_t x = 0;
-        if(denominator != 0)
+        if (denominator != 0)
         {
             x = ((int32_t)rawValues[s] - calmin) * 1000 / denominator;
-            if(x < 0)
+            if (x < 0)
             {
                 x = 0;
             }
-            else if(x > 1000)
+            else if (x > 1000)
             {
                 x = 1000;
             }
@@ -52,7 +52,7 @@
     uint32_t sum = 0;
     
     lineVisible = false;
-    for(uint8_t s = 0; s < LINE_SENSOR_COUNT; s++)
+    for (uint8_t s = 0; s < LINE_SENSOR_COUNT; s++)
     {
         // keep track of whether we see the line at all
         uint16_t value = calibratedValues[s];
@@ -71,15 +71,15 @@
     
     if (lineVisible)
     {
-        linePosition = avg/sum;   
+        linePosition = avg / sum;   
     }
     else
     {
         // We cannot see the line, so just snap the position to the left-most or right-most
         // depending on what we saw previousl.
         
-        const uint32_t max = (LINE_SENSOR_COUNT-1)*1000;
-        if(linePosition < max/2)
+        const uint32_t max = (LINE_SENSOR_COUNT - 1) * 1000;
+        if(linePosition < max / 2)
         {
             linePosition = 0;
         }