Final Project files for mBed development.

Dependencies:   m3pi mbed

Files at this revision

API Documentation at this revision

Comitter:
lsaristo
Date:
Tue Dec 09 01:56:03 2014 +0000
Parent:
29:459ff10d2a07
Child:
31:1e950ee04481
Commit message:
Removed extra centering 'wiggle' at calibration and shortened interval between instructions.

Changed in this revision

main.c Show annotated file Show diff for this revision Revisions of this file
--- a/main.c	Mon Dec 08 22:43:09 2014 +0000
+++ b/main.c	Tue Dec 09 01:56:03 2014 +0000
@@ -102,10 +102,11 @@
         pi.locate(0,0);
         pi.printf("O: %f", pos);
     }
-    pi.stop();
-    timerWait(2);
-
+    pi.stop();    
+    timerWait(0.5);
     backward(500);
+    
+    /* Maybe uncomment this depending on the surface.
     timerWait(.5);
     while(fabs(pos = pi.line_position()) > CLOSE_ENOUGH) {
         pi.right((pos < 0 ? -.6*CAL_SPEED : .6*CAL_SPEED));
@@ -114,10 +115,10 @@
         pi.printf("O: %f", pos);
     }
     pi.stop();
-    timerWait(2);
+    */
+    
+    timerWait(.6);
 
-    timerWait(1);
-    
     // Main program loop.
     size_t bytes_read = 0;
     int err, x, y, last_x, last_y, delta_x, delta_y;
@@ -154,7 +155,7 @@
     offset = instbuf+instbuflen-cur-1;
     memcpy(instbuf, cur, offset);
     while (1) {
-        timerWait(1);
+        timerWait(.18);
         memset(instbuf+offset, 0, instbuflen-offset);
         bytes_read = fread(instbuf+offset, sizeof(char), instbuflen-1-offset, ps_file);
         
@@ -189,6 +190,9 @@
         if (delta_a > 180) {
             delta_a -= 360;
         }
+        if (delta_a < -180) {
+            delta_a = 360 + delta_a;
+        }
         angle += delta_a;
         if (angle >= 360) {
             angle -= 360;
@@ -269,12 +273,10 @@
     Timer t;
     pi.locate(0,0);
     pi.printf("Fwd %d", amt);
+    t.start();
     pi.left_motor(DRIVE_SPEED+.0023);
     pi.right_motor(DRIVE_SPEED);
-    t.start();
     while(t.read_ms() < amt);
-    pi.left_motor(.7*DRIVE_SPEED+.0023);
-    pi.right_motor(.7*DRIVE_SPEED);
     t.stop();
     pi.stop();
 }
@@ -297,9 +299,10 @@
         return left(-1*deg);
     }
     Timer t;
-    pi.right(TURN_SPEED);
+    float amt = ((float)(deg/360)*TIME_FACT);
     t.start();
-    while(t.read_ms() < ((float)(deg/360)*TIME_FACT));
+    pi.right(TURN_SPEED);
+    while(t.read_ms() < amt);
     t.stop();
     pi.stop();
 }