Left and right turning needs to be worked out

Dependencies:   m3pi_ng mbed

Fork of CrossandMapping by Amanda Bayagich

Revision:
8:d5a5d104996e
Parent:
7:dd79b0942620
Child:
9:accfae3aaf72
--- a/main.cpp	Tue Jun 03 12:10:29 2014 +0000
+++ b/main.cpp	Tue Jun 03 12:48:53 2014 +0000
@@ -46,7 +46,7 @@
     
     //finds the directions of the robot 
     int startpt = 2; //start();  
-    int endpt = 3; //end(); 
+    int endpt = 4; //end(); 
     string d = directions(startpt, endpt);
     int turns = 0; 
  
@@ -54,8 +54,6 @@
         //check if it needs to turn 
         while(returned <= 240){
                 //turns right 
-               
-                
                 while(sensor[0] < sensor[4] && thinggy.line_position() != 0){
                     cross = cross_detection(sensor, black_thresh, white_thresh);
                     if(cross){
@@ -63,15 +61,15 @@
                         ++turns;
                         cross = 0;  
                     }
-                    thinggy.left_motor(turn_speed);
-                    thinggy.right_motor(-turn_speed);
+                    else {
+                        thinggy.left_motor(turn_speed);
+                        thinggy.right_motor(-turn_speed);
+                    }
                     
                     thinggy.calibrated_sensor(sensor);
                     
-                    
                 }
                 //turns left 
-                turn_left();
                 while(sensor[4] > sensor[0] && thinggy.line_position() != 0){
                     cross = cross_detection(sensor, black_thresh, white_thresh);
                     if(cross){
@@ -79,12 +77,12 @@
                         ++turns; 
                         cross = 0; 
                     }
-                    thinggy.left_motor(-turn_speed);
-                    thinggy.right_motor(turn_speed);
+                    else{
+                        thinggy.left_motor(-turn_speed);
+                        thinggy.right_motor(turn_speed);
+                    }
                     
                     thinggy.calibrated_sensor(sensor);
-                    
-                    
                 }
                 thinggy.calibrated_sensor(sensor);
                 returned = (sensor[1] + sensor[2]*2 + sensor[3])/4;
@@ -175,7 +173,7 @@
 string directions(int startpoint, int endpoint){
     string charmap[6][6] = {
        {"", "RLLR", "RLFF", "RRRLLF", "RRLFLRRRL", "RRLR"}, 
-       {"LRRL", "", "LLF", "LFRLLF", "LFRLRRL", "LRFLR"},
+       {"LRRL", "", "LLF", "LLRL", "LFRLRRL", "LRFLR"},
        {"FFRL", "FRR", "", "LL", "FLRLRRL", "FFFLR"},
        {"FRRLRL", "RLRR", "RR", "", "FFRL", "FRLRL"},
        {"RLLLRFRLL", "RLLRLFR", "RLFLR", "RLFF", "", "RLLLRL"},
@@ -193,48 +191,17 @@
     
     //tells it which direction to go 
     if(x == 'L'){
-        thinggy.locate(0,1);
-        thinggy.printf("Left");
-        thinggy.locate(0,0);
-        thinggy.printf("Pimpin");
-        thinggy.calibrated_sensor(sensor);
-        returned = (sensor[1] + sensor[2]*2 + sensor[3])/4;
         turn_left();
-        /*while(returned <= 240){
-                //turns left 
-                while(sensor[4] > sensor[0] && thinggy.line_position() != 0){
-                    thinggy.left_motor(-turn_speed);
-                    thinggy.right_motor(turn_speed);
-                    
-                    thinggy.calibrated_sensor(sensor);
-                    
-                }
-                thinggy.calibrated_sensor(sensor);
-                returned = (sensor[1] + sensor[2]*2 + sensor[3])/4;
-                
-        }//while returned <= 220 */
         return; 
     }
     else if(x == 'R'){
-        thinggy.calibrated_sensor(sensor);
-        returned = (sensor[1] + sensor[2]*2 + sensor[3])/4;
         turn_right();
-        /*while(returned <= 240){
-                //turns right 
-                while(sensor[0] < sensor[4] && thinggy.line_position() != 0){
-                    thinggy.left_motor(turn_speed);
-                    thinggy.right_motor(-turn_speed);
-                    
-                    thinggy.calibrated_sensor(sensor);
-                }
-                thinggy.calibrated_sensor(sensor);
-                returned = (sensor[1] + sensor[2]*2 + sensor[3])/4;
-                
-        }//while returned <= 220 */
         return; 
     }
     else if(x == 'F'){
-        //do nothing 
+        thinggy.printf("F"); 
+        thinggy.forward(speed); 
+        wait(.1); 
         return; 
     }
     else if (x == NULL){
@@ -246,9 +213,10 @@
 
 void turn_left(){
   int n=0;
-    while (n<1000){
-        thinggy.left_motor(0.2);
-        thinggy.right_motor(-0.2);
+  wait(.08); 
+    while (n<850){
+        thinggy.left_motor(-0.2);
+        thinggy.right_motor(0.2);
         n++;
         }
     thinggy.forward(0.2);
@@ -258,13 +226,13 @@
 
 void turn_right(){
     int n=0;
-    while (n<1000){
-        thinggy.left_motor(-0.2);
-        thinggy.right_motor(0.2);
+    wait(.08); 
+    while (n<850){
+        thinggy.left_motor(0.2);
+        thinggy.right_motor(-0.2);
         n++;
         }
     thinggy.forward(0.2);
-    wait(0.15);       
-    
+    wait(0.15);      
     
 }
\ No newline at end of file