Moved to Team 9.
Fork of LineScan by
LineScan.cpp@4:91e7f2c8999f, 2015-03-31 (annotated)
- Committer:
- ikrase
- Date:
- Tue Mar 31 19:10:18 2015 +0000
- Revision:
- 4:91e7f2c8999f
- Parent:
- 1:f10ec868cd71
- Child:
- 5:9c19face64a7
telemetry changes to getlinepos
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ng3600 | 0:2d546112b0b8 | 1 | /* |
ng3600 | 0:2d546112b0b8 | 2 | AnalogIn cam1(CAM1_IN); |
ng3600 | 0:2d546112b0b8 | 3 | DigitalOut camSi(CAM_SI); |
ikrase | 1:f10ec868cd71 | 4 | DigitalOut camClk(CAM_CLK); // Definining camera pins. These are actually defined in Main... |
ng3600 | 0:2d546112b0b8 | 5 | */ |
ng3600 | 0:2d546112b0b8 | 6 | #include "LineScan.h" |
ng3600 | 0:2d546112b0b8 | 7 | |
ng3600 | 0:2d546112b0b8 | 8 | uint16_t read1Bit(AnalogIn cam, DigitalOut *camClk){ |
ng3600 | 0:2d546112b0b8 | 9 | uint16_t pixel; |
ng3600 | 0:2d546112b0b8 | 10 | |
ng3600 | 0:2d546112b0b8 | 11 | //read pixel n |
ng3600 | 0:2d546112b0b8 | 12 | pixel = cam.read_u16(); |
ng3600 | 0:2d546112b0b8 | 13 | |
ng3600 | 0:2d546112b0b8 | 14 | //clock pulse for next pixel n + 1 |
ng3600 | 0:2d546112b0b8 | 15 | *camClk = 1; |
ikrase | 1:f10ec868cd71 | 16 | *camClk = 0; // Apparently there is no need for any delay. It may be desireable to flatten this, or perhaps the compiler does it. |
ng3600 | 0:2d546112b0b8 | 17 | |
ng3600 | 0:2d546112b0b8 | 18 | return pixel; //return result as an uint16_t (16 bit integer) |
ng3600 | 0:2d546112b0b8 | 19 | } |
ng3600 | 0:2d546112b0b8 | 20 | |
ng3600 | 0:2d546112b0b8 | 21 | void startRead(DigitalOut *camSi, DigitalOut *camClk){ |
ng3600 | 0:2d546112b0b8 | 22 | //pulse first clock cycle and start integral pin |
ng3600 | 0:2d546112b0b8 | 23 | *camSi = 1; |
ng3600 | 0:2d546112b0b8 | 24 | *camClk = 1; |
ng3600 | 0:2d546112b0b8 | 25 | *camSi = 0; |
ng3600 | 0:2d546112b0b8 | 26 | *camClk = 0; |
ng3600 | 0:2d546112b0b8 | 27 | } |
ng3600 | 0:2d546112b0b8 | 28 | |
ng3600 | 0:2d546112b0b8 | 29 | int processFn(uint16_t *array, int arraySz){ |
ng3600 | 0:2d546112b0b8 | 30 | int lineCtr = 0; |
ng3600 | 0:2d546112b0b8 | 31 | |
ng3600 | 0:2d546112b0b8 | 32 | //replace with cross correlation function or averaging function |
ng3600 | 0:2d546112b0b8 | 33 | //currently returns index of smallest item |
ng3600 | 0:2d546112b0b8 | 34 | //skip 15 indices on both ends as they are noisy |
ng3600 | 0:2d546112b0b8 | 35 | for(int i = 16; i < arraySz - 15; i++){ |
ng3600 | 0:2d546112b0b8 | 36 | if(array[i] < array[lineCtr]) |
ng3600 | 0:2d546112b0b8 | 37 | lineCtr = i; |
ng3600 | 0:2d546112b0b8 | 38 | } |
ng3600 | 0:2d546112b0b8 | 39 | |
ng3600 | 0:2d546112b0b8 | 40 | return lineCtr; |
ng3600 | 0:2d546112b0b8 | 41 | } |
ng3600 | 0:2d546112b0b8 | 42 | |
ng3600 | 0:2d546112b0b8 | 43 | //call after integration time is done, returns index of array line is expected to be at |
ikrase | 4:91e7f2c8999f | 44 | int getLinePos(AnalogIn cam, DigitalOut *camSi, DigitalOut *camClk, telemetry::NumericArray<uint16_t, 128> &tele_linescan){ |
ikrase | 1:f10ec868cd71 | 45 | uint16_t lineAry[NUM_PIX]; // It might be nice to make this static and add double buffering and export of pointers like I had. |
ng3600 | 0:2d546112b0b8 | 46 | int position; |
ng3600 | 0:2d546112b0b8 | 47 | |
ng3600 | 0:2d546112b0b8 | 48 | //read |
ng3600 | 0:2d546112b0b8 | 49 | startRead(camSi, camClk); |
ng3600 | 0:2d546112b0b8 | 50 | for(int i = 0; i < NUM_PIX; i++){ |
ng3600 | 0:2d546112b0b8 | 51 | lineAry[i] = read1Bit(cam, camClk); |
ikrase | 4:91e7f2c8999f | 52 | tele_linescan[i] = lineAry[i]; |
ng3600 | 0:2d546112b0b8 | 53 | } |
ng3600 | 0:2d546112b0b8 | 54 | |
ng3600 | 0:2d546112b0b8 | 55 | //process line scan data |
ng3600 | 0:2d546112b0b8 | 56 | position = processFn(lineAry, NUM_PIX); |
ng3600 | 0:2d546112b0b8 | 57 | |
ng3600 | 0:2d546112b0b8 | 58 | return position; |
ng3600 | 0:2d546112b0b8 | 59 | } |
ng3600 | 0:2d546112b0b8 | 60 | |
ng3600 | 0:2d546112b0b8 | 61 | /* |
ng3600 | 0:2d546112b0b8 | 62 | sample call (handler thread): |
ng3600 | 0:2d546112b0b8 | 63 | |
ng3600 | 0:2d546112b0b8 | 64 | while(1){ |
ng3600 | 0:2d546112b0b8 | 65 | linePos = getLinePos(cameraIn1, si, clk); //volatile linePos, replace with steering angle and read 2 cameras? |
ng3600 | 0:2d546112b0b8 | 66 | Thread::wait(14); //sleep for 14 us |
ng3600 | 0:2d546112b0b8 | 67 | } |
ng3600 | 0:2d546112b0b8 | 68 | */ |