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:
33:58a0ab6e9ad2
Parent:
32:83a13b06093c
Child:
34:6c84680d823a
--- a/main.cpp	Tue Mar 04 04:32:51 2014 +0000
+++ b/main.cpp	Wed Mar 05 02:50:09 2014 +0000
@@ -16,7 +16,7 @@
 Reckoner reckoner;
 LineTracker lineTracker;
 
-const int16_t drivingSpeed = 300;
+const int16_t drivingSpeed = 400;
 
 void setLeds(bool v1, bool v2, bool v3, bool v4)
 {
@@ -41,30 +41,36 @@
     //testLineSensors();
     //testReckoner();
     //testButtons();
-    //testDriveHome();
+    testDriveHome();
     //testFinalSettleIn();
     //testCalibrate();
-    testLineFollowing();
+    //testLineFollowing();
     //testAnalog();
     //testSensorGlitches();
+    //testTurnInPlace();
+    //testCloseness();
 
     // Real routines for the contest.
     loadCalibration();
     
     setLeds(1, 0, 0, 0);
     waitForSignalToStart();
-    setLeds(0, 1, 0, 0);
     
+    setLeds(0, 1, 0, 0);    
     findLine();
     
     //setLeds(1, 1, 0, 0);
     //turnRightToFindLine();
+    
     setLeds(0, 0, 1, 0);
     followLineToEnd();
+    
     setLeds(1, 0, 1, 0);
     driveHomeAlmost();
-    setLeds(0, 1, 1, 0);
-    finalSettleIn();
+    
+    //setLeds(0, 1, 1, 0);
+    //finalSettleIn();
+    
     setLeds(1, 1, 1, 1);
     while(1){}
 }
@@ -178,7 +184,7 @@
 
 void updateMotorsToFollowLine()
 {
-    const int followLineStrength = 300;
+    const int followLineStrength = drivingSpeed;
 
     int16_t speedLeft = drivingSpeed;
     int16_t speedRight = drivingSpeed;
@@ -206,13 +212,14 @@
         updateMotorsToDriveStraight();        
         lineStatus.update(lineTracker.getLineVisible());       
 
-        if(lineStatus.getState() == true && lineStatus.getTimeInCurrentStateMicroseconds() > 100000)
+        if(lineStatus.getState() == true && lineStatus.getTimeInCurrentStateMicroseconds() > 20000)
         {
             break;
         }
     }
 }
 
+/**
 void turnRightToFindLine()
 {   
     while(1)
@@ -228,7 +235,7 @@
         
         motorsSpeedSet(300, 100);        
     }
-}
+}**/
 
 void followLineToEnd()
 {
@@ -267,9 +274,9 @@
         
         float magn = magnitude();
         
-        if (magn < (1<<17))  
+        if (magn < (1<<(14+7)))  
         {
-            // We are within 8 encoder ticks, so go to the next step.
+            // We are within 128 encoder ticks, so go to the next step.
             break;
         }
         
@@ -277,9 +284,9 @@
         
         int16_t speedLeft = drivingSpeed;
         int16_t speedRight = drivingSpeed;
-        if (magn < (1<<20)) // Within 64 encoder ticks of the origin, so slow down.
+        if (magn < (1<<(14+9))) // Within 512 encoder ticks of the origin, so slow down.
         {
-            int16_t reduction = (1 - magn/(1<<20)) * drivingSpeed;
+            int16_t reduction = (1 - magn/(1<<(14+8))) * (drivingSpeed/2);
             speedLeft = reduceSpeed(speedLeft, reduction);
             speedRight = reduceSpeed(speedRight, reduction);
         }