Robotics Term Project / Mbed 2 deprecated Robottics_Motion

Dependencies:   mbed

Revision:
27:1696ef46b538
Parent:
26:dbdbfdb4dd41
Child:
28:d576b1190610
--- a/AI_Friday.cpp	Thu May 26 10:28:19 2016 +0000
+++ b/AI_Friday.cpp	Thu May 26 10:35:46 2016 +0000
@@ -80,6 +80,7 @@
 float wideB; // wide of the court
 int yB1,yB2,xB3,xB4; // broder conditions
 
+int ticCheck = 10;
 
 int main() {
     
@@ -235,30 +236,43 @@
                     funcBorder();
                     break;
                 case 2: // 前進 再判別   v1+  v2-
-                    if((borAngle-angleC)> 5 || (borAngle-angleC)<-5) //誤差容忍正負五度
-                    {
-                        v1_ref =  100;
-                        v2_ref = -100;    
-                    }
-                    bor_state = 1;
-                    break;
-                case 3: // 後退 再判別   v1-  v2+
-                    if((borAngle-angleC)> 5 || (borAngle-angleC)<-5)//誤差容忍正負五度
+                    if(ticCheck >0) //誤差容忍正負五度
                     {
                         v1_ref =  100;
                         v2_ref = -100;    
+                        ticCheck -- ;
                     }
-                    bor_state = 1;
+                    else
+                    {
+                        bor_state = 1;
+                        ticCheck = 10;
+                    }
+                    break;
+                case 3: // 後退 再判別   v1-  v2+
+                    
+                    if(ticCheck >0) //誤差容忍正負五度
+                    {
+                        v1_ref = -100;
+                        v2_ref = +100;    
+                        ticCheck -- ;
+                    }
+                    else
+                    {
+                        bor_state = 1;
+                        ticCheck = 10;
+                    }
                     break;
                 case 4: // 順時轉到特定角 結束  v1-- v2 --
-                    if((borAngle-angleC)> 5 || (borAngle-angleC)<-5)//誤差容忍正負五度
-                    {
+                    
                         v1_ref = -100;
                         v2_ref = -100;    
+                    
+                    else
+                    {
+                        borAngle = 0;
+                        aI_State = 2;
+                        bor_state = 1;
                     }
-                    borAngle = 0;
-                    aI_State = 2;
-                    bor_state = 1;
                     break;
                 case 5: // 逆時轉到特定角 結束  v1 ++   v2++
                      if((borAngle-angleC)> 5 || (borAngle-angleC)<-5)//誤差容忍正負五度
@@ -266,9 +280,12 @@
                         v1_ref = 100;
                         v2_ref = 100;    
                     }
-                    borAngle = 0;
-                    aI_State = 2;
-                    bor_state = 1;
+                    else
+                    {
+                        borAngle = 0;
+                        aI_State = 2;
+                        bor_state = 1;
+                    }
                     break;
                 
                 }