James Heavey / Mbed 2 deprecated 3875_DISSERTATION

Dependencies:   mbed 3875_Individualproject

Revision:
59:11e31ce4d675
Parent:
58:cb32aa0f4116
Child:
60:ea69bd1a9889
--- a/main/main.cpp	Sat Apr 18 17:33:31 2020 +0000
+++ b/main/main.cpp	Sat Apr 18 18:02:36 2020 +0000
@@ -454,19 +454,19 @@
     // find the closest previous node with unexplored paths and go back through the path until reaching that node, updating the path and directions appropriately, then choose turn
     // also if no nodes have unexplored paths set complete to true
     
-    bool complete = false;
+    bool fully_explored = true;
     
     int d_node;   // an index to the most recent (desired) node with unexplored paths
     
     for(int i = total_points; i >= 0; i--) {    // start from the most recently discovered node
         if( explored[i] != type[i] ) {          
-            complete = true;
+            fully_explored = false;
             d_node = i;
             break;
         }
     }
     
-    if( complete == false ) { looped_goal(); }
+    if( fully_explored == true && completed == false) {  completed = true; looped_goal(); }
     
     else {
             // compare node coordinates to previous node coordinates
@@ -1064,17 +1064,20 @@
     bool _switch = true;
     
     while(1) {
+        
         robot.lcd_clear();
         robot.lcd_goto_xy(0,0);
         robot.lcd_print("  ENTER   ", 10);
         robot.lcd_goto_xy(0,1);
         robot.lcd_print("=restart", 10);
         
-        while( button_enter.read() == 1 ) {
-            leds = 0b1001;
-            wait(0.2);
-            leds = 0b0110;
-            wait(0.2);
+        if( _switch ) {
+            while( button_enter.read() == 1 ) {
+                leds = 0b1001;
+                wait(0.2);
+                leds = 0b0110;
+                wait(0.2);
+            }
         }
         
         wait(2);
@@ -1083,8 +1086,6 @@
         
         goal_path_explored(_switch);
         
-        _switch = ~ _switch;
-        
         while(1) {
         
             if ( t_restart ){                // only start the timer if it isnt already started
@@ -1108,15 +1109,26 @@
                 if (dir == 'W'){ curr_coords[0] -= dist_est; }
                 
                 update_index();
+                
+                if( _switch == true && point[curr_index] == 100 )  { break; }
+                else if( _switch == false && point[curr_index] == 0 ) { break; }
+                
                 choose_turn(); //looks at the point we are at, examines the type vs explored and makes the appropriate turn also updates the explored
             
             }
-            
-            if( _switch == true && point[curr_index] == 100 )  { break; }
-            else if( _switch == false && point[curr_index] == 0 ) { break; }
         }
         
+        turn_select('B');
         robot.stop();
+        
+        if( dir == 'N' ) { dir = 'S'; }
+        else if( dir == 'S' ) { dir = 'N'; }
+        else if( dir == 'E' ) { dir = 'W'; }
+        else if( dir == 'W' ) { dir = 'E'; }
+        
+        robot.stop();
+        
+        _switch = ~ _switch;
     }  
 }