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:
Tue Apr 11 11:47:04 2017 +0000
Parent:
3:24e098715b78
Child:
5:f48b2609c328
Commit message:
hallo

Changed in this revision

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
Servos.cpp Show diff for this revision Revisions of this file
Servos.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Roboter.cpp	Tue Apr 04 13:27:59 2017 +0000
+++ b/Roboter.cpp	Tue Apr 11 11:47:04 2017 +0000
@@ -1,7 +1,8 @@
 #include "Roboter.h"
 
 
-Roboter::Roboter(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, PwmOut* pwmL, PwmOut* pwmR, Servo* s1, Servo* s2)
+Roboter::Roboter(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, PwmOut* pwmL, PwmOut* pwmR, Servo* s1, Servo* s2,DigitalIn* switch1, DigitalIn* switch2)
+
 {
 
     sensors[0].init( distance, bit0, bit1, bit2, 0);
@@ -13,6 +14,11 @@
 
     this->pwmR = pwmR;
     this->pwmL = pwmL;
+    this->s1 = s1;
+    this->s2 = s2;
+    this->switch1 = switch1;
+    this->switch2 = switch2;
+
 
     pwmL->period(0.00005f); // Setzt die Periode auf 50 μs
     pwmR->period(0.00005f);
@@ -54,7 +60,6 @@
     *pwmL = 0.5f+offsetDir+offsetLin; // Setzt die Duty-Cycle auf 50%
     *pwmR = 0.5f+offsetDir-offsetLin;
 
-    wait(0.1);
 }
 
 
@@ -67,10 +72,22 @@
 
 }
 
-void Roboter::turn()      //im Kreis drehen
+void Roboter::findBlock()      //im Kreis drehen
 {
+    static int count =0;
+    count++;
+
+    if(count <= 10);      //1s lang (10*0.1s) im Kreis drehen
     *pwmL = 0.55f;
-    *pwmR = 0.45f;
+    *pwmR = 0.55f;
+
+    if(count > 10 && count <= 20); //zwischen Sekunde 1 und 2 geradeaus fahren
+    *pwmL = 0.6f;
+    *pwmR = 0.4f;
+
+    if(count > 20 && count <=30); //zwischen Sekunde 2 und 3 im Kreis drehen
+    *pwmL = 0.55f;
+    *pwmR = 0.55f;
 
 }
 
--- a/Roboter.h	Tue Apr 04 13:27:59 2017 +0000
+++ b/Roboter.h	Tue Apr 11 11:47:04 2017 +0000
@@ -10,12 +10,12 @@
 
 public:
 
-    Roboter(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2,   PwmOut * pwmL, PwmOut* pwmR, Servo* s1, Servo* s2);
+    Roboter(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2,   PwmOut * pwmL, PwmOut* pwmR, Servo* s1, Servo* s2, DigitalIn * switch1, DigitalIn* switch2 );
 
     void bandeAusweichen();
     float readSensor1();
     void pickup();
-    void turn();
+    void findBlock();
 
 
 private:
@@ -24,6 +24,10 @@
 
     PwmOut* pwmL;
     PwmOut* pwmR;
+    Servo*s1;
+    Servo*s2;
+    DigitalIn * switch1;
+    DigitalIn* switch2; 
 
 
 
--- a/Servos.cpp	Tue Apr 04 13:27:59 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-#include "Servos.h" 
-#include "Servo.h" 
-
-
-
--- a/Servos.h	Tue Apr 04 13:27:59 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-#ifndef SERVOS_H_
-#define SERVOS_H_
-
-#include <mbed.h>
-
-
-class Servos{
-    
-    public: 
-    
-    
-
-    
-    
-    
-    } 
-    
-    #endif /* SERVOS_H_ */
\ No newline at end of file
--- a/main.cpp	Tue Apr 04 13:27:59 2017 +0000
+++ b/main.cpp	Tue Apr 11 11:47:04 2017 +0000
@@ -12,8 +12,12 @@
 IRSensor sensors[6];
 
 // Periphery for servos
-Servos servos1(PB_7);
-Servos servos2(PA_6);
+Servo servos1(PB_7);
+Servo servos2(PA_6);
+
+//Periphery for limit switch 
+DigitalIn limitSwitch1(PA_10);
+DigitalIn limitSwitch2(PB_13); 
 
 //motor stuff
 DigitalOut enableMotorDriver(PB_2);
@@ -23,31 +27,29 @@
 //indicator leds arround robot
 DigitalOut leds[] = { PC_8, PC_6, PB_12, PA_7, PC_0, PC_9 };
 
-Roboter roboter1(&distance, &bit0, &bit1, &bit2, &pwmL, &pwmR, &servos1,&servos2);
+Roboter roboter1(&distance, &bit0, &bit1, &bit2, &pwmL, &pwmR, &servos1,&servos2, &limitSwitch1, &limitSwitch2);
 
 int main()
 {
     enable = 1;
     enableMotorDriver = 1;
 
-    while(1) {
-
-        roboter1.kamera();        //Kameraauswertung
+    /*roboter1.kamera();        //Kameraauswertung
 
-        roboter1.getBlock
-
-        while(camY>20) {          //ausweichen aktive solange Y-Wert von Kamera grösser als 20
-            roboter1.bandeAusweichen();
-        }
+    while(cam=1) {
+        roboter1.getBlock();
+        wait(0.1f);
+    }*/
 
-        while(cam==0) {           //im Kreis drehen bis Kamera einen Klotz sieht
-            if(
-                roboter1.turn();
-        }
+    //while(cam==1 && camY>20) {         //ausweichen aktive solange Y-Wert von Kamera grösser als 20
+        roboter1.bandeAusweichen();
+        wait(0.1f);
+    //}
 
-
+    //while(cam==0) {           //im Kreis drehen bis Kamera einen Klotz sieht
+        roboter1.findBlock();
         wait(0.1f);
+    //}
 
-    }
 }