share

Dependencies:   mbed-rtos mbed

Fork of BX-car_2 by Tony Lin

Files at this revision

API Documentation at this revision

Comitter:
TonyLin
Date:
Sun Jun 29 14:02:37 2014 +0000
Parent:
18:88b083db7491
Child:
20:4ed21397e775
Commit message:
new;

Changed in this revision

camera_api.cpp Show annotated file Show diff for this revision Revisions of this file
camera_api.h 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
--- a/camera_api.cpp	Sun Jun 29 06:41:21 2014 +0000
+++ b/camera_api.cpp	Sun Jun 29 14:02:37 2014 +0000
@@ -15,6 +15,66 @@
 int BX_camera::black_centerR(void)
 {
 
+    int r_care=10;
+    int l_care=118;
+
+
+    // find center
+    // case 1      //  |  //
+    // case 2       /  |  /
+
+    char find_type=0x00;
+
+    int b_end=64;
+    int b_start=64;
+    int b_w=0;
+    int b_center=64;    
+    int b2_end=64;
+    int b2_start=64;
+    int b2_center=64;
+    int b2_w=0;
+    int center=30;
+    int j=64,i;
+    int offset=64;
+    bool f1=false;
+    bool f2=false;
+    bool f3=false;
+    bool f4=false;
+    bool count=false;
+    int same_chars=0;
+    int w_thr_up=32;
+    int w_thr_dn=2;
+
+    b_start=b_center=b_end=b2_start=b2_center=b2_end=offset;
+    
+    for(i=l_care-1; i>r_care; i--){
+        if(sign_line_imageR[i]==' ' && count==false){
+            b_start=i;
+            count=true;
+            if(last_sign_line_imageR[i]==' ')
+                same_chars++;
+        }
+        else if(sign_line_imageR[i]==' ' && count==true){
+            if(last_sign_line_imageR[i]==' ')
+                same_chars++;
+        }
+        else if(sign_line_imageR[i]!=' ' && count==true){
+            count=false;
+            if(same_chars>5 && same_chars<32){
+                b_end=i+1;
+                break;    
+            }
+        }
+    }
+    
+    center=(b_end+b_start)/2;
+    
+    for(i=l_care-1; i>r_care; i--){
+        last_sign_line_imageR[i]=sign_line_imageR[i];
+        }
+        
+    return center;
+/*
     int l_care=10;
     int r_care=118;
 
@@ -44,7 +104,7 @@
     int w_thr_dn=2;
 
     b_start=b_center=b_end=b2_start=b2_center=b2_end=offset;
-
+    
     if(sign_line_imageR[64]==' ')
         find_type=0x02;
     else
@@ -107,30 +167,15 @@
                 center=b2_center;
             else
                 center=offset;
-
-            /*            if( ( w_thr_up- (b_w))>0  &&( ( w_thr_up- (b_w)) < (w_thr_up-(b2_w)) )           ) {
-                            center=(b_end+b_start)/2;
-
-
-
-              //          } else if( ( w_thr_up- (b2_w) )>0 ) {
-                            center=(b2_end+b2_start)/2;
-            //            } else {
-
-                            center=65;
-
-                            //????????????????
-
-                        }
-
-            */
             break;
 
         case 0x02:
             center=(b_end+b_start)/2;
             break;
     }
+    
     return center;
+    */
 }
 
 
--- a/camera_api.h	Sun Jun 29 06:41:21 2014 +0000
+++ b/camera_api.h	Sun Jun 29 14:02:37 2014 +0000
@@ -13,7 +13,7 @@
     int  black_centerR(void); //index 0~127
     int  black_centerL(void);
     char sign_line_imageL[128];
-    char sign_line_imageR[128];
+    char sign_line_imageR[128], last_sign_line_imageR[128];
     int de_v;
     int de_v2;
     
--- a/main.cpp	Sun Jun 29 06:41:21 2014 +0000
+++ b/main.cpp	Sun Jun 29 14:02:37 2014 +0000
@@ -78,7 +78,8 @@
             else
                 pc.printf("%c", cam.sign_line_imageR[i]);
         }
-        pc.printf("\r\n");
+        pc.printf("    ");
+        //pc.printf("\r\n");
 #endif
 #endif
 
@@ -95,7 +96,7 @@
         //stand at 65
         error=b_r_c-offset;
         brc_df=b_r_c-last_brc;
-        last_brc=b_r_c;
+        
         
         if(first_time==true){
                 r_kp=0;
@@ -103,13 +104,16 @@
             }
         else{
                 r_kp+=brc_df;
+                if(b_r_c==last_brc)
+                    r_kp=0;
             }
+        last_brc=b_r_c;
             
         if(r_kp<0.0){
                 r_kp*=-1.0;
                 r_kp_neg=true;
             }
-        kp=0.016/(1280-r_kp);
+        kp=0.016/(30-(r_kp/10.0));
         if(r_kp_neg==true){
                 r_kp_neg=false;
                 r_kp*=-1.0;
@@ -129,9 +133,9 @@
 
         if(PID_v < 0.0) {
             PID_v*=-1.0;
-            PID_v=0.077-PID_v;
+            PID_v=0.077+PID_v;
         } else if(PID_v > 0.0)
-            PID_v=0.077+PID_v;
+            PID_v=0.077-PID_v;
         else
             PID_v=0.077;
         pc.printf("%lf %lf %lf\r\n",PID_v, r_kp, b_r_c);