Gruppe 3 / Mbed 2 deprecated PES1

Dependencies:   Servo mbed pixy

Fork of PES by Gruppe 3

Files at this revision

API Documentation at this revision

Comitter:
itslinear
Date:
Wed Apr 19 10:07:55 2017 +0000
Parent:
8:6d9cd5ad332d
Child:
10:75a18bf17c86
Commit message:
tada

Changed in this revision

Kamera.cpp Show annotated file Show diff for this revision Revisions of this file
Kamera.h Show annotated file Show diff for this revision Revisions of this file
Roboter.cpp Show annotated file Show diff for this revision Revisions of this file
Roboter.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Kamera.cpp	Tue Apr 18 12:09:46 2017 +0000
+++ b/Kamera.cpp	Wed Apr 19 10:07:55 2017 +0000
@@ -1,3 +1,5 @@
-
+#include "Kamera.h"
 
-#include "Kamera.h"
\ No newline at end of file
+int kamera(){
+    return 1;
+    }
\ No newline at end of file
--- a/Kamera.h	Tue Apr 18 12:09:46 2017 +0000
+++ b/Kamera.h	Wed Apr 19 10:07:55 2017 +0000
@@ -3,6 +3,7 @@
 
 #include <mbed.h>
 
+int kamera();
 
 
 
--- 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;
+
+    }
 
 }
 
--- a/Roboter.h	Tue Apr 18 12:09:46 2017 +0000
+++ b/Roboter.h	Wed Apr 19 10:07:55 2017 +0000
@@ -4,6 +4,7 @@
 #include <mbed.h>
 #include "IRSensor.h"
 #include "Servo.h"
+#include "Kamera.h"
 
 class Roboter
 {
--- a/main.cpp	Tue Apr 18 12:09:46 2017 +0000
+++ b/main.cpp	Wed Apr 19 10:07:55 2017 +0000
@@ -40,78 +40,96 @@
     pwmL.period(0.00005f); // Setzt die Periode auf 50 μs
     pwmR.period(0.00005f);
     pwmL = 0.5f;
-    pwmR = 0.5f; 
-   
+    pwmR = 0.5f;
+
 
     int state = 1; // Diese Variable gibt an in welchem State man sich befindet
 
-    /*if ( kamera() == 1) {
-        state = 4;
-        } // Die Kamera erkennt ein grünen Klotz*/
-        while(1) {
+
+    while(1) {
+
+        if (kamera() == 1 || kamera() == 2 || kamera() == 3) {           // Die Kamera erkennt ein grünen Klotz
+            state = 4;
+        }
+        if(kamera() == 4) {     // Roboter in Position
+            state = 5;
+        }
+
 
         switch(state) {
 
-                case 1: // Roboter Anschalten mit Knopf
+            case 1: // Roboter Anschalten mit Knopf
 
-                    if (switchOnOff== 0){
-                        state = 5;
-                    }
+                if (switchOnOff== 0) {
+                    state = 2;
+                }
 
-                    break;
+                break;
 
-                case 2:
-                    roboter1.bandeAusweichen();
-                    static int time1 = 0;
-                    if(time1 < 10) {       // Im Kreis drehen für 1s
-                        pwmL = 0.4f;
-                        pwmR = 0.4f;
-                        time1 ++;
-                    } else {
-                        time1 = 0;
-                        pwmL = 0.5f;
-                        pwmR = 0.5f;
-                        state = 3;
-                    }
-                    break;
+            case 2:
+                static int time1 = 0;
+                if(time1 < 20) {       // Im Kreis drehen für 1s
+                    pwmL = 0.4f;
+                    pwmR = 0.4f;
+                    time1 ++;
+                } else {
+                    time1 = 0;
+                    pwmL = 0.5f;
+                    pwmR = 0.5f;
+                    state = 3;
+                }
+                break;
 
 
-                case 3:
-                    roboter1.bandeAusweichen();
-                    static int time2 = 0;
-                    if(time2 < 10) {    // gerade aus fahren
-                        pwmL = 0.6f;
-                        pwmR = 0.4f;
-                        time2 ++;
-                    } else {
-                        time2 = 0;
-                        pwmL = 0.5f;
-                        pwmR = 0.5f;
-                        state = 2;
-                    }
-                    break;
+            case 3:
+                roboter1.bandeAusweichen();
+                static int time2 = 0;
+                if(time2 < 40) {    // gerade aus fahren
+                    pwmL = 0.6f;
+                    pwmR = 0.4f;
+                    time2 ++;
+                } else {
+                    time2 = 0;
+                    pwmL = 0.5f;
+                    pwmR = 0.5f;
+                    state = 2;
+                }
+                break;
 
 
-                case 4: // Roboter erkennt gründer Klotz, Klotz wird angefahren
-
-                    
-                    break;
-
-                case 5: // Aufnehmen des Klotzes
+            case 4: // Roboter erkennt gründer Klotz, Klotz wird angefahren
+                roboter1.bandeAusweichen();
+                if(kamera() == 1) {     // links fahren
+                    pwmL = 0.45f;
+                    pwmR = 0.45f;
+                }
+                if(kamera() == 2) {     // rechts fahren
+                    pwmL = 0.55f;
+                    pwmR = 0.55f;
+                }
+                if(kamera() == 3) {     // gerade fahren
+                    pwmL = 0.55f;
+                    pwmR = 0.45f;
+                }
 
- roboter1.bandeAusweichen();
-                    
-                    break;
-                    
-                    
-                default: break;  
+                break;
+
+            case 5: // Aufnehmen des Klotzes
+
+                
 
-                    
-            }
+                break;
+
 
-            wait(0.1f);
+            default:
+                break;
+
 
         }
 
+        wait(0.1f);
+
     }
 
+}
+