Robotics Term Project / Mbed 2 deprecated Robottics_Motion

Dependencies:   mbed

Revision:
24:f61847968e72
Parent:
23:948ce071cbb6
Child:
25:7053736ea6cc
--- a/AI_Friday.cpp	Thu May 26 04:49:23 2016 +0000
+++ b/AI_Friday.cpp	Thu May 26 05:02:53 2016 +0000
@@ -731,9 +731,20 @@
         else //上邊界 
         {
           if(angleC == -90 || angleC == 90)
-          {aI_State = 2;} // do nothing, turn to next point
+            aI_State = 2; // do nothing, turn to next point
           else
-          {smallAngle(90);} // turn to 90, then turn to next point
+          {
+            if(0 > borAngle >= -90 || 90< borAngle <=0) //CW
+            {
+                bor_state = 4;
+                borAngle = 90;
+            }
+            else
+            {
+                bor_state = 5;
+                borAngle = 90;
+            }
+          } // turn to 90, then turn to next point
         }
       
         
@@ -785,9 +796,20 @@
         else //下邊界  
         {       
           if(angleC == -90 || angleC == 90)
-            aI_State = 2;} // do nothing, turn to next point
+            aI_State = 2; // do nothing, turn to next point
           else
-          {smallAngle(-90);} // turn to 90, then turn to next point
+          {
+            if(0 > borAngle >= -90 || 90< borAngle <=0) //CCW
+            {
+                bor_state = 5;
+                borAngle = -90;
+            }
+            else
+            {
+                bor_state = 4;
+                borAngle = -90;
+            }
+          } // turn to -90, then turn to next point
         }
         
        
@@ -796,43 +818,45 @@
     {
           if(angleC == 0 || angleC == 180)
             aI_State = 2; // do nothing, turn to next point
+
+          else if(-180 < angleC < 0) // CW
+          {
+             bor_state = 4;
+             borAngle = 0;
+          }
           else
           {
-        if(0<=angleC<90 || -90<=angleC<0)
-        {
-            bor_state = 5;
-            borAngle = 90;
-        }
-       } // turn to 90, then turn to next point
+              bor_state = 5;
+              borAngle = 0;
+          }
+                 // turn to 0, then turn to next point
     }
 
     else if(xC > xB4) //靠近右邊界     *********************************************88
     {
           if(angleC == 0 || angleC == 180)
             aI_State = 2; // do nothing, turn to next point
+            
+          else if(-180 < angleC < 0) // CCW
+          {
+             bor_state = 5;
+             borAngle = 180;
+          } // turn to 90, then turn to next point
           else
-          {smallAngle(180);} // turn to 90, then turn to next point
+          {
+              bor_state = 4;
+              borAngle = 180;
+          }
     }
   }
   else
   {aI_State = 2;}
 } // funcBorder() 
 
-    else if(xC > xB4) //靠近右邊界     *********************************************88
-    {
-          if(angleC == 0 || angleC == 180)
-          {} // do nothing, turn to next point
-          else
-          {smallAngle(180);} // turn to 90, then turn to next point
-    }
-  }
-  else
-  {aI_State = 2;}
-} // funcBorder() 
 //****************  smallAngle()  *****************************************
 
 void smallAngle( float goodAngle ) // use the smallest turn to right angle  ccw / cw,  based on 0~360 degree system
-{}
+{
     if(angleR > 0) // CW
     {
         // turn clockwise to goodAngle;
@@ -842,7 +866,7 @@
         // turn counter clockwise to goodAngle;
     }
 
-
+}
 //***************   turnCW() ***********************************
 
 void turnCW(float goodAngle)