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:
13:bba5b3abd13f
Parent:
12:835a4d24ae3b
Child:
21:c279c6a83671
--- a/reckoner.h	Sun Feb 23 22:23:34 2014 +0000
+++ b/reckoner.h	Sun Feb 23 23:49:58 2014 +0000
@@ -1,7 +1,3 @@
-// Robot configuration:
-
-// General purpose code:
-
 class Reckoner
 {
     public:
@@ -9,28 +5,15 @@
     Reckoner();
     
     // Together, cos and sin form a vector with a magnitude close to 2^30 that indicates
-    // the current position of the robot.  By definition, when the reckoning starts,
-    // sin is 0 and cos is 2^30.
+    // the current position of the robot.
     // cos corresponds to the x component of the orientation vector.
     // sin corresponds to the y component of the orientation vector.
     int32_t cos, sin;
     
     // Together, x and y are a vector that points from the starting point to the
     // robot's current position.
-    // Units:
-    // * If the units are too big, precision is lost.
-    // * If they are too small, the integers wil overflow.
-    // * For convenience, they should be a power of 2 off from Df (Distance robot moves
-    //   forward per encoder tick), so we can just write x += cos >> some_constant.
-    // * Worst case for overflow: our encoders give us a Df of 0.25mm and our robot moves
-    //   5m away from the starting point.  Therefore, x and y might need to hold a value
-    //   20000 or -20000 without overflowing.
-    //   Overflow condition:              x = (1<<31)
-    //                20000*Df < max_dist_x = (1<<31) * U
-    //                                U > Df * (20000) / (1<<31) = Df / (1<<16)
-    // * Therefore the units we choose for x are Df / (1<<16).
-    // * If we wrote x += cos it would mean the units are Df / (1<<30).
-    //   Instead, we write x += cos >> 14 so the units are correct.
+    // The untis are Df / (1<<14), where Df is the distance the robot moves forward
+    // or backwards due to a single encoder tick.
     int32_t x, y;
 
     void handleTickLeftForward();