Finished!

Dependencies:   m3pi_ng mbed

Fork of BlueToothStuff by Stephen Tyson

Files at this revision

API Documentation at this revision

Comitter:
mmpeter
Date:
Thu May 22 11:57:29 2014 +0000
Child:
1:6402638c6f6d
Commit message:
Thursday's work 1

Changed in this revision

m3pi_ng.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m3pi_ng.lib	Thu May 22 11:57:29 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/ngoldin/code/m3pi_ng/#da9ef3d5c3fe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 22 11:57:29 2014 +0000
@@ -0,0 +1,79 @@
+#include "mbed.h"
+#include "m3pi_ng.h"
+#include "cmath"
+#include "iostream"
+ 
+using namespace std;
+ 
+m3pi thinggy;
+ 
+ 
+int main() {
+    
+    float speed = 0.25;
+    float correction;
+    float k = -0.3;
+    int sensor[5];
+    int returned;   
+    thinggy.locate(0,1);
+    thinggy.printf("Villan");
+    thinggy.locate(0,0);
+    thinggy.printf("Pimpin");
+    
+    wait(1.0);
+ 
+    thinggy.sensor_auto_calibrate();
+ 
+    thinggy.calibrated_sensor(sensor);
+    returned = (sensor[1] + sensor[2] + sensor[3])/3;
+ 
+    
+    
+    while(1) {
+        // change "if" to while
+        while(returned < 220){
+                while(sensor[0] < sensor[4] && thinggy.line_position() != 0){
+                    thinggy.left_motor(.2);
+                    thinggy.right_motor(-.2);
+                    thinggy.calibrated_sensor(sensor);
+                }
+                while(sensor[4] > sensor[0] && thinggy.line_position() != 0){
+                    thinggy.left_motor(-.2);
+                    thinggy.right_motor(.2);
+                    thinggy.calibrated_sensor(sensor);
+                }
+                thinggy.calibrated_sensor(sensor);
+                returned = (sensor[1] + sensor[2] + sensor[3])/3;
+        }
+        
+        // Curves and straightaways    
+        while(returned > 220){
+ 
+        float position = thinggy.line_position();
+        correction = k*(position);
+       
+         // -1.0 is far left, 1.0 is far right, 0.0 in the middle
+        
+        //speed limiting for right motor
+        if(speed + correction > 1){
+            thinggy.right_motor(0.6);
+            thinggy.left_motor(speed-correction);
+        } 
+        else if(speed - correction > 1){
+            thinggy.right_motor(speed+correction);
+            thinggy.left_motor(0.6);
+        }
+        else{
+            thinggy.left_motor(speed-correction);
+            thinggy.right_motor(speed+correction);
+        }
+         thinggy.calibrated_sensor(sensor);
+         returned = (sensor[1] + sensor[2] + sensor[3])/3;   
+        }
+    thinggy.calibrated_sensor(sensor);
+    returned = (sensor[1] + sensor[2] + sensor[3])/3;
+    }
+}
+ 
+ 
+ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu May 22 11:57:29 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877
\ No newline at end of file