Dependencies:   mbed

Revision:
1:e046cce6ceb8
Parent:
0:301acbabd57a
diff -r 301acbabd57a -r e046cce6ceb8 main.cpp
--- a/main.cpp	Thu Nov 11 05:45:44 2010 +0000
+++ b/main.cpp	Thu Nov 11 14:56:38 2010 +0000
@@ -6,6 +6,8 @@
 
 #define MAX 1.0
 #define MIN 0
+
+
 #define P_TERM 1
 #define I_TERM 0
 #define D_TERM 20
@@ -18,31 +20,33 @@
     wait(2.0);
 
     float right;
-	float left;
-	float position_of_line = 0.0;
+    float left;
+    float position_of_line = 0.0;
     float prev_pos_of_line = 0.0;
-	float derivative,proportional;
-	float integral = 0;
-	float power;
+    float derivative,proportional;
+    float integral = 0;
+    float power;
     m3pi.sensor_auto_calibrate();
     float speed = MAX;
-	
+    
     while (1) {
 
         // Get the position of the line.
         position_of_line = m3pi.line_position();
-		proportional = position_of_line;
-		// Compute the derivative
+        proportional = position_of_line;
+        // Compute the derivative
         derivative = position_of_line - prev_pos_of_line;
-		// Compute the integral
-		integral += proportional;
-
+        // Compute the integral
+        integral += proportional;
+         // Remember the last position.
+        prev_pos_of_line = position_of_line;
+        // Compute
         power = (proportional * (P_TERM) ) + (integral*(I_TERM)) + (derivative*(D_TERM)) ;
-		// Remember the last position.
-        prev_pos_of_line = position_of_line;        
+        
+        //    Compute new speeds   
         right = speed+power;
         left  = speed-power;
-        
+        // limit checks
         if (right < MIN)
             right = MIN;
         else if (right > MAX)