Final Project files for mBed development.

Dependencies:   m3pi mbed

Files at this revision

API Documentation at this revision

Comitter:
lsaristo
Date:
Sun Nov 16 09:17:20 2014 +0000
Parent:
12:1aa6b8a74136
Child:
14:41fa8b95a9ab
Child:
15:14d4e7021125
Commit message:
Incorporated untested line calibration correction

Changed in this revision

main.c Show annotated file Show diff for this revision Revisions of this file
--- a/main.c	Sun Nov 16 09:11:34 2014 +0000
+++ b/main.c	Sun Nov 16 09:17:20 2014 +0000
@@ -47,12 +47,25 @@
     // Basic setup information
     start_button.mode(PullUp);
         
+    //
+    // Drawing environment calibration.
     pi.sensor_auto_calibrate();
     pi.backward(DRIVE_SPEED);
-    float pos;
+    float   pos;
+    float   over_thresh = 0.5;
+    float   correction  = 0.1;
     
     do {
         pos = pi.line_position();
+        if(pos > over_thresh) {
+            pi.right_motor(DRIVE_SPEED);
+            pi.left_motor(DRIVE_SPEED - correction);
+        } else if(pos < -over_thresh) {
+            pi.left_motor(DRIVE_SPEED);
+            pi.right_motor(DRIVE_SPEED - correction);
+        } else {
+            pi.forward(DRIVE_SPEED);
+        }
         pi.cls();
         pi.locate(0,0);
         pi.printf("P: %f", pos);
@@ -71,6 +84,15 @@
     while(pi.line_position() == 1);
     do {
         pos = pi.line_position();
+        if(pos > over_thresh) {
+            pi.right_motor(DRIVE_SPEED);
+            pi.left_motor(DRIVE_SPEED - correction);
+        } else if(pos < -over_thresh) {
+            pi.left_motor(DRIVE_SPEED);
+            pi.right_motor(DRIVE_SPEED - correction);
+        } else {
+            pi.forward(DRIVE_SPEED);
+        }
         pi.cls();
         pi.locate(0,0);
         pi.printf("Pos: %f", pos);