E=MC / Mbed 2 deprecated coolcarsuperfast2

Dependencies:   mbed MODSERIAL telemetry-master

Fork of coolcarsuperfast by Michael Romain

Revision:
11:b59ec039a712
Parent:
10:e40ad924e935
Child:
12:48b76450c4b4
--- a/main.cpp	Mon Apr 06 19:28:45 2015 +0000
+++ b/main.cpp	Thu Apr 09 01:13:49 2015 +0000
@@ -26,9 +26,15 @@
 float approxPos;
 float maxVal;
 int maxLoc;
+int maxSlopeLoc [5];
+int minSlopeLoc [5];
+
+//Brightness accommodater
+int intTimMod = 0;
 
 //Data Collection
 bool dataCol = false;
+int loopCounterForModdingSoThatWeCanIncreaseTheRecordingTime;
 
 //Line Crossing variables
 int prevTrackLoc;
@@ -304,15 +310,15 @@
     
     wait(3);
 
-    motor1.pulsewidth(motorPeriod*pulsewidth);
-    motor2.pulsewidth(motorPeriod*pulsewidth);
+    //motor1.pulsewidth(motorPeriod*pulsewidth);
+    //motor2.pulsewidth(motorPeriod*pulsewidth);
     break1 = 0;
     break2 = 0;
     
     //t.start();
     
     if(dataCol){
-        int loopCounterForModdingSoThatWeCanIncreaseTheRecordingTime = 0;
+        loopCounterForModdingSoThatWeCanIncreaseTheRecordingTime = 0;
         printTimer.start();
     }
 
@@ -345,6 +351,8 @@
             maxCount = 0;
             approxPos = 0;
             
+            maxSlopeLoc[0] = 0;
+            maxSlopeLoc[0] = 0;
             space = false;
 
         }
@@ -365,16 +373,26 @@
             }
             
             for (int c = 10; c < 118; c++) {
-                if (ADCdata[c] <= maxVal && maxVal - ADCdata[c] < 0.07f && ADCdata[c] > 0.1f){
-                    maxAccum += c;
-                    maxCount++;
-                    if (c > prevTrackLoc + spaceThresh){
-                        space = true;
+                    if (ADCdata[c] <= maxVal && maxVal - ADCdata[c] < 0.005f /*&& ADCdata[c] > 0.1f*/){
+                        maxAccum += c;
+                        maxCount++;
+                        if (c > prevTrackLoc + spaceThresh){
+                            space = true;
+                        }
+                        prevTrackLoc = c;
                     }
-                    prevTrackLoc = c;
+            }
+            
+            //Check if we need to alter integration time due to brightness
+            if (maxVal < 0.15f){
+                intTimMod += 10;
+            } else if (maxVal >= 1) {
+                if (intTimMod > 0) {
+                    intTimMod -= 10;
                 }
             }
             
+            
             //Line Crossing Checks
             if (space) {
                 currDir = prevDir;
@@ -389,7 +407,7 @@
                     }
                 }
                 
-                currDir = hardLeft + approxPos/((float) 127)*(hardRight-hardLeft);
+                currDir = hardLeft + (approxPos - 10)/((float) 108)*(hardRight-hardLeft);
                 
 
             }
@@ -428,7 +446,7 @@
         }
         else{
             clk = 1;
-            wait_us(10);
+            wait_us(10 + intTimMod);
             ADCdata[integrationCounter - 1] = camData;
             clk = 0;
         }