Object Avoidance Program

Dependencies:   4DGL-uLCD-SE Motordriver mbed

Revision:
4:1c83cabcd6f8
Parent:
3:8af20d0242b2
Child:
5:50887f863c01
--- a/main.cpp	Tue Apr 29 22:06:35 2014 +0000
+++ b/main.cpp	Tue Apr 29 22:18:25 2014 +0000
@@ -50,33 +50,105 @@
 //        pc.printf("Right Sensor is: %f \n", rightsensor);
 //        
         if((frontsensor > 52)&&(frontsensor < 100)){
-            //mA.stop(0.5);
-              //   mB.stop(0.5);
-                //mA.speed(-.6);
-                //mB.speed(-.8); 
-                //led_front = 1;
-             //   led_back = 0;
-               // led_left = 0;
-             //   led_right = 0;
-               // mA.stop(0.5);
-                 //mB.stop(0.5);
-              led_front = 1;
-              }
-              else {led_front= 0;}
+            sensor = 2;}
+        else if((backsensor > 52)&&(backsensor < 100)){
+            sensor = 3;}
+        else if((leftsensor > 52)&&(leftsensor < 100)){
+            sensor = 1;}
+         else if((rightsensor > 52)&&(rightsensor < 100)){
+            sensor = 0;}
+        
+        
+        switch(sensor) 
+        {
+            case 0: //Right
+                mA.speed(.6);
+                mB.speed(.9);  
+                led_right = 1;
+                break;
+            case 1: // Left
+                mA.speed(.9);
+                mB.speed(.6);  
+                led_left = 1;
+                break;
+            case 2: // Front
+          //       mA.stop(0.5);
+//                 mB.stop(0.5);
+                mA.speed(-1);
+                mB.speed(-1); 
+                led_front = 1;
+                //mA.stop(0.5);
+//                 mB.stop(0.5);
 
-              if((backsensor > 52)&&(backsensor < 100)){
-            led_back = 1;}
-            else {led_back = 0;}
-
-          if((leftsensor > 52)&&(leftsensor < 100)){
-            led_left = 1;}
-            else {led_left = 0;}
-
-          if((rightsensor > 52)&&(rightsensor < 100)){
-            led_right = 1;}
-          else {led_right = 0;}
-
-
-
+                mA.speed(.2);
+                mB.speed(.2);
+                wait(0.5);
+                break;    
+            case 3: // Back//
+//                mA.speed(.4);
+//                mB.speed(.4);
+//                wait(0.5);
+//                 mA.stop(0.5);
+//                 mB.stop(0.5);
+                mA.speed(.7);
+                mB.speed(.7);  
+                led_back = 1;
+                break;
+            default ://
+//                mA.speed(.5);
+//                mB.speed(.5);
+//                wait(0.5);
+//                 mA.stop(0.3);
+//                 mB.stop(0.3);
+                mA.speed(0.7);
+                mB.speed(0.7);
+                led_left = 0;
+                led_back = 0;
+                led_front = 0;
+                led_right = 0;
+                 break; 
         }
+                //led_left = 0;
+                //led_back = 0;
+                //led_front = 0;
+                //led_right = 0;
+        sensor = 4; //DEFAULT CONDITION
+       // Back Sensor
+       // if((backsensor > 52)&&(backsensor < 100)){
+//            mA.speed(.8);
+//            mB.speed(.8);  
+//            led_back = 1;
+//                             
+//        }
+//        // front Sensor
+//        else if((frontsensor > 52)&&(frontsensor < 100)){
+//            mA.speed(-1);
+//            mB.speed(-1);  
+//            led_front = 1;
+//                             
+//        }else
+//        // right Sensor
+//        if((rightsensor > 52)&&(rightsensor < 100)){
+//            mA.speed(.4);
+//            mB.speed(.6);  
+//            led_right = 1;
+//                             
+//        }else // Left Sensor
+//        if((leftsensor > 52)&&(leftsensor < 100)){
+//            mA.speed(.6);
+//            mB.speed(.4);  
+//            led_left = 1;
+//                             
+//        }else{
+//             mA.speed(1);
+//           mB.speed(1);
+//            led_left = 0; 
+//            led_back = 0;
+//            led_front = 0;
+//            led_right = 0;
+//        }     
+        
+        
+        wait(0.1);
+    }
 }
\ No newline at end of file