AKUL check if this has the correct right and left turning, if not replace it Code with lots of comments

Dependencies:   m3pi_ng mbed

Fork of Working_on_Left_and_Right by der Roboter

Revision:
7:dd79b0942620
Parent:
6:a6f752174eef
Child:
8:d5a5d104996e
--- a/main.cpp	Tue Jun 03 11:54:28 2014 +0000
+++ b/main.cpp	Tue Jun 03 12:10:29 2014 +0000
@@ -13,6 +13,9 @@
 bool cross_detection(int sensor[5], int black_thresh, int white_thresh); 
 void mapping(string directions, float speed, int turns);
 string directions(int startpoint, int endpoint);
+void turn_right();
+void turn_left();
+
 int end(); 
 int start(); 
 
@@ -51,6 +54,8 @@
         //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){
@@ -62,8 +67,11 @@
                     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){
@@ -76,6 +84,7 @@
                     
                     thinggy.calibrated_sensor(sensor);
                     
+                    
                 }
                 thinggy.calibrated_sensor(sensor);
                 returned = (sensor[1] + sensor[2]*2 + sensor[3])/4;
@@ -190,7 +199,8 @@
         thinggy.printf("Pimpin");
         thinggy.calibrated_sensor(sensor);
         returned = (sensor[1] + sensor[2]*2 + sensor[3])/4;
-        while(returned <= 240){
+        turn_left();
+        /*while(returned <= 240){
                 //turns left 
                 while(sensor[4] > sensor[0] && thinggy.line_position() != 0){
                     thinggy.left_motor(-turn_speed);
@@ -202,13 +212,14 @@
                 thinggy.calibrated_sensor(sensor);
                 returned = (sensor[1] + sensor[2]*2 + sensor[3])/4;
                 
-        }//while returned <= 220
+        }//while returned <= 220 */
         return; 
     }
     else if(x == 'R'){
         thinggy.calibrated_sensor(sensor);
         returned = (sensor[1] + sensor[2]*2 + sensor[3])/4;
-        while(returned <= 240){
+        turn_right();
+        /*while(returned <= 240){
                 //turns right 
                 while(sensor[0] < sensor[4] && thinggy.line_position() != 0){
                     thinggy.left_motor(turn_speed);
@@ -219,7 +230,7 @@
                 thinggy.calibrated_sensor(sensor);
                 returned = (sensor[1] + sensor[2]*2 + sensor[3])/4;
                 
-        }//while returned <= 220
+        }//while returned <= 220 */
         return; 
     }
     else if(x == 'F'){
@@ -231,4 +242,29 @@
         wait(300); 
         return; 
     }
+}
+
+void turn_left(){
+  int n=0;
+    while (n<1000){
+        thinggy.left_motor(0.2);
+        thinggy.right_motor(-0.2);
+        n++;
+        }
+    thinggy.forward(0.2);
+    wait(0.15);          
+    
+}
+
+void turn_right(){
+    int n=0;
+    while (n<1000){
+        thinggy.left_motor(-0.2);
+        thinggy.right_motor(0.2);
+        n++;
+        }
+    thinggy.forward(0.2);
+    wait(0.15);       
+    
+    
 }
\ No newline at end of file