Final Project files for mBed development.

Dependencies:   m3pi mbed

Files at this revision

API Documentation at this revision

Comitter:
alecguertin
Date:
Fri Dec 19 03:41:52 2014 +0000
Parent:
44:fd755ef0f862
Child:
46:a3b9c0fe8f36
Commit message:
final commit

Changed in this revision

main.c Show annotated file Show diff for this revision Revisions of this file
--- a/main.c	Thu Dec 18 05:20:51 2014 +0000
+++ b/main.c	Fri Dec 19 03:41:52 2014 +0000
@@ -23,6 +23,7 @@
 /* Local File System */
 LocalFileSystem local("local");
 
+/* States specifying the robot's behavior. */
 enum RobotState {
     ERROR,
     LINE_CAL,
@@ -33,7 +34,6 @@
     TURN,
     MOVE,
     DRAW,
-    FIND_LINE,
     FINISHED,
 };
 
@@ -46,7 +46,7 @@
     double      dist;
     float       delta_a, angle, cal_time, pos, last_pos;
     size_t      bytes_read;
-    int         corner, err, init, x, y, last_x, last_y, dim_x, dim_y, offset, right_found, complete;
+    int         corner, err, init, x, y, last_x, last_y, dim_x, dim_y, offset, right_found;
     char        instbuf[INST_BUF_SIZE];
     char        *cur, *next;
     angle       =   0;
@@ -63,7 +63,6 @@
     cal_time    =   0;
     pos         =   0;
     last_pos    =   0;
-    complete    =   0;
     cur         =   NULL;
     next        =   NULL;
     ps_file     =   NULL;
@@ -91,7 +90,7 @@
                 last_state = state;
                 // Corner we are looking for specified by right_found
                 // If we already found the right corner, measure frame
-                if (right_found && !complete) {
+                if (right_found) {
                     caltimer.start();
                 }
                 corner = find_corner(1-right_found);
@@ -99,7 +98,7 @@
                     state = ERROR;
                     break;
                 }
-                if (right_found && !complete) {
+                if (right_found) {
                     caltimer.stop();
                     cal_time = caltimer.read_ms();
                 }
@@ -109,10 +108,7 @@
             // Reverse robot to face other corner of frame
             case REV_TURN:
                 last_state = state;
-                if (complete) {
-                    right(HALF_TURN);
-                    state = FINISHED;
-                } else if (right_found) {
+                if (right_found) {
                     right(HALF_TURN);
                     state = DRAW_INIT;
                 } else {
@@ -180,7 +176,7 @@
                 bytes_read = fread(instbuf+offset, sizeof(char), INST_BUF_SIZE-1-offset, ps_file);
                 if (instbuf[0] == '\0') {
                     pen_up();
-                    state = FIND_LINE;
+                    state = FINISHED;
                     break;
                 }
 
@@ -248,27 +244,6 @@
                 state = PARSE;
                 break;
 
-            case FIND_LINE:
-                if (angle > 0) {
-                    right(angle+QUARTER_TURN);
-                } else {
-                    right(angle+QUARTER_TURN);
-                }
-                pos = pi.line_position();
-                last_pos = pos;
-                pi.forward(DRIVE_SPEED/2);
-                while (pos < 0.6 && fabs(pos-last_pos) > 0.1) {
-                    pos = pi.line_position();
-                    last_pos = pos;
-                    robot_printf(0, "%f", pos);
-                }
-                pi.stop();
-                forward(300);
-                right(QUARTER_TURN);
-                last_state = state;
-                state = FIND_CORNER;
-                break;
-
             // Done drawing - alert user
             case FINISHED:
                 pi.stop();