für holdor

Dependencies:   Servo mbed pixy

Fork of PES by Gruppe 3

Revision:
9:d9e46f9c9e40
Parent:
8:6d9cd5ad332d
Child:
17:caf5ae550f2e
--- a/Roboter.cpp	Tue Apr 18 12:09:46 2017 +0000
+++ b/Roboter.cpp	Wed Apr 19 10:07:55 2017 +0000
@@ -39,31 +39,33 @@
     offsetDir = 0;
     offsetLin = 0;
 
-    if(sensors[0] < x && sensors[1] < x && sensors[5] < x) {  // alle sensoren aktiv, roboter fährt nach hinten
-        offsetLin = -0.1f;
-        printf("Alle sensoren aktiv"); 
+    while(sensors[0] < x && sensors[1] < x && sensors[5] < x) {  // alle sensoren aktiv, roboter fährt nach hinten
+        offsetLin = 0.1f;
+        *pwmL = 0.5f+offsetDir-offsetLin; // Setzt die Duty-Cycle auf 50%
+        *pwmR = 0.5f+offsetDir+offsetLin;
+
+    }
+
+    while(sensors[0].read() < x && sensors[5] > x) { // sensor vorne, roboter dreht nach links
+        offsetDir = -0.05;
+        *pwmL = 0.5f+offsetDir+offsetLin; // Setzt die Duty-Cycle auf 50%
+        *pwmR = 0.5f+offsetDir-offsetLin;
+
     }
 
-    if(sensors[0].read() < x && sensors[5] > x) { // sensor vorne, roboter dreht nach links
-        offsetDir = -0.05;
-        offsetLin = 0;
-        printf(" sensoren vorne"); 
-    }
-    
-    if(sensors[1] < x) {     // sensor rechts, roboter dreht nach links
+    while(sensors[1] < x) {     // sensor rechts, roboter dreht nach links
         offsetDir = -0.05;
-        offsetLin = 0;
-        printf("sensor rechts"); 
-    }
-    
-    if(sensors[5] < x && sensors[1]>(x+0.02f)) {     // sensor links, roboter dreht nach rechts
-        offsetDir = 0.05;
-        offsetLin = 0;
-        printf("sensor links"); 
+        *pwmL = 0.5f+offsetDir+offsetLin; // Setzt die Duty-Cycle auf 50%
+        *pwmR = 0.5f+offsetDir-offsetLin;
+
     }
 
-    *pwmL = 0.5f+offsetDir+offsetLin; // Setzt die Duty-Cycle auf 50%
-    *pwmR = 0.5f+offsetDir-offsetLin;
+    while(sensors[5] < x && sensors[1]>(x+0.02f)) {     // sensor links, roboter dreht nach rechts
+        offsetDir = 0.08;
+        *pwmL = 0.5f+offsetDir+offsetLin; // Setzt die Duty-Cycle auf 50%
+        *pwmR = 0.5f+offsetDir-offsetLin;
+
+    }
 
 }