QQQQQQQQQ

Dependencies:   mbed

Fork of Boboobooo by kao yi

Files at this revision

API Documentation at this revision

Comitter:
physicsgood
Date:
Mon Jul 07 08:16:46 2014 +0000
Parent:
5:e32b091aa1fb
Commit message:
QQQQQQQ

Changed in this revision

camera_api.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
servo_api.cpp Show annotated file Show diff for this revision Revisions of this file
servo_api.h Show annotated file Show diff for this revision Revisions of this file
diff -r e32b091aa1fb -r b046d6ff3745 camera_api.cpp
--- a/camera_api.cpp	Thu Jun 05 10:32:55 2014 +0000
+++ b/camera_api.cpp	Mon Jul 07 08:16:46 2014 +0000
@@ -14,242 +14,37 @@
  
 int BX_camera::black_centerR(void){
        
-         // find center 
-         // case 1      //  |  //
-         // case 2       /  |  /
-    
-     char find_type=0x00;
-     
-     int b_end=0;
-     int b_start=0;
-     
-     int b2_end=0;
-     int b2_start=0;
-     
-     
-     int center;
-     int j=64;
-     bool f1=false;
-     bool f2=false;
-     bool f3=false;
-     bool f4=false;
+    int black_R_left = 0;
+    for(int i = 120; i >=8; i--){
+        if(sign_line_imageR[i] == 'O' && sign_line_imageR[i-1] == ' ' && sign_line_imageR[i-2] == ' '){
+            return i;
+        }
+    } 
+    return black_R_left;
     
          
-            if(sign_line_imageR[64]==' ')
-              find_type=0x02;
-            else
-              find_type=0x01;  
-            
-          
-           for(int i=64;i<128; i++,j--){
-               
-                
-               switch(find_type){
-                   
-                   
-                   case 0x01:
-                       
-                         if(f1==false&&sign_line_imageR[i]==' '){ 
-                                  if(f1==false){
-                                      b_start=i;
-                                      f1=true;
-                                  }
-                                  
-                         }
-                         if(f1== true&& f2==false&&sign_line_imageR[i]=='O'){ 
-                                  if(f2==false){
-                                      b_end=i-1;
-                                      f2=true;
-                                  }
-                                  
-                         }
-                         
-                         if(f3==false&&sign_line_imageR[j]==' '){ 
-                                  if(f3==false){
-                                      b2_end=j;
-                                      f3=true;
-                                  }
-                                  
-                         }
-                         if(f3==true&&f4==false&&sign_line_imageR[j]=='O'){ 
-                                  if(f4==false){
-                                      b2_start=j-1;
-                                      f4=true;
-                                  }
-                                  
-                         }
-                         
-                   
-                   break;
-                   
-                   
-                   case 0x02:
-                   
-                         if(sign_line_imageR[i]=='O'){         
-                    
-                                  if(f1==false){
-                                      b_end=i;
-                                      f1=true;
-                                  }
-                         }  
-                    
-                         if(sign_line_imageR[j]=='O'){
-                        
-                                   if(f2==false){
-                                       b_start=j;     
-                                      f2=true;
-                                  }
-       
-                        }
-                   
-                   
-                   break;    
-      
-               }
-        
-               
-           }
-       
-            
-          switch(find_type){
-         
-             case 0x01:
-                
-               if((b_end-b_start)>(b2_end-b2_start)    )
-                     center=(b_end+b_start)/2;
-                     
-               else  
-                     center=(b2_end+b2_start)/2;
-             break;
-             
-             case 0x02:
-               center=(b_end+b_start)/2;
-              
-             break;
-         }
+
     
-    
-      return center;
-    
-    }
+}
 
 
 
 
 int BX_camera::black_centerL(void){
          
-         // find center 
-         // case 1      //  |  //
-         //case 2         / |  /
-         
-         
-     char find_type=0x00;
-     
-     int b_end=0;
-     int b_start=0;
-     int b2_end=0;
-     int b2_start=0;
+     int black_L_right = 128;
+     for(int i = 8; i <121 ; i++){
+        if(sign_line_imageL[i] == 'O' && sign_line_imageL[i+1] == ' ' && sign_line_imageL[i+2] == ' '){
+            return i;
+        }
+    }
+    return black_L_right;
      
      
-     int center;
-     int j=64;
-     bool f1=false;
-     bool f2=false;
-     bool f3=false;
-     bool f4=false;
-
-            if(sign_line_imageL[64]==' ')
-              find_type=0x02;
-            else
-              find_type=0x01;  
-            
-           
-           for(int i=64;i<128; i++,j--){
-               
-                
-               switch(find_type){
-                   
-                   
-                   case 0x01:
-                       
-                         if(f1==false&&sign_line_imageL[i]==' '){ 
-                                  if(f1==false){
-                                      b_start=i;
-                                      f1=true;
-                                  }
-                                  
-                         }
-                         if(f1== true&& f2==false&&sign_line_imageL[i]=='O'){ 
-                                  if(f2==false){
-                                      b_end=i-1;
-                                      f2=true;
-                                  }
-                                  
-                         }
-                         
-                         if(f3==false&&sign_line_imageL[j]==' '){ 
-                                  if(f3==false){
-                                      b2_end=j;
-                                      f3=true;
-                                  }
-                                  
-                         }
-                         if(f3==true&&f4==false&&sign_line_imageL[j]=='O'){ 
-                                  if(f4==false){
-                                      b2_start=j-1;
-                                      f4=true;
-                                  }
-                                  
-                         }
-                                    
-                   break;
-                   
-                   
-                   case 0x02:
-                   
-                         if(sign_line_imageL[i]=='O'){         
-                    
-                                  if(f1==false){
-                                      b_end=i;
-                                      f1=true;
-                                  }
-                         }  
-                    
-                         if(sign_line_imageL[j]=='O'){
-                        
-                                   if(f2==false){
-                                       b_start=j;     
-                                      f2=true;
-                                  }
-       
-                        }
-                   
-                   
-                   break;               
-                   
-               }
-         
-           }
-       
-            
-          switch(find_type){
-         
-             case 0x01:
-                
-               if((b_end-b_start)>(b2_end-b2_start)    )
-                     center=(b_end+b_start)/2;
-                     
-               else  
-                     center=(b2_end+b2_start)/2;             
-             break;
-             
-             case 0x02:
-               center=(b_end+b_start)/2;
-              
-             break;
-         }
- 
-    return center;
+    
+          
+                 
+     
  
  }
  
