Final Project

Dependencies:   Motor Servo TCS3472_I2C mbed

Fork of ES202_Final_Entire by Robert Stroup

Files at this revision

API Documentation at this revision

Comitter:
mon3ywolf
Date:
Tue Apr 28 01:50:18 2015 +0000
Parent:
0:267ae73c744e
Commit message:
final project final edits;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Apr 28 01:24:23 2015 +0000
+++ b/main.cpp	Tue Apr 28 01:50:18 2015 +0000
@@ -12,7 +12,6 @@
 AnalogIn range(p19);
 Serial pc(USBTX, USBRX);
 float distance;
-float new_distance;
 
 int main()      //starts the program
 {
@@ -106,7 +105,23 @@
             //pc.printf("No region. Bad data. \n");      //prints to tera term
             //  m1.speed(0.0);
         }
-
+        distance = 565.9273577*(range.read()) -.63993889;   //calculate the distance with the range sensor using a calibrated curve
+        if(distance>15) {       //if the obstacle is still very far away
+            m1.speed(0.5);      //move the motor forward (It will turn according to the RGB servo motor command above)
+            wait(0.1);
+            m1.speed(0);        //stop the motor and go back to the RGB sensor
+        } else {
+            while(distance>8) { //slow the movement down once you start to get close and no longer use the RGB sensor for directtion
+                s1 = 0.5;           //make it go straight towards the obstacle.
+                m1.speed(0.5);
+                wait(0.05);
+                m1.speed(0);
+            }
+            while(1) {
+                printf("Complete!\n");//entire an infinite loop so it doesn't move again after reaching the objective
+                wait(1);
+            }
 
+        }
     }
-}
+}
\ No newline at end of file