Curtis Sellier / Mbed 2 deprecated Project_Car_Curtis_Non_Tested

Dependencies:   Servo mbed

Files at this revision

API Documentation at this revision

Comitter:
csellier
Date:
Sun Oct 16 16:36:56 2016 +0000
Parent:
8:07464acc8a85
Child:
10:57a0c57cabac
Commit message:
updated program avoid obstacle 90 90 90

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Oct 14 09:53:56 2016 +0000
+++ b/main.cpp	Sun Oct 16 16:36:56 2016 +0000
@@ -28,8 +28,8 @@
     float front;
     float left;
     float right;
-    float LDRleft;
-    float LDRright;
+    float LDRvalueleft;
+    float LDRvalueright;
 
      // set the USB serial interface baud rate
      pc.baud(921600);
@@ -37,38 +37,71 @@
 
  while(1) {
     
-    // Auto drive
+    // Auto drive : the car will avoid all obstacles aroiund it and get away from them
     front = IRfront.read();
     left  = IRleft.read();
     right = IRright.read();
     LDRvalueright = LDRright.read();
-    LDRvalueleft = LDRleft.read()
+    LDRvalueleft = LDRleft.read();       //output voltage of the LDR used for line following feature
     
-    if (front > DISTANCE) {
-        if (left > DISTANCE) {
-            ServoRight.write(0.5);   //turn right
-            ServoLeft.write(0.4);
-        } else {
-            ServoRight.write(0.6);   // turn left
-            ServoLeft.write(0.5);    
-        }
-    } else if (left > DISTANCE) {
-        if (right < DISTANCE) {
-            ServoRight.write(0.5); // right
-            ServoLeft.write(0.4);
-        } else {
-            ServoRight.write(0.6); // forward    
-            ServoLeft.write(0.4);
-        }
-    }
-    
+   /*****************************************************************************
+   / if (front > DISTANCE) {           Collision avoidance system only,the robot will move away from an obstacle/wall if getting to close to it
+    /    if (left > DISTANCE) {
+    /        ServoRight.write(0.5);   //turn right
+    /        ServoLeft.write(0.4);
+    /    } else {
+    /        ServoRight.write(0.6);   // turn left
+    /        ServoLeft.write(0.5);    
+    /    }
+    / } else if (left > DISTANCE) {
+    /    if (right < DISTANCE) {
+    /        ServoRight.write(0.5); // right
+    /        ServoLeft.write(0.4);
+    /    } else {
+    /        ServoRight.write(0.6); // forward    
+    /        ServoLeft.write(0.4);
+    /    }
+    / }
+   /*****************************************************************************/
     //Turn both LED's on for the line following feature
     LEDleft=1;
     LEDright=1;
     
     // send the servo command to the servos themselves
-    ServoRight.write(0.6); // write to the continuous rotation servo1
-    ServoLeft.write(0.4); // write to the continous servo2
+    //ServoRight.write(0.6); // write to the continuous rotation servo1
+   // ServoLeft.write(0.4); // write to the continous servo2
+   
+   if (front > DISTANCE) {
+       // turn right
+       ServoRight.write(0.5); // stop servoright
+       ServoLeft.write(0.4); // turn on servoleft 
+       wait(2.0); //wait 2 seconds to allow the robot to turn approximately 90 degrees
+       if (left > DISTANCE) {
+           // keep going straight for 1 second
+           ServoRight.write(0.6); // write to the continuous rotation servo1
+           ServoLeft.write(0.4); // write to the continous servo2
+           wait(1.0);
+       } else {
+           // turn left 90 degrees
+           ServoRight.write(0.5);
+           ServoLeft.write(0.4);
+           wait(2.0); // wait 2 seconds to allow the robot to turn approx. 90 degrees
+           ServoRight.write(0.6); //go straight for 1 second
+           ServoLeft.write(0.4);
+           if (left > DISTANCE) {
+           //keep going straight for 1 second
+           ServoRight.write(0.6);
+           ServoLeft.write(0.4);
+           wait(1.0);      //wait for 1 second
+           } else {
+               // turn left 90 degrees
+               ServoRight.write(0.6);
+               ServoLeft.write(0.5);
+               wait(2.0);     //wait 2 seconds to allow robot to turn 90 degrees
+               }     
+           }
+           
+         
 
     }
 }