fatboyslim / Mbed 2 deprecated bouncesinglecam

Dependencies:   FRDM-TFC mbed

Revision:
14:1a408e13679d
Parent:
13:8a667757beb3
Child:
15:60d699b587c5
--- a/main.cpp	Thu Mar 26 19:44:24 2015 +0000
+++ b/main.cpp	Thu Mar 26 20:18:04 2015 +0000
@@ -156,7 +156,7 @@
                     
   
                     // checking for center line (single line)
-                    for (uint16_t i=15; i<113; i++) {
+                    for (uint16_t i=10; i<118; i++) {
                         if ((*(TFC_LineScanImage0+i) < 450)) {
                             black_values_list[black_value_count] = i;
                             black_value_count++;
@@ -179,15 +179,15 @@
                     
                     uint8_t num = 0;
                     
-                    if(center_now > 15 && center_now < 27)
+                    if(center_now > 10 && center_now < 27)
                         num = 1;
-                    else if(center_now >= 27 && center_now < 54)
+                    else if(center_now >= 27 && center_now < 63)
                         num = 2;
-                    else if(center_now > 60 && center_now < 70)
+                    else if(center_now > 63 && center_now < 65)
                         num = 15;
-                    else if(center_now >= 54 && center_now < 81)
+                    else if(center_now >= 65 && center_now < 81)
                         num = 4;
-                    else if(center_now >= 81 && center_now < 113)
+                    else if(center_now >= 81 && center_now < 118)
                         num = 8;
                     
                     else
@@ -205,10 +205,24 @@
                     
                     // turn left
                     // hit wall a little bit on the right
-                    if (num==8 and right_counter <.2 ) // only if we arent turning right
+                    //if (num==8 and right_counter <.2 ) // only if we arent turning right
+                    if(center_now >= 110 && center_now < 118 and right_counter <.2)
                     {
                         //turn away a little bit for each frame that is wall
-                        if (left_counter >-.4)
+                        if (left_counter >-.45)
+                            //left_counter -=.05;    
+                            left_counter -=.03; 
+                            
+                        turn_left=true;
+                        turn_right=false;
+                    }
+                    
+                    // turn left
+                    // hit wall a little bit on the right
+                    if(center_now >= 81 && center_now < 110 and right_counter <.2)
+                    {
+                        //turn away a little bit for each frame that is wall
+                        if (left_counter >-.45)
                             left_counter -=.05;    
                             //left_counter -=.03; 
                             
@@ -216,22 +230,35 @@
                         turn_right=false;
                     }
                     
+                    
                     // turn left real hard
                     // wall is close to center on right
                     if (num==4 and right_counter <.2) // only if we arent turning right
                     {
-                        left_counter=-0.5;
+                        left_counter=-0.54;
                         turn_left=true;
                         turn_right=false;
                         need_decel=true;
                     }
                     
+                    // turn right hard
+                    // wall is close to center on left
+                      else if (num==2 and left_counter >-.2)// only if we arent turning left
+                    {
+                        right_counter =.54;
+                        turn_left=false;
+                        turn_right=true;
+                        need_decel=true;
+                    }
+                    
+                    
                     // turn right
                     // hit wall a little bit on the left
-                    else if (num==1 and left_counter >-.2) // only if we arent turning left
+                    //else if (num==1 and left_counter >-.2) // only if we arent turning left
+                    else if ( center_now > 15 && center_now < 27 and left_counter >-.2) // only if we arent turning left
                     {    
                         //turn away a little bit for each frame that is wall
-                        if (right_counter <.4)
+                        if (right_counter <.45)
                             right_counter +=.05;
                             //right_counter +=.03;
               
@@ -239,16 +266,20 @@
                         turn_right=true;
                     }
                     
-                    // turn right hard
-                    // wall is close to center on left
-                      else if (num==2 and left_counter >-.2)// only if we arent turning left
-                    {
-                        right_counter =.5;
+                    // turn right
+                    // hit wall a little bit on the left
+                    else if ( center_now > 10 && center_now < 15 and left_counter >-.2) // only if we arent turning left
+                    {    
+                        //turn away a little bit for each frame that is wall
+                        if (right_counter <.45)
+                            //right_counter +=.05;
+                            right_counter +=.03;
+              
                         turn_left=false;
                         turn_right=true;
-                        need_decel=true;
                     }
 
+
                    // going straight yesssss
                    else if (turn_right == false and turn_left == false and (violence_level !=0))
                     {
@@ -285,7 +316,7 @@
 
                         if (need_decel) // need to deal with the decel
                             {
-                                TFC_SetMotorPWM(current_left_motor_speed+(.55*left_counter), current_right_motor_speed-(.4*left_counter));  // ++left is slowed,--right is slowed 
+                                TFC_SetMotorPWM(current_left_motor_speed+(.7*left_counter), current_right_motor_speed-(.5*left_counter));  // ++left is slowed,--right is slowed 
                                 need_decel = false;
                             }
                         else  //  turning speeds 
@@ -316,7 +347,7 @@
                             
                         if(need_decel)// need to deal with the decel
                             {
-                                TFC_SetMotorPWM(current_left_motor_speed+(.55*right_counter), current_right_motor_speed-(.4*right_counter));  // ++left is slowed,--right is slowed 
+                                TFC_SetMotorPWM(current_left_motor_speed+(.5*right_counter), current_right_motor_speed-(.7*right_counter));  // ++left is slowed,--right is slowed 
                                 need_decel = false;
                             }
                         else    //  turning speeds