diff -r e32b091aa1fb -r b046d6ff3745 main.cpp
--- a/main.cpp	Thu Jun 05 10:32:55 2014 +0000
+++ b/main.cpp	Mon Jul 07 08:16:46 2014 +0000
@@ -2,14 +2,15 @@
 #include "servo_api.h"
 #include "camera_api.h"
 
-
+#include "motor_api.h"
 #define Debug_cam_uart
 
-
+//middle 0.041
 Serial pc(USBTX, USBRX);
 BX_servo servo; 
- 
-    BX_camera cam;
+BX_camera cam;
+BX_motor MotorA('A');
+BX_motor MotorB('B');
 
 
 
@@ -19,6 +20,7 @@
     int black_va;
     int white_va;
     */
+    double Kp = 0.0;
     
 #ifdef Debug_cam_uart
      pc.baud(115200);
@@ -26,9 +28,11 @@
      
   while(1){   
      
-      cam.read();
-         
-        for(int i=0;i<128;i++){
+        cam.read();
+        MotorA.rotate(0.0);
+        MotorB.rotate(0.0);
+        servo.set_angle(0.051);
+        /*for(int i=0;i<128;i++){
              if(i==64)
                pc.printf("X");
              else          
@@ -42,13 +46,7 @@
              else          
                pc.printf("%c", cam.sign_line_imageR[i]);
          }
-         pc.printf("\r\n");
-     
-
-
-        pc.printf("R center : %d  \r\nL center: %d\r\n",cam.black_centerR(),cam.black_centerL());
-
-
+         pc.printf("\r\n");*/
        }
 
      
diff -r e32b091aa1fb -r b046d6ff3745 servo_api.cpp
--- a/servo_api.cpp	Thu Jun 05 10:32:55 2014 +0000
+++ b/servo_api.cpp	Mon Jul 07 08:16:46 2014 +0000
@@ -1,50 +1,28 @@
 // 0~180 angle    1~2ms
 #include "mbed.h"
 #include "servo_api.h"
-
-
-#define right_end 0.05  //90
-
-#define left_end 0.1    //-90
+#define right_end 1.0  //90
+#define left_end 0.0  //-90
+//middle 0.057
 
 //memory opt
 // 5 degree seperate
-
-
-
-BX_servo::BX_servo(void){
-    
-    
-      angle = 0;
+BX_servo::BX_servo(void)
+{
+    angle = 0;
+    servo_in= new  PwmOut(PTB0);
+    servo_in->period_ms(20);
+}
 
-      servo_in= new  PwmOut(PTB0);
-      
-      servo_in->period_ms(20);
-          
-      for(int i=0;i<37;i++){
-          
-          angle_level[i]=i*(0.05/36)+right_end;
-          }
+float BX_servo::set_angle(float a)
+{
 
-      *servo_in =angle_level[18];
-      
-    
-    }
-
-
-
-
-
+    if( a<left_end )
+        a=left_end;
+    else if(a>right_end)
+        a=right_end;
+    angle=a;
+    *servo_in=angle;
 
-int BX_servo::set_angle(int a){
-    
-    
-      angle=a;
-       
-      *servo_in=angle_level[18+a/5];
-   
-         
-     
     return angle;
-    
-    }
\ No newline at end of file
+}
\ No newline at end of file
diff -r e32b091aa1fb -r b046d6ff3745 servo_api.h
--- a/servo_api.h	Thu Jun 05 10:32:55 2014 +0000
+++ b/servo_api.h	Mon Jul 07 08:16:46 2014 +0000
@@ -1,5 +1,3 @@
-
-
 
 #include "mbed.h"
 
@@ -9,7 +7,7 @@
     
     
     public:
-        int set_angle(int a);
+        float set_angle(float a);
     
         BX_servo(void);
     
@@ -22,10 +20,10 @@
     private:
     
         //-90~0~90
-        int angle ;
+        float angle ;
     
         PwmOut* servo_in;
          //0~36  // 18 mid  
-        float angle_level[37];
+      
     
     };
\ No newline at end of file