Clark Lin
/
BX-car_s
QQQ
Fork of BX-car_s by
camera_api.cpp@23:d6d4e8adf7fe, 2014-07-02 (annotated)
- Committer:
- physicsgood
- Date:
- Wed Jul 02 13:33:49 2014 +0000
- Revision:
- 23:d6d4e8adf7fe
- Parent:
- 22:1464a3f0a290
QQQQ
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
backman | 1:82bc25a7b68b | 1 | #include "mbed.h" |
backman | 1:82bc25a7b68b | 2 | #include "camera_api.h" |
TonyLin | 20:4ed21397e775 | 3 | |
backman | 1:82bc25a7b68b | 4 | #define clk 2 //ms |
TonyLin | 20:4ed21397e775 | 5 | |
TonyLin | 20:4ed21397e775 | 6 | BX_camera::BX_camera(int p) |
backman | 6:5a39bde2e016 | 7 | { |
TonyLin | 20:4ed21397e775 | 8 | |
backman | 6:5a39bde2e016 | 9 | line_CamR = new FastAnalogIn(PTD5); |
backman | 6:5a39bde2e016 | 10 | line_CamL= new FastAnalogIn(PTD6,0); |
backman | 6:5a39bde2e016 | 11 | cam_clk=new DigitalOut(PTE1); |
backman | 6:5a39bde2e016 | 12 | si=new DigitalOut(PTD7); |
TonyLin | 20:4ed21397e775 | 13 | padding = p; |
backman | 6:5a39bde2e016 | 14 | } |
physicsgood | 22:1464a3f0a290 | 15 | /*int BX_camera::black_center(void) |
physicsgood | 21:5f7efc1ca8ad | 16 | { |
physicsgood | 21:5f7efc1ca8ad | 17 | int black_L_right = 96 , black_R_left = 32; |
physicsgood | 21:5f7efc1ca8ad | 18 | |
physicsgood | 21:5f7efc1ca8ad | 19 | for(int i = 10; i <118; i++){ |
physicsgood | 21:5f7efc1ca8ad | 20 | if(sign_line_imageR[i] == 'O' && sign_line_imageR[i+1] == ' ' && sign_line_imageR[i+2] == ' '){ |
physicsgood | 21:5f7efc1ca8ad | 21 | black_R_left = i; |
physicsgood | 21:5f7efc1ca8ad | 22 | break; |
physicsgood | 21:5f7efc1ca8ad | 23 | } |
physicsgood | 21:5f7efc1ca8ad | 24 | } |
physicsgood | 21:5f7efc1ca8ad | 25 | |
physicsgood | 21:5f7efc1ca8ad | 26 | for(int i = 118; i >= 10; i--){ |
physicsgood | 21:5f7efc1ca8ad | 27 | if(sign_line_imageR[i] == 'O' && sign_line_imageR[i-1] == ' ' && sign_line_imageR[i-2] == ' '){ |
physicsgood | 21:5f7efc1ca8ad | 28 | black_L_right = i; |
physicsgood | 21:5f7efc1ca8ad | 29 | break; |
physicsgood | 21:5f7efc1ca8ad | 30 | } |
physicsgood | 21:5f7efc1ca8ad | 31 | } |
physicsgood | 21:5f7efc1ca8ad | 32 | |
physicsgood | 21:5f7efc1ca8ad | 33 | return (black_R_left + black_L_right) / 2; |
physicsgood | 22:1464a3f0a290 | 34 | }*/ |
physicsgood | 22:1464a3f0a290 | 35 | int BX_camera::black_centerR(void)//64~0 right eye |
physicsgood | 22:1464a3f0a290 | 36 | { |
physicsgood | 22:1464a3f0a290 | 37 | int black_R_left = 0; |
physicsgood | 23:d6d4e8adf7fe | 38 | for(int i = 120; i >=8; i--){ |
physicsgood | 22:1464a3f0a290 | 39 | if(sign_line_imageR[i] == 'O' && sign_line_imageR[i-1] == ' ' && sign_line_imageR[i-2] == ' '){ |
physicsgood | 22:1464a3f0a290 | 40 | return i; |
physicsgood | 22:1464a3f0a290 | 41 | } |
physicsgood | 22:1464a3f0a290 | 42 | } |
physicsgood | 22:1464a3f0a290 | 43 | return black_R_left; |
physicsgood | 21:5f7efc1ca8ad | 44 | } |
physicsgood | 22:1464a3f0a290 | 45 | int BX_camera::black_centerL(void) |
backman | 6:5a39bde2e016 | 46 | { |
physicsgood | 22:1464a3f0a290 | 47 | int black_L_right = 128; |
physicsgood | 23:d6d4e8adf7fe | 48 | for(int i = 8; i <121 ; i++){ |
physicsgood | 23:d6d4e8adf7fe | 49 | if(sign_line_imageL[i] == 'O' && sign_line_imageL[i+1] == ' ' && sign_line_imageL[i+2] == ' '){ |
physicsgood | 22:1464a3f0a290 | 50 | return i; |
physicsgood | 22:1464a3f0a290 | 51 | } |
backman | 6:5a39bde2e016 | 52 | } |
physicsgood | 22:1464a3f0a290 | 53 | return black_L_right; |
physicsgood | 22:1464a3f0a290 | 54 | } |
physicsgood | 22:1464a3f0a290 | 55 | //turn right 122~64(120) 0 |
physicsgood | 22:1464a3f0a290 | 56 | //turn left 128 64~6(8) |
physicsgood | 22:1464a3f0a290 | 57 | //straight 122~64 64~6 186~70 |
backman | 6:5a39bde2e016 | 58 | void BX_camera::read(void) |
backman | 6:5a39bde2e016 | 59 | { |
TonyLin | 20:4ed21397e775 | 60 | |
backman | 6:5a39bde2e016 | 61 | w_f_vL=0x0000; |
backman | 6:5a39bde2e016 | 62 | b_f_vL=0xffff; |
TonyLin | 20:4ed21397e775 | 63 | |
backman | 6:5a39bde2e016 | 64 | w_f_vR=0x0000; |
backman | 6:5a39bde2e016 | 65 | b_f_vR=0xffff; |
TonyLin | 20:4ed21397e775 | 66 | |
TonyLin | 20:4ed21397e775 | 67 | |
TonyLin | 20:4ed21397e775 | 68 | |
TonyLin | 20:4ed21397e775 | 69 | |
backman | 6:5a39bde2e016 | 70 | *si=1; |
backman | 6:5a39bde2e016 | 71 | *cam_clk=1; |
TonyLin | 20:4ed21397e775 | 72 | |
backman | 6:5a39bde2e016 | 73 | wait_us(30); // tune here |
backman | 6:5a39bde2e016 | 74 | *si=0; |
backman | 6:5a39bde2e016 | 75 | *cam_clk=0; |
TonyLin | 20:4ed21397e775 | 76 | |
TonyLin | 20:4ed21397e775 | 77 | |
TonyLin | 20:4ed21397e775 | 78 | |
backman | 6:5a39bde2e016 | 79 | line_CamR->enable(); |
backman | 6:5a39bde2e016 | 80 | line_CamL->enable(); |
TonyLin | 20:4ed21397e775 | 81 | |
TonyLin | 20:4ed21397e775 | 82 | |
backman | 6:5a39bde2e016 | 83 | //input 128 //both |
TonyLin | 20:4ed21397e775 | 84 | |
backman | 6:5a39bde2e016 | 85 | for(int i=0; i<128; i++) { |
backman | 6:5a39bde2e016 | 86 | *cam_clk=1; |
backman | 6:5a39bde2e016 | 87 | wait_us(5); |
TonyLin | 20:4ed21397e775 | 88 | |
TonyLin | 20:4ed21397e775 | 89 | |
backman | 6:5a39bde2e016 | 90 | line_imageR[i]=line_CamR->read_u16(); |
backman | 6:5a39bde2e016 | 91 | line_imageL[i]=line_CamL->read_u16(); |
TonyLin | 20:4ed21397e775 | 92 | |
backman | 6:5a39bde2e016 | 93 | // big small |
backman | 6:5a39bde2e016 | 94 | if(line_imageR[i] > w_f_vR) |
backman | 6:5a39bde2e016 | 95 | w_f_vR=line_imageR[i]; |
backman | 6:5a39bde2e016 | 96 | else if(line_imageR[i] < b_f_vR ) |
backman | 6:5a39bde2e016 | 97 | b_f_vR = line_imageR[i]; |
TonyLin | 20:4ed21397e775 | 98 | |
TonyLin | 20:4ed21397e775 | 99 | |
backman | 6:5a39bde2e016 | 100 | if(line_imageL[i] > w_f_vL) |
backman | 6:5a39bde2e016 | 101 | w_f_vL=line_imageL[i]; |
backman | 6:5a39bde2e016 | 102 | else if(line_imageL[i] < b_f_vL ) |
backman | 6:5a39bde2e016 | 103 | b_f_vL = line_imageL[i]; |
TonyLin | 20:4ed21397e775 | 104 | |
TonyLin | 20:4ed21397e775 | 105 | |
TonyLin | 20:4ed21397e775 | 106 | |
TonyLin | 20:4ed21397e775 | 107 | |
backman | 6:5a39bde2e016 | 108 | *cam_clk=0; |
backman | 6:5a39bde2e016 | 109 | wait_us(5); |
TonyLin | 20:4ed21397e775 | 110 | |
TonyLin | 20:4ed21397e775 | 111 | |
backman | 6:5a39bde2e016 | 112 | } |
TonyLin | 20:4ed21397e775 | 113 | |
TonyLin | 20:4ed21397e775 | 114 | |
backman | 6:5a39bde2e016 | 115 | line_CamR->enable(); |
backman | 6:5a39bde2e016 | 116 | line_CamL->enable(); |
TonyLin | 20:4ed21397e775 | 117 | |
TonyLin | 20:4ed21397e775 | 118 | |
backman | 6:5a39bde2e016 | 119 | //filter L R //may change |
TonyLin | 20:4ed21397e775 | 120 | |
backman | 6:5a39bde2e016 | 121 | for(int i=0; i<128; i++) { |
TonyLin | 20:4ed21397e775 | 122 | |
TonyLin | 20:4ed21397e775 | 123 | |
backman | 6:5a39bde2e016 | 124 | if( (line_imageR[i]-b_f_vR) < (w_f_vR - line_imageR[i] ) ) |
backman | 6:5a39bde2e016 | 125 | sign_line_imageR[i]=' '; |
backman | 6:5a39bde2e016 | 126 | else |
backman | 6:5a39bde2e016 | 127 | sign_line_imageR[i]='O'; |
TonyLin | 20:4ed21397e775 | 128 | |
TonyLin | 20:4ed21397e775 | 129 | |
backman | 6:5a39bde2e016 | 130 | if( (line_imageL[i]-b_f_vL) < (w_f_vL - line_imageL[i] ) ) |
backman | 6:5a39bde2e016 | 131 | sign_line_imageL[i]=' '; |
backman | 6:5a39bde2e016 | 132 | else |
backman | 6:5a39bde2e016 | 133 | sign_line_imageL[i]='O'; |
TonyLin | 20:4ed21397e775 | 134 | |
TonyLin | 20:4ed21397e775 | 135 | |
TonyLin | 20:4ed21397e775 | 136 | |
TonyLin | 20:4ed21397e775 | 137 | |
TonyLin | 20:4ed21397e775 | 138 | |
backman | 6:5a39bde2e016 | 139 | if(i==0) { |
backman | 6:5a39bde2e016 | 140 | sign_line_imageR[i]='X'; |
backman | 6:5a39bde2e016 | 141 | sign_line_imageL[i]='X'; |
backman | 6:5a39bde2e016 | 142 | } |
TonyLin | 20:4ed21397e775 | 143 | |
TonyLin | 20:4ed21397e775 | 144 | |
backman | 6:5a39bde2e016 | 145 | } |
TonyLin | 20:4ed21397e775 | 146 | |
TonyLin | 20:4ed21397e775 | 147 | |
TonyLin | 20:4ed21397e775 | 148 | |
backman | 6:5a39bde2e016 | 149 | } |