Clark Lin
/
Boboobooo
QQQQQQQQQ
Fork of Boboobooo by
Revision 2:c51647d3c14d, committed 2014-06-04
- Comitter:
- backman
- Date:
- Wed Jun 04 12:56:52 2014 +0000
- Parent:
- 1:82bc25a7b68b
- Child:
- 3:c5f2281b3ed2
- Commit message:
- two cam
Changed in this revision
--- a/camera_api.cpp Tue Jun 03 15:53:55 2014 +0000 +++ b/camera_api.cpp Wed Jun 04 12:56:52 2014 +0000 @@ -4,33 +4,32 @@ #define clk 2 //ms - BX_camera::BX_camera(char cam){ - + BX_camera::BX_camera(void){ - cam_clk= new DigitalOut(PTE1) ; - - si = new DigitalOut(PTD7); - - line_Cam = new FastAnalogIn(PTD5); + line_CamR = new FastAnalogIn(PTD5); + line_CamL= new FastAnalogIn(PTD6,0); + cam_clk=new DigitalOut(PTE1); + si=new DigitalOut(PTD7); - - - + } -void BX_camera::read(void){ - + void BX_camera::read(void){ - w_f_v=0x0000; - b_f_v=0xffff; + w_f_vL=0x0000; + b_f_vL=0xffff; + + w_f_vR=0x0000; + b_f_vR=0xffff; + *si=1; - *cam_clk=1; + *cam_clk=1; wait_us(30); // tune here *si=0; @@ -38,24 +37,31 @@ - line_Cam->enable(); + line_CamR->enable(); + line_CamL->enable(); - //input 128 + //input 128 //both for(int i=0;i<128;i++){ - *cam_clk=1; - wait_us(5); + *cam_clk=1; + wait_us(5); - line_image[i]=line_Cam->read_u16(); - + line_imageR[i]=line_CamR->read_u16(); + line_imageL[i]=line_CamL->read_u16(); // big small - if(line_image[i] > w_f_v) - w_f_v=line_image[i]; - else if(line_image[i] < b_f_v ) - b_f_v = line_image[i]; + if(line_imageR[i] > w_f_vR) + w_f_vR=line_imageR[i]; + else if(line_imageR[i] < b_f_vR ) + b_f_vR = line_imageR[i]; + + + if(line_imageL[i] > w_f_vL) + w_f_vL=line_imageL[i]; + else if(line_imageL[i] < b_f_vL ) + b_f_vL = line_imageL[i]; @@ -67,22 +73,35 @@ } - line_Cam->disable(); + line_CamR->enable(); + line_CamL->enable(); - - //filter + //filter L R //may change for(int i=0;i<128;i++){ - if( (line_image[i]-b_f_v) < (w_f_v - line_image[i] ) ) - sign_line_image[i]=' '; + if( (line_imageR[i]-b_f_vR) < (w_f_vR - line_imageR[i] ) ) + sign_line_imageR[i]=' '; + else + sign_line_imageR[i]='O'; + + + if( (line_imageL[i]-b_f_vL) < (w_f_vL - line_imageL[i] ) ) + sign_line_imageL[i]=' '; else - sign_line_image[i]='O'; + sign_line_imageL[i]='O'; + - if(i==0) - sign_line_image[i]='X'; + + + + if(i==0){ + sign_line_imageR[i]='X'; + sign_line_imageL[i]='X'; + } + }
--- a/camera_api.h Tue Jun 03 15:53:55 2014 +0000 +++ b/camera_api.h Wed Jun 04 12:56:52 2014 +0000 @@ -1,51 +1,46 @@ #include "bx-adc.h" +#include "mbed.h" +//cause same si and clk camR ,camL are synchronous + class BX_camera{ + public: + + //static + void read(void); //block in here + + unsigned int line_imageR[128]; + unsigned int line_imageL[128]; + + + BX_camera(); + + + + + char sign_line_imageL[128]; + char sign_line_imageR[128]; + + + + private: + + FastAnalogIn* line_CamR; + FastAnalogIn* line_CamL; + DigitalOut* cam_clk; + DigitalOut* si; + + int w_f_vL; + int b_f_vL; + + int w_f_vR; + int b_f_vR; + - public: - - BX_camera(char cam); - - void read(void); //block in here - - - unsigned int line_image[128]; - - char sign_line_image[128]; - - private: - - - DigitalOut *cam_clk; - DigitalOut *si; - - FastAnalogIn *line_Cam; - - int w_f_v; - - int b_f_v; - - - - - - - - - - - - - - - - - -
--- a/main.cpp Tue Jun 03 15:53:55 2014 +0000 +++ b/main.cpp Wed Jun 04 12:56:52 2014 +0000 @@ -7,8 +7,7 @@ Serial pc(USBTX, USBRX); BX_servo servo; - BX_camera cam('n'); - PwmOut cam_clk(PTC3); + BX_camera cam; int main() { @@ -40,24 +39,33 @@ bool f4; while(1){ - + // cam.read(); for(int i=0;i<128;i++){ if(i==64) pc.printf("X"); else - pc.printf("%c", cam.sign_line_image[i]); + pc.printf("%c", cam.sign_line_imageL[i]); + } + pc.printf(" || "); + + for(int i=0;i<128;i++){ + if(i==64) + pc.printf("X"); + else + pc.printf("%c", cam.sign_line_imageR[i]); } pc.printf("\r\n"); + // find center // case 1 // | // //case 2 / | / - + /* if(cam.sign_line_image[64]==' ') find_type=0x02; else @@ -172,11 +180,13 @@ break; } - pc.printf("center :%d\r\n",center); + pc.printf("ang :%d\r\n ",( (64.0-center) /64.0 )*90); //-------------------------------------------- - - - + + + servo.set_angle(( (64.0-center) /64.0 )*90 ); + + */ } @@ -222,9 +232,9 @@ // angle+=cam.line_image[i]-cam.line_image[127-i]; - if(cam.line_image[i]==0) + if(cam.line_imageR[i]==0) black_pR++; - if(cam.line_image[127-i]==0) + if(cam.line_imageR[127-i]==0) black_pL++; }