Moved to Team 9.
Fork of LineScan by
Diff: LineScan.cpp
- Revision:
- 8:b9ec2f3e12b6
- Parent:
- 7:7d3b6edd783e
- Child:
- 9:5226617d2019
--- a/LineScan.cpp Tue Mar 31 23:34:18 2015 +0000 +++ b/LineScan.cpp Thu Apr 02 18:38:29 2015 +0000 @@ -5,7 +5,9 @@ */ #include "LineScan.h" -#define MEAN_REF 15000 //ideal difference we should see +#define THRESH 10000 + +#define MEAN_REF 30000 //ideal difference we should see #define CAM_CTRL_GAIN 0.001 //should be small uint16_t read1Bit(AnalogIn cam, DigitalOut *camClk){ @@ -29,24 +31,25 @@ *camClk = 0; } -int processFn(uint16_t *array, int arraySz, int* exposure){ - int avg[NUM_PIX]; - int diff[NUM_PIX]; +float processFn(uint16_t *array, int arraySz, int* exposure){ + int frameLen = NUM_PIX - 2 * SKIP; + int avg[frameLen]; + int diff[frameLen]; int highest = 0; int lowest = 0; - int h_idx = NUM_PIX/2; - int l_idx = NUM_PIX/2; + int h_idx = frameLen/2; + int l_idx = frameLen/2; //for AGC float exposureChange; //Just finds line center, does not track crossings (needs this feature) if(array){ - avg[0] = array[0]; + avg[0] = array[SKIP - 1]/2 + array[SKIP]/2; diff[0] = 0; - for(int i = 1; i < NUM_PIX; i++){ - avg[i] = array[i - 1]/2 + array[i]/2; //smoothing + for(int i = 1; i < frameLen; i++){ + avg[i] = array[i - 1 + SKIP]/2 + array[i + SKIP]/2; //smoothing diff[i] = avg[i - 1] - avg[i]; //differential if(diff[i] > highest){ @@ -58,7 +61,7 @@ l_idx = i; } } - exposureChange = ((float)(MEAN_REF - highest)) * CAM_CTRL_GAIN; //AGC, simple proportional controller + exposureChange = ((float)(MEAN_REF - highest + lowest)) * CAM_CTRL_GAIN; //AGC, simple proportional controller *exposure += (int)exposureChange; if(*exposure <= 0) *exposure = 1; @@ -66,13 +69,13 @@ *exposure = 40; } - return (h_idx + l_idx)/2; + return ((float)(h_idx + l_idx)) / (2.0 * (float)frameLen); //0 is center } //call after integration time is done, returns index of array line is expected to be at and new exposure time -int getLinePos(AnalogIn cam, DigitalOut *camSi, DigitalOut *camClk, int *exposure){ // telemetry::NumericArray<uint16_t, 128> &tele_linescan){ +float getLinePos(AnalogIn cam, DigitalOut *camSi, DigitalOut *camClk, int *exposure){ // telemetry::NumericArray<uint16_t, 128> &tele_linescan){ uint16_t lineAry[NUM_PIX]; - int position; + float position; //read startRead(camSi, camClk);