good

Dependencies:   mbed

Fork of BX-car by Clark Lin

Committer:
backman
Date:
Sun Jun 22 13:58:01 2014 +0000
Revision:
7:fd976e1ced33
Parent:
6:5a39bde2e016
Child:
8:8e49e21d80a2
printf should use right type

Who changed what in which revision?

UserRevisionLine numberNew contents of line
backman 1:82bc25a7b68b 1 #include "mbed.h"
backman 1:82bc25a7b68b 2 #include "camera_api.h"
backman 1:82bc25a7b68b 3
backman 1:82bc25a7b68b 4 #define clk 2 //ms
backman 6:5a39bde2e016 5
backman 6:5a39bde2e016 6 BX_camera::BX_camera(void)
backman 6:5a39bde2e016 7 {
backman 6:5a39bde2e016 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);
backman 6:5a39bde2e016 13
backman 6:5a39bde2e016 14 }
backman 6:5a39bde2e016 15
backman 6:5a39bde2e016 16 int BX_camera::black_centerR(void)
backman 6:5a39bde2e016 17 {
backman 6:5a39bde2e016 18
backman 7:fd976e1ced33 19 int l_care=10;
backman 7:fd976e1ced33 20 int r_care=118;
backman 7:fd976e1ced33 21
backman 7:fd976e1ced33 22
backman 6:5a39bde2e016 23 // find center
backman 6:5a39bde2e016 24 // case 1 // | //
backman 6:5a39bde2e016 25 // case 2 / | /
backman 6:5a39bde2e016 26
backman 6:5a39bde2e016 27 char find_type=0x00;
backman 6:5a39bde2e016 28
backman 6:5a39bde2e016 29 int b_end=0;
backman 6:5a39bde2e016 30 int b_start=0;
backman 6:5a39bde2e016 31
backman 6:5a39bde2e016 32 int b_w=0;
backman 7:fd976e1ced33 33 int b_center=0;
backman 6:5a39bde2e016 34
backman 6:5a39bde2e016 35 int b2_end=0;
backman 6:5a39bde2e016 36 int b2_start=0;
backman 7:fd976e1ced33 37 int b2_center=0;
backman 6:5a39bde2e016 38
backman 6:5a39bde2e016 39 int b2_w=0;
backman 6:5a39bde2e016 40
backman 7:fd976e1ced33 41 int center=30;
backman 6:5a39bde2e016 42 int j=64;
backman 6:5a39bde2e016 43 bool f1=false;
backman 6:5a39bde2e016 44 bool f2=false;
backman 6:5a39bde2e016 45 bool f3=false;
backman 6:5a39bde2e016 46 bool f4=false;
backman 6:5a39bde2e016 47 int w_thr_up=32;
backman 6:5a39bde2e016 48 int w_thr_dn=0;
backman 6:5a39bde2e016 49
backman 6:5a39bde2e016 50 if(sign_line_imageR[64]==' ')
backman 6:5a39bde2e016 51 find_type=0x02;
backman 6:5a39bde2e016 52 else
backman 6:5a39bde2e016 53 find_type=0x01;
backman 6:5a39bde2e016 54
backman 6:5a39bde2e016 55
backman 7:fd976e1ced33 56 for(int i=64; i<r_care; i++,j--) {
backman 6:5a39bde2e016 57
backman 6:5a39bde2e016 58
backman 6:5a39bde2e016 59 switch(find_type) {
backman 6:5a39bde2e016 60
backman 6:5a39bde2e016 61
backman 6:5a39bde2e016 62 case 0x01:
backman 4:05b21dbca0c7 63
backman 6:5a39bde2e016 64 if(f1==false&&sign_line_imageR[i]==' ') {
backman 6:5a39bde2e016 65 if(f1==false) {
backman 6:5a39bde2e016 66 b_start=i;
backman 6:5a39bde2e016 67 f1=true;
backman 6:5a39bde2e016 68 }
backman 6:5a39bde2e016 69
backman 6:5a39bde2e016 70 }
backman 6:5a39bde2e016 71 if(f1== true&& f2==false&&sign_line_imageR[i]=='O') {
backman 6:5a39bde2e016 72 if(f2==false) {
backman 6:5a39bde2e016 73 b_end=i-1;
backman 6:5a39bde2e016 74 f2=true;
backman 6:5a39bde2e016 75 }
backman 6:5a39bde2e016 76
backman 6:5a39bde2e016 77 }
backman 6:5a39bde2e016 78
backman 6:5a39bde2e016 79 if(f3==false&&sign_line_imageR[j]==' ') {
backman 6:5a39bde2e016 80 if(f3==false) {
backman 6:5a39bde2e016 81 b2_end=j;
backman 6:5a39bde2e016 82 f3=true;
backman 6:5a39bde2e016 83 }
backman 6:5a39bde2e016 84
backman 6:5a39bde2e016 85 }
backman 6:5a39bde2e016 86 if(f3==true&&f4==false&&sign_line_imageR[j]=='O') {
backman 6:5a39bde2e016 87 if(f4==false) {
backman 6:5a39bde2e016 88 b2_start=j-1;
backman 6:5a39bde2e016 89 f4=true;
backman 6:5a39bde2e016 90 }
backman 6:5a39bde2e016 91
backman 6:5a39bde2e016 92 }
backman 6:5a39bde2e016 93
backman 6:5a39bde2e016 94
backman 6:5a39bde2e016 95 break;
backman 6:5a39bde2e016 96
backman 6:5a39bde2e016 97
backman 6:5a39bde2e016 98 case 0x02:
backman 6:5a39bde2e016 99
backman 6:5a39bde2e016 100 if(sign_line_imageR[i]=='O') {
backman 6:5a39bde2e016 101
backman 6:5a39bde2e016 102 if(f1==false) {
backman 6:5a39bde2e016 103 b_end=i;
backman 6:5a39bde2e016 104 f1=true;
backman 6:5a39bde2e016 105 }
backman 6:5a39bde2e016 106 }
backman 6:5a39bde2e016 107
backman 6:5a39bde2e016 108 if(sign_line_imageR[j]=='O') {
backman 6:5a39bde2e016 109
backman 6:5a39bde2e016 110 if(f2==false) {
backman 6:5a39bde2e016 111 b_start=j;
backman 6:5a39bde2e016 112 f2=true;
backman 6:5a39bde2e016 113 }
backman 6:5a39bde2e016 114
backman 6:5a39bde2e016 115 }
backman 6:5a39bde2e016 116
backman 6:5a39bde2e016 117
backman 6:5a39bde2e016 118 break;
backman 6:5a39bde2e016 119
backman 6:5a39bde2e016 120 }
backman 6:5a39bde2e016 121
backman 6:5a39bde2e016 122
backman 6:5a39bde2e016 123 }
backman 6:5a39bde2e016 124
backman 6:5a39bde2e016 125 b_w=b_start-b_end;
backman 6:5a39bde2e016 126 b2_w=b2_start-b2_end;
backman 3:c5f2281b3ed2 127
backman 7:fd976e1ced33 128 de_v=b_start;
backman 7:fd976e1ced33 129 de_v2=b_end;
backman 6:5a39bde2e016 130
backman 6:5a39bde2e016 131 switch(find_type) {
backman 6:5a39bde2e016 132
backman 6:5a39bde2e016 133 case 0x01:
backman 7:fd976e1ced33 134 b_center=(b_end+b_start)/2;
backman 7:fd976e1ced33 135 b2_center=(b2_end+b2_start)/2;
backman 7:fd976e1ced33 136
backman 7:fd976e1ced33 137
backman 7:fd976e1ced33 138 if(w_thr_up>b_w&&(b_center-64)<(64-b2_center))
backman 7:fd976e1ced33 139 center=b_center;
backman 7:fd976e1ced33 140 else
backman 7:fd976e1ced33 141 center=b2_center;
backman 6:5a39bde2e016 142
backman 6:5a39bde2e016 143
backman 6:5a39bde2e016 144
backman 6:5a39bde2e016 145
backman 6:5a39bde2e016 146
backman 7:fd976e1ced33 147 /* if( ( w_thr_up- (b_w))>0 &&( ( w_thr_up- (b_w)) < (w_thr_up-(b2_w)) ) ) {
backman 6:5a39bde2e016 148 center=(b_end+b_start)/2;
backman 6:5a39bde2e016 149
backman 6:5a39bde2e016 150
backman 6:5a39bde2e016 151
backman 7:fd976e1ced33 152 // } else if( ( w_thr_up- (b2_w) )>0 ) {
backman 6:5a39bde2e016 153 center=(b2_end+b2_start)/2;
backman 7:fd976e1ced33 154 // } else {
backman 6:5a39bde2e016 155
backman 6:5a39bde2e016 156 center=65;
backman 6:5a39bde2e016 157
backman 6:5a39bde2e016 158 //????????????????
backman 6:5a39bde2e016 159
backman 6:5a39bde2e016 160 }
backman 6:5a39bde2e016 161
backman 7:fd976e1ced33 162 */
backman 6:5a39bde2e016 163 break;
backman 6:5a39bde2e016 164
backman 6:5a39bde2e016 165 case 0x02:
backman 6:5a39bde2e016 166 center=(b_end+b_start)/2;
backman 6:5a39bde2e016 167
backman 6:5a39bde2e016 168
backman 6:5a39bde2e016 169 break;
backman 3:c5f2281b3ed2 170 }
backman 3:c5f2281b3ed2 171
backman 7:fd976e1ced33 172 de_v=center;
backman 6:5a39bde2e016 173 return center;
backman 7:fd976e1ced33 174
backman 6:5a39bde2e016 175 }
backman 6:5a39bde2e016 176
backman 6:5a39bde2e016 177
backman 3:c5f2281b3ed2 178
backman 3:c5f2281b3ed2 179
backman 6:5a39bde2e016 180 int BX_camera::black_centerL(void)
backman 6:5a39bde2e016 181 {
backman 6:5a39bde2e016 182
backman 6:5a39bde2e016 183 // find center
backman 6:5a39bde2e016 184 // case 1 // | //
backman 6:5a39bde2e016 185 //case 2 / | /
backman 6:5a39bde2e016 186
backman 6:5a39bde2e016 187
backman 6:5a39bde2e016 188 char find_type=0x00;
backman 6:5a39bde2e016 189
backman 6:5a39bde2e016 190 int b_end=0;
backman 6:5a39bde2e016 191 int b_start=0;
backman 6:5a39bde2e016 192 int b2_end=0;
backman 6:5a39bde2e016 193 int b2_start=0;
backman 6:5a39bde2e016 194
backman 6:5a39bde2e016 195
backman 6:5a39bde2e016 196 int center;
backman 6:5a39bde2e016 197 int j=64;
backman 6:5a39bde2e016 198 bool f1=false;
backman 6:5a39bde2e016 199 bool f2=false;
backman 6:5a39bde2e016 200 bool f3=false;
backman 6:5a39bde2e016 201 bool f4=false;
backman 6:5a39bde2e016 202
backman 6:5a39bde2e016 203 if(sign_line_imageL[64]==' ')
backman 6:5a39bde2e016 204 find_type=0x02;
backman 6:5a39bde2e016 205 else
backman 6:5a39bde2e016 206 find_type=0x01;
backman 6:5a39bde2e016 207
backman 6:5a39bde2e016 208
backman 6:5a39bde2e016 209 for(int i=64; i<128; i++,j--) {
backman 6:5a39bde2e016 210
backman 6:5a39bde2e016 211
backman 6:5a39bde2e016 212 switch(find_type) {
backman 6:5a39bde2e016 213
backman 6:5a39bde2e016 214
backman 6:5a39bde2e016 215 case 0x01:
backman 6:5a39bde2e016 216
backman 6:5a39bde2e016 217 if(f1==false&&sign_line_imageL[i]==' ') {
backman 6:5a39bde2e016 218 if(f1==false) {
backman 6:5a39bde2e016 219 b_start=i;
backman 6:5a39bde2e016 220 f1=true;
backman 6:5a39bde2e016 221 }
backman 6:5a39bde2e016 222
backman 6:5a39bde2e016 223 }
backman 6:5a39bde2e016 224 if(f1== true&& f2==false&&sign_line_imageL[i]=='O') {
backman 6:5a39bde2e016 225 if(f2==false) {
backman 6:5a39bde2e016 226 b_end=i-1;
backman 6:5a39bde2e016 227 f2=true;
backman 6:5a39bde2e016 228 }
backman 6:5a39bde2e016 229
backman 6:5a39bde2e016 230 }
backman 4:05b21dbca0c7 231
backman 6:5a39bde2e016 232 if(f3==false&&sign_line_imageL[j]==' ') {
backman 6:5a39bde2e016 233 if(f3==false) {
backman 6:5a39bde2e016 234 b2_end=j;
backman 6:5a39bde2e016 235 f3=true;
backman 6:5a39bde2e016 236 }
backman 6:5a39bde2e016 237
backman 6:5a39bde2e016 238 }
backman 6:5a39bde2e016 239 if(f3==true&&f4==false&&sign_line_imageL[j]=='O') {
backman 6:5a39bde2e016 240 if(f4==false) {
backman 6:5a39bde2e016 241 b2_start=j-1;
backman 6:5a39bde2e016 242 f4=true;
backman 6:5a39bde2e016 243 }
backman 6:5a39bde2e016 244
backman 6:5a39bde2e016 245 }
backman 6:5a39bde2e016 246
backman 6:5a39bde2e016 247 break;
backman 6:5a39bde2e016 248
backman 6:5a39bde2e016 249
backman 6:5a39bde2e016 250 case 0x02:
backman 6:5a39bde2e016 251
backman 6:5a39bde2e016 252 if(sign_line_imageL[i]=='O') {
backman 6:5a39bde2e016 253
backman 6:5a39bde2e016 254 if(f1==false) {
backman 6:5a39bde2e016 255 b_end=i;
backman 6:5a39bde2e016 256 f1=true;
backman 6:5a39bde2e016 257 }
backman 6:5a39bde2e016 258 }
backman 6:5a39bde2e016 259
backman 6:5a39bde2e016 260 if(sign_line_imageL[j]=='O') {
backman 6:5a39bde2e016 261
backman 6:5a39bde2e016 262 if(f2==false) {
backman 6:5a39bde2e016 263 b_start=j;
backman 6:5a39bde2e016 264 f2=true;
backman 6:5a39bde2e016 265 }
backman 6:5a39bde2e016 266
backman 6:5a39bde2e016 267 }
backman 6:5a39bde2e016 268
backman 6:5a39bde2e016 269
backman 6:5a39bde2e016 270 break;
backman 6:5a39bde2e016 271
backman 6:5a39bde2e016 272 }
backman 6:5a39bde2e016 273
backman 6:5a39bde2e016 274 }
backman 6:5a39bde2e016 275
backman 6:5a39bde2e016 276
backman 6:5a39bde2e016 277 switch(find_type) {
backman 6:5a39bde2e016 278
backman 6:5a39bde2e016 279 case 0x01:
backman 6:5a39bde2e016 280
backman 6:5a39bde2e016 281 if((b_end-b_start)>(b2_end-b2_start) )
backman 6:5a39bde2e016 282 center=(b_end+b_start)/2;
backman 6:5a39bde2e016 283
backman 3:c5f2281b3ed2 284 else
backman 6:5a39bde2e016 285 center=(b2_end+b2_start)/2;
backman 6:5a39bde2e016 286 break;
backman 6:5a39bde2e016 287
backman 6:5a39bde2e016 288 case 0x02:
backman 6:5a39bde2e016 289 center=(b_end+b_start)/2;
backman 6:5a39bde2e016 290
backman 6:5a39bde2e016 291 break;
backman 6:5a39bde2e016 292 }
backman 6:5a39bde2e016 293
backman 3:c5f2281b3ed2 294 return center;
backman 6:5a39bde2e016 295
backman 6:5a39bde2e016 296 }
backman 6:5a39bde2e016 297
backman 6:5a39bde2e016 298
backman 6:5a39bde2e016 299
backman 6:5a39bde2e016 300 void BX_camera::read(void)
backman 6:5a39bde2e016 301 {
backman 6:5a39bde2e016 302
backman 6:5a39bde2e016 303 w_f_vL=0x0000;
backman 6:5a39bde2e016 304 b_f_vL=0xffff;
backman 6:5a39bde2e016 305
backman 6:5a39bde2e016 306 w_f_vR=0x0000;
backman 6:5a39bde2e016 307 b_f_vR=0xffff;
backman 6:5a39bde2e016 308
backman 6:5a39bde2e016 309
backman 6:5a39bde2e016 310
backman 6:5a39bde2e016 311
backman 6:5a39bde2e016 312 *si=1;
backman 6:5a39bde2e016 313 *cam_clk=1;
backman 6:5a39bde2e016 314
backman 6:5a39bde2e016 315 wait_us(30); // tune here
backman 6:5a39bde2e016 316 *si=0;
backman 6:5a39bde2e016 317 *cam_clk=0;
backman 6:5a39bde2e016 318
backman 6:5a39bde2e016 319
backman 6:5a39bde2e016 320
backman 6:5a39bde2e016 321 line_CamR->enable();
backman 6:5a39bde2e016 322 line_CamL->enable();
backman 6:5a39bde2e016 323
backman 6:5a39bde2e016 324
backman 6:5a39bde2e016 325 //input 128 //both
backman 6:5a39bde2e016 326
backman 6:5a39bde2e016 327 for(int i=0; i<128; i++) {
backman 6:5a39bde2e016 328 *cam_clk=1;
backman 6:5a39bde2e016 329 wait_us(5);
backman 6:5a39bde2e016 330
backman 6:5a39bde2e016 331
backman 6:5a39bde2e016 332 line_imageR[i]=line_CamR->read_u16();
backman 6:5a39bde2e016 333 line_imageL[i]=line_CamL->read_u16();
backman 4:05b21dbca0c7 334
backman 6:5a39bde2e016 335 // big small
backman 6:5a39bde2e016 336 if(line_imageR[i] > w_f_vR)
backman 6:5a39bde2e016 337 w_f_vR=line_imageR[i];
backman 6:5a39bde2e016 338 else if(line_imageR[i] < b_f_vR )
backman 6:5a39bde2e016 339 b_f_vR = line_imageR[i];
backman 6:5a39bde2e016 340
backman 6:5a39bde2e016 341
backman 6:5a39bde2e016 342 if(line_imageL[i] > w_f_vL)
backman 6:5a39bde2e016 343 w_f_vL=line_imageL[i];
backman 6:5a39bde2e016 344 else if(line_imageL[i] < b_f_vL )
backman 6:5a39bde2e016 345 b_f_vL = line_imageL[i];
backman 6:5a39bde2e016 346
backman 6:5a39bde2e016 347
backman 6:5a39bde2e016 348
backman 6:5a39bde2e016 349
backman 6:5a39bde2e016 350 *cam_clk=0;
backman 6:5a39bde2e016 351 wait_us(5);
backman 6:5a39bde2e016 352
backman 6:5a39bde2e016 353
backman 6:5a39bde2e016 354 }
backman 6:5a39bde2e016 355
backman 6:5a39bde2e016 356
backman 6:5a39bde2e016 357 line_CamR->enable();
backman 6:5a39bde2e016 358 line_CamL->enable();
backman 6:5a39bde2e016 359
backman 6:5a39bde2e016 360
backman 6:5a39bde2e016 361 //filter L R //may change
backman 6:5a39bde2e016 362
backman 6:5a39bde2e016 363 for(int i=0; i<128; i++) {
backman 6:5a39bde2e016 364
backman 6:5a39bde2e016 365
backman 6:5a39bde2e016 366 if( (line_imageR[i]-b_f_vR) < (w_f_vR - line_imageR[i] ) )
backman 6:5a39bde2e016 367 sign_line_imageR[i]=' ';
backman 6:5a39bde2e016 368 else
backman 6:5a39bde2e016 369 sign_line_imageR[i]='O';
backman 6:5a39bde2e016 370
backman 6:5a39bde2e016 371
backman 6:5a39bde2e016 372 if( (line_imageL[i]-b_f_vL) < (w_f_vL - line_imageL[i] ) )
backman 6:5a39bde2e016 373 sign_line_imageL[i]=' ';
backman 6:5a39bde2e016 374 else
backman 6:5a39bde2e016 375 sign_line_imageL[i]='O';
backman 6:5a39bde2e016 376
backman 6:5a39bde2e016 377
backman 6:5a39bde2e016 378
backman 6:5a39bde2e016 379
backman 6:5a39bde2e016 380
backman 6:5a39bde2e016 381 if(i==0) {
backman 6:5a39bde2e016 382 sign_line_imageR[i]='X';
backman 6:5a39bde2e016 383 sign_line_imageL[i]='X';
backman 6:5a39bde2e016 384 }
backman 6:5a39bde2e016 385
backman 6:5a39bde2e016 386
backman 6:5a39bde2e016 387 }
backman 6:5a39bde2e016 388
backman 6:5a39bde2e016 389
backman 6:5a39bde2e016 390
backman 6:5a39bde2e016 391 }