Created LineScan library to interface with line scanner. Verified that it was able to store values form camera. Needs a means to detect the line (rising/falling edge detection) and actuate servo. Needs to be merged with other branch.

Files at this revision

API Documentation at this revision

Comitter:
ng3600
Date:
Fri Mar 13 06:26:35 2015 +0000
Commit message:
LineScan library to interface with the line scanner

Changed in this revision

LineScan.cpp Show annotated file Show diff for this revision Revisions of this file
LineScan.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 2d546112b0b8 LineScan.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LineScan.cpp	Fri Mar 13 06:26:35 2015 +0000
@@ -0,0 +1,67 @@
+/*
+AnalogIn cam1(CAM1_IN);
+DigitalOut camSi(CAM_SI);
+DigitalOut camClk(CAM_CLK); // Definining camera pins. 
+*/
+#include "LineScan.h"
+
+uint16_t read1Bit(AnalogIn cam, DigitalOut *camClk){
+    uint16_t pixel;
+    
+    //read pixel n
+    pixel = cam.read_u16();
+    
+    //clock pulse for next pixel n + 1
+    *camClk = 1;
+    *camClk = 0;
+    
+    return pixel;  //return result as an uint16_t (16 bit integer)
+}
+
+void startRead(DigitalOut *camSi, DigitalOut *camClk){
+    //pulse first clock cycle and start integral pin
+    *camSi = 1;
+    *camClk = 1;
+    *camSi = 0;
+    *camClk = 0;
+}
+
+int processFn(uint16_t *array, int arraySz){
+    int lineCtr = 0;
+    
+    //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;
+    }
+    
+    return lineCtr;
+}
+
+//call after integration time is done, returns index of array line is expected to be at
+int getLinePos(AnalogIn cam, DigitalOut *camSi, DigitalOut *camClk){
+    uint16_t lineAry[NUM_PIX];
+    int position;
+    
+    //read 
+    startRead(camSi, camClk);
+    for(int i = 0; i < NUM_PIX; i++){
+        lineAry[i] = read1Bit(cam, camClk);
+    }
+    
+    //process line scan data
+    position  = processFn(lineAry, NUM_PIX);
+    
+    return position;
+}
+
+/*
+sample call (handler thread):
+
+while(1){
+   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
diff -r 000000000000 -r 2d546112b0b8 LineScan.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LineScan.h	Fri Mar 13 06:26:35 2015 +0000
@@ -0,0 +1,9 @@
+#include "mbed.h"
+#include "rtos.h"
+
+#define NUM_PIX 128
+
+uint16_t read1Bit(AnalogIn cam, DigitalOut *camClk);
+void startRead(DigitalOut *camSi, DigitalOut *camClk);
+int processFn(uint16_t *array, int arraySz);
+int getLinePos(AnalogIn cam, DigitalOut *camSi, DigitalOut *camClk);
\ No newline at end of file