der Roboter / S1

Dependencies:   SensoryTest

Fork of btbee by Nikolas Goldin

Files at this revision

API Documentation at this revision

Comitter:
mmpeter
Date:
Wed May 21 11:47:58 2014 +0000
Parent:
10:7ef481d28dcd
Child:
12:6b5dd9e5469c
Commit message:
Testing K=-0.5

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue May 20 14:33:23 2014 +0000
+++ b/main.cpp	Wed May 21 11:47:58 2014 +0000
@@ -6,9 +6,10 @@
 
 int main() {
     
-    float speed = 0.1;
-    float correction = 0.5;
+    float speed = 0.5;
+    float correction;
     float threshold = 0.5;
+    float k = -0.5;
     
     thinggy.locate(0,1);
     thinggy.printf("Line Flw");
@@ -17,27 +18,29 @@
     
     thinggy.sensor_auto_calibrate();
     while(1) {
+        
+        
          // -1.0 is far left, 1.0 is far right, 0.0 in the middle
-        float position= thinggy.line_position();
- 
-        // Too far to the right--slow left motor
-        if (position > threshold) {
-            thinggy.right_motor(speed);
+        float position = thinggy.line_position();
+        correction = k*(position);
+        
+        //speed limiting for right motor
+        if(speed + correction > 1){
+            thinggy.right_motor(1);
+        }
+        else{
+            thinggy.right_motor(speed+correction);
+        }
+        
+        //speed limiting for left motor
+        if(speed - correction > 1){
+            thinggy.left_motor(1);
+        }
+        else{
             thinggy.left_motor(speed-correction);
+        }
             
-        }
+        
  
-        // Too far to the left--slow right motor
-        else if (position < -threshold) {
-            thinggy.left_motor(speed);
-            thinggy.right_motor(speed-correction);
-            
-        }
- 
-        // Default: Centered
-        else {
-            thinggy.forward(speed);
-        }
-    }
-}
-
+      }
+    }
\ No newline at end of file