Moved to Team 9.

Fork of LineScan by Nicholas Gan

Revision:
2:6a87b2348245
Parent:
1:f10ec868cd71
Child:
3:f31986cb68fd
--- a/LineScan.cpp	Fri Mar 13 08:18:05 2015 +0000
+++ b/LineScan.cpp	Thu Mar 19 19:13:34 2015 +0000
@@ -27,17 +27,34 @@
 }
 
 int processFn(uint16_t *array, int arraySz){
-    int lineCtr = 0;
+    int avg[NUM_PIX];
+    int diff[NUM_PIX];
+    int highest = 0;
+    int lowest = 0;
+    int h_idx = NUM_PIX/2;
+    int l_idx = NUM_PIX/2;
     
-    //replace with cross correlation function or averaging function
-    //currently returns index of smallest item
-    //skip 15 indices on both ends as they are noisy
-    for(int i = 16; i < arraySz - 15; i++){
-        if(array[i] < array[lineCtr])
-            lineCtr = i;
+    //Just finds line center, does not track crossings
+    if(array){
+        avg[0] = array[0];
+        diff[0] = 0;
+        
+        for(int i = 1; i < NUM_PIX; i++){
+            avg[i] = array[i - 1]/2 + array[i]/2;
+            diff[i] = avg[i - 1] - avg[i];
+            
+            if(diff[i] > highest){
+                highest = diff[i];
+                h_idx = i;
+            }
+            else if(diff[i] < lowest){
+                lowest = diff[i];
+                l_idx = i;
+            }
+        }
     }
     
-    return lineCtr;
+    return (h_idx + l_idx)/2;
 }
 
 //call after integration time is done, returns index of array line is expected to be at
@@ -64,4 +81,4 @@
    linePos  = getLinePos(cameraIn1, si, clk);   //volatile linePos, replace with steering angle and read 2 cameras?
    Thread::wait(14);    //sleep for 14 us
 }
-*/
\ No newline at end of file
+*/