car using PID from centre line

Dependencies:   FRDM-TFC mbed CBuffer XBEE mbed_angular_speed motor2 MMA8451Q

Fork of KL25Z_Camera_Test by GDP 4

Revision:
23:b234e8fb51b3
Parent:
19:65f0b6febc23
--- a/main.cpp	Wed Dec 07 15:10:59 2016 +0000
+++ b/main.cpp	Fri Dec 09 11:20:24 2016 +0000
@@ -182,7 +182,8 @@
         //dutyCycleCorner(float cornerspeed, servo_pid.output);
         //dutyCycleCorner(speed, servo_pid.output);
         
-        //sensorCorner(left_motor_pid.desired_value, right_motor_pid.desired_value , servo_pid.output, 50);  
+        sensorCorner(left_motor_pid.desired_value, right_motor_pid.desired_value , servo_pid.output, speed);  
+        // may need speed for corner speed if slowing down for corner. 
     }
     
     if(abs(servo_pid.measured_value) > 0.11f){
@@ -199,8 +200,11 @@
             } else {
                 //sendString("stop turning turned=%d",turning);
                 keepTurning = 0;
-                turning = 0;    
-                TFC_SetMotorPWM(speed,speed);
+                turning = 0;
+                
+                left_motor_pid.desired_value = speed;
+                right_motor_pid.desired_value = speed;   
+                //TFC_SetMotorPWM(speed,speed);
             }
                
         }
@@ -279,12 +283,16 @@
     {
         if(0 > right_motor_pid.output)
         {
-            TFC_SetMotorPWM(left_motor_pid.output,0);
+            left_motor_pid.output=0;
+           
         }
         if(0 > left_motor_pid.output)
         {
-            TFC_SetMotorPWM(0,right_motor_pid.output);
+            right_motor_pid.output=0;
+            
         }
+        
+         TFC_SetMotorPWM(left_motor_pid.output,right_motor_pid.output);
     }