fatboyslim / Mbed 2 deprecated bouncesinglecam

Dependencies:   FRDM-TFC mbed

Revision:
7:f21986164bf1
Parent:
6:ed97e4324202
Child:
8:2a238dbd0386
--- a/main.cpp	Thu Mar 26 02:29:18 2015 +0000
+++ b/main.cpp	Thu Mar 26 15:51:49 2015 +0000
@@ -78,6 +78,7 @@
     float right_counter =0;
     bool turn_left=false;
     bool turn_right=false;
+    bool need_decel=false;
 
     //servo is offset zero by some bullshit number
     float bullshit_offset = .074;
@@ -195,8 +196,8 @@
                     if (num==8 and right_counter <.2 )
                     {
                         //turn away a little bit for each frame that is wall
-                        if (left_counter >-.5)
-                            left_counter -=.1;    
+                        if (left_counter >-.4)
+                            left_counter -=.04;    
                             
                         turn_left=true;
                         turn_right=false;
@@ -206,9 +207,10 @@
                     // wall is close to center on right
                     if (num==4 and right_counter <.2)
                     {
-                        left_counter=-0.56;
+                        left_counter=-0.5;
                         turn_left=true;
                         turn_right=false;
+                        need_decel=true;
                     }
                     
                     // turn right
@@ -216,8 +218,8 @@
                     else if (num==1 and left_counter >-.2)
                     {    
                         //turn away a little bit for each frame that is wall
-                        if (right_counter <.5)
-                            right_counter +=.1;
+                        if (right_counter <.4)
+                            right_counter +=.04;
               
                         turn_left=false;
                         turn_right=true;
@@ -227,9 +229,10 @@
                     // wall is close to center on left
                       else if (num==2 and left_counter >-.2)
                     {
-                        right_counter =.56;
+                        right_counter =.5;
                         turn_left=false;
                         turn_right=true;
+                        need_decel=true;
                     }
 
                    // going straight yesssss
@@ -251,7 +254,13 @@
                         if (left_counter > (0+ bullshit_offset))
                             turn_left = false;
 
-                        TFC_SetMotorPWM(current_left_motor_speed+(.1*left_counter), current_right_motor_speed+(.3*left_counter));  
+                        if (need_decel)
+                            {
+                                TFC_SetMotorPWM(current_left_motor_speed+(.3*left_counter), current_right_motor_speed-(.2*left_counter));  // ++left is slowed,--right is slowed 
+                                need_decel = false;
+                            }
+                        else
+                            TFC_SetMotorPWM(current_left_motor_speed+(.1*left_counter), current_right_motor_speed+(.3*left_counter));  //  ++left is slowed, ++right is faster
                         }
                     
                     // set servo and motors according to how much right we need to turn
@@ -264,7 +273,13 @@
                         if (right_counter < (0+ bullshit_offset))
                             turn_right = false;
                             
-                        TFC_SetMotorPWM(current_left_motor_speed-(.3*right_counter), current_right_motor_speed-(.1*right_counter));        
+                        if(need_decel)
+                            {
+                                TFC_SetMotorPWM(current_left_motor_speed+(.2*left_counter), current_right_motor_speed-(.3*left_counter));  // ++left is slowed,--right is slowed 
+                                need_decel = false;
+                            }
+                        else    
+                            TFC_SetMotorPWM(current_left_motor_speed-(.3*right_counter), current_right_motor_speed-(.1*right_counter));  //  --left is faster, --right is slowed      
                         }   
 
                     // clearing values for next image processing round