IT GOES NORTH MOST OF THE TIME

Dependencies:   HMC6352 Motor mbed

Revision:
12:204600e080c4
Parent:
11:0fd03f66af0d
Child:
13:76a6ce8b2116
--- a/main.cpp	Wed Oct 10 08:27:10 2012 +0000
+++ b/main.cpp	Wed Oct 10 09:05:22 2012 +0000
@@ -30,7 +30,7 @@
         readFront=irFront;
         diagRight=dirRight;
         diagLeft=dirLeft;
-    
+   
     int NorthOn=0;
     int NorthCount=0;
         for(j=0;j<2;j++) stable[0][j] = readLeft;
@@ -69,6 +69,8 @@
 
         switch(dir){
             case Forward:
+            
+                NorthCount++;
                 if ((avgFront<35&&stable[4][0]<35&&stable[4][1]<35)/*&&stable[4][2]<35&&stable[4][3]<35)*/||
                     (diagLeft<35&&stable[2][0]<35&&stable[2][1]<35/*&&stable[2][2]<35&&stable[2][3]<35)*/
                     /*(avgLeft<40&&stable[0][0]<40&&stable[0][1]<40&&stable[0][2]<40&&stable[0][3]<40)*/))
@@ -100,7 +102,9 @@
                 else {right.speed(1); left.speed(1);
                 //printf("CHARGE!\n\r");
                 if((avgLeft>35&&stable[0][0]>35&&stable[0][1]>35)
-                   &&(avgRight>35&&stable[1][0]>35&&stable[1][1]>35)) NorthOn=1;
+                   &&(avgRight>35&&stable[1][0]>35&&stable[1][1]>35)
+                   &&NorthCount>=350){ NorthOn=1; NorthCount=0;}
+
                 }
             break;
             case Right:
@@ -149,15 +153,15 @@
             case TurnNorth:
                 //printf("TO THE NORTH!\n\r");
                 if(
-                   (avgLeft<35||stable[0][0]<35||stable[0][1]<35)
+                   (avgLeft<35&&stable[0][0]<35&&stable[0][1]<35)
                    ||
-                   (avgRight<35||stable[1][0]<35||stable[1][1]<35)
+                   (avgRight<35&&stable[1][0]<35&&stable[1][1]<35)
                    ||
-                   (diagLeft<35||stable[2][0]<35||stable[2][1]<35)
+                   (diagLeft<35&&stable[2][0]<35&&stable[2][1]<35)
                    ||
-                   (diagRight<35||stable[3][0]<35||stable[3][1]<35)
+                   (diagRight<35&&stable[3][0]<35&&stable[3][1]<35)
                    ||
-                   (avgFront<35||stable[4][0]<35||stable[4][1]<35)
+                   (avgFront<35&&stable[4][0]<35&&stable[4][1]<35)
                    )
                    {right.speed(0);
                     left.speed(0);