wu

Dependencies:   mbed-rtos mbed

Fork of Boboobooov4 by kao yi

Revision:
14:2d90b0066fc6
Parent:
13:63f9a5101205
Child:
15:585df3979be8
--- a/main.cpp	Sat Jun 28 08:37:06 2014 +0000
+++ b/main.cpp	Sat Jun 28 12:16:33 2014 +0000
@@ -14,6 +14,12 @@
 #define Pcontroller
 #define task_ma_time
 
+
+#define car_center 15
+
+
+
+
 #define t_cam 6
 
 
@@ -25,7 +31,7 @@
 
 BX_servo servo; 
 
-BX_camera cam(79);
+BX_camera cam(0);
 
 BX_motor MotorA('A');
 BX_motor MotorB('B');
@@ -42,18 +48,14 @@
 Mutex stdio_mutex; 
 
 
-/*
-void led2_thread(void const *args) {
-   while (true) {
-        led2 = !led2;
-        Thread::wait(1000);
-    }
-}
-*/
+
+
+
+//static int line3[3]; //special point 
 
 static int b_r_c=0;
-static int b_l_c=0;
-static int line3[3]; //special point 
+static int b_l_c=118;
+
 static int l3_p=0;
 
 static double v_motor;
@@ -62,24 +64,13 @@
 void cam_thread(void const *args){
     
     while(true){
+     
         cam.read();
         
-        b_l_c=(double)cam.black_centerL();
         
-        if(l3_p==0){
-        
-            line3[l3_p]=(double)cam.black_centerL();
-        }else if(l3_p==1){
-            line3[l3_p]=0;
-            
-        }else {
-           line3[l3_p]=(double)cam.black_centerR();    
-               
-        }        
-               
-        l3_p++;
-        if(l3_p==3)
-            l3_p=0;
+        b_r_c=cam.black_centerR();
+      
+          
             
         Thread::wait(t_cam);
         
@@ -125,7 +116,7 @@
          }
          pc.printf("\r\n");
      #endif
-         pc.printf("L: %d  mid: %d R: %d   center : %d    \r\n",line3[0],line3[1],line3[2],(line3[0]+line3[2])/2 );
+         pc.printf("L: %d  mid: %d R: %d  center: %d \r\n", );
          stdio_mutex.unlock();
      
          
@@ -149,15 +140,12 @@
 
         while(1){
 
-             int ctrl=(line3[0]+line3[2])/2;
             
         
-             v_servo=cam_to_M_ctrlr.compute(ctrl,118.0);
-             
-          //   pc.printf("angle: %f\r\n",v_servo);
-              stdio_mutex.lock();
+         v_servo=cam_to_M_ctrlr.compute(b_r_c,car_center);
+        
              servo.set_angle(v_servo);
-             stdio_mutex.unlock();
+            
          Thread::wait(20);    
         }    
     
@@ -169,11 +157,11 @@
     
         while(1){
             
-            
+             v_motor=pot1.read();
              MotorA.rotate(v_motor);
              MotorB.rotate(v_motor);
             
-            Thread::wait(1);    
+            Thread::wait(10);    
         }
       
       
@@ -188,7 +176,6 @@
     
       while(1){
           
-         b_r_c=(double)cam.black_centerR();
 
          cam_to_M_ctrlr.compute(b_r_c,64.0);
           
@@ -224,9 +211,9 @@
     */
       Thread th_c(cam_thread);
    //   Thread thread(ctrl_thread);  
-      Thread thread(servo_thread);  
-   //   Thread thread(motor_thread);     
-        Thread th_de(de_thread);  
+      Thread th_s(servo_thread);  
+      Thread th_m(motor_thread);     
+     //   Thread th_de(de_thread);  
      while(1){
          
            
@@ -234,7 +221,7 @@
   //   stdio_mutex.lock();
     //    printf("L: %d  mid: %d R: %d\r\n",line3[0],line3[1],line3[2]);
     // stdio_mutex.unlock();     
-          Thread::wait(2000);
+         // Thread::wait(2000);
     
      }