Moved to Team 9.

Fork of LineScan by Nicholas Gan

Revision:
23:a1a671d3c9e5
Parent:
22:0136520fe249
--- a/LineScan.cpp	Sat Apr 18 09:00:19 2015 +0000
+++ b/LineScan.cpp	Sat Apr 18 13:44:05 2015 +0000
@@ -8,8 +8,8 @@
 #define THRESH 5000
 
 #define MEAN_REF 20000      //ideal mean we should see
-#define BRIGHTEST_REF 40000
-#define CAM_CTRL_GAIN 0.0005 //should be small
+#define BRIGHTEST_REF 50000
+#define CAM_CTRL_GAIN 0.0003 //should be small
 
 uint16_t read1Bit(AnalogIn cam, DigitalOut *camClk){
     uint16_t pixel;
@@ -59,8 +59,8 @@
             avg[i] = array[i - 1 + SKIP]/2 + array[i + SKIP]/2;   //smoothing
             diff[i] = avg[i - 1] - avg[i];          //differential
             
+            //total = avg[i];    //AGC
             if (avg[i] > brightest) {
-                total = avg[i];    //AGC
                 brightest = avg[i];
             }
             
@@ -74,8 +74,8 @@
             }
         }
         //AGC, simple proportional controller
-        total = total / frameLen;
-        exposureChange = ((float)(BRIGHTEST_REF - total)) * CAM_CTRL_GAIN;    
+        //total = total / frameLen;
+        exposureChange = ((float)(BRIGHTEST_REF - brightest)) * CAM_CTRL_GAIN;    
         *exposure += (int)exposureChange;
         if(*exposure < 1)
             *exposure = 1;
@@ -86,9 +86,9 @@
     if (highest > THRESH && -1 * lowest > THRESH)
         return ((float) h_idx + (float) l_idx) / (2*(float)frameLen);
     else if(highest > THRESH && -1 * lowest < THRESH )
-        return ((float) h_idx + (float)left_bound - (float)(right_bound - h_idx)) / (2*(float)frameLen);    //0.5 is center
+        return ((float) h_idx + (float)left_bound - 1.5*(float)(right_bound - h_idx)) / (2*(float)frameLen);    //0.5 is center
     else if (-1*lowest > THRESH && highest < THRESH )
-        return ((float) l_idx + (float)right_bound + (float)(l_idx - left_bound)) / (2*(float)frameLen);
+        return ((float) l_idx + (float)right_bound + 1.5*(float)(l_idx - left_bound)) / (2*(float)frameLen);
     else
         return -1.0;  //invalid read
 }