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 04 11:55:54 2017 +0000
Parent:
0:306a2438de17
Child:
2:953263712480
Commit message:
fds

Changed in this revision

Motoren.cpp Show diff for this revision Revisions of this file
Motoren.h 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/Motoren.cpp	Tue Mar 21 12:42:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-#include "Motoren.h"
\ No newline at end of file
--- a/Motoren.h	Tue Mar 21 12:42:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#ifndef MOTOREN_H
-#define MOTOREN_H
-
-#include <mbed.h>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#endif 
\ No newline at end of file
--- a/Roboter.cpp	Tue Mar 21 12:42:01 2017 +0000
+++ b/Roboter.cpp	Tue Apr 04 11:55:54 2017 +0000
@@ -1,50 +1,60 @@
-
 #include "Roboter.h"
 
 
+Roboter::Roboter(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, PwmOut* pwmL, PwmOut* pwmR)
+{
 
-//timer object for ledshow and distance sensor
-Ticker t1;
+    sensors[0].init( distance, bit0, bit1, bit2, 0);
+    sensors[1].init( distance, bit0, bit1, bit2, 1);
+    sensors[2].init( distance, bit0, bit1, bit2, 2);
+    sensors[3].init( distance, bit0, bit1, bit2, 3);
+    sensors[4].init( distance, bit0, bit1, bit2, 4);
+    sensors[5].init( distance, bit0, bit1, bit2, 5);
 
-//lights up the led according to the sensor signal
-void ledDistance()
+    this->pwmR = pwmR;
+    this->pwmL = pwmL;
+
+    pwmL->period(0.00005f); // Setzt die Periode auf 50 μs
+    pwmR->period(0.00005f);
+
+}
+
+float Roboter::readSensor1()
 {
-    for( int ii = 0; ii<6; ++ii)
-        sensors[ii]< 0.1f ? leds[ii] = 1 : leds[ii] = 0;
+    return sensors[0].read();
+
 }
 
-//blinks at startup and starts ledDistance task
-void ledShow()
+
+void Roboter::bandeAusweichen()
 {
-    static int timer = 0;
-    for( int ii = 0; ii<6; ++ii)
-        leds[ii] = !leds[ii];
+    float offsetDir;
+    float offsetLin;
+
+    float x=0.13f;       // Distanz ab welcher sensoren reagieren sollen
+
+
+    offsetDir = 0;
+    offsetLin = 0.1;
+
 
-    //quit ticker and start led distance show
-    if( ++timer > 10) {
-        t1.detach();
-        t1.attach( &ledDistance, 0.01f );
+    if(sensors[0].read() < x && sensors[5] > x) { // sensor vorne, roboter dreht nach links
+        offsetDir = -0.05;
+        offsetLin = 0;
+    }
+    if(sensors[1] < x) {     // sensor rechts, roboter dreht nach links
+        offsetDir = -0.05;
+        offsetLin = 0;
     }
+    if(sensors[5] < x && sensors[1]>(x+0.02f)) {     // sensor links, roboter dreht nach rechts
+        offsetDir = 0.05;
+        offsetLin = 0;
+    }
+
+    *pwmL = 0.5f+offsetDir+offsetLin; // Setzt die Duty-Cycle auf 50%
+    *pwmR = 0.5f+offsetDir-offsetLin;
+
+    wait(0.1);
+
 }
 
-int IRSensor()
-{
-    pwmL.period(0.00005f); // Setzt die Periode auf 50 μs
-    pwmR.period(0.00005f);
-
-    pwmL = 0.5f; // Setzt die Duty-Cycle auf 50%
-    pwmR = 0.5f;
-    enableMotorDriver = 0;
-
-    t1.attach( &ledShow, 0.05f );
-
-    //init distance sensors
-    for( int ii = 0; ii<6; ++ii)
-        sensors[ii].init(&distance, &bit0, &bit1, &bit2, ii);
-
-    enable = 1;
-
-    while(1) {
-        wait( 0.2f );
-    }
-}
--- a/Roboter.h	Tue Mar 21 12:42:01 2017 +0000
+++ b/Roboter.h	Tue Apr 04 11:55:54 2017 +0000
@@ -2,39 +2,29 @@
 #define ROBOTER_H
 
 #include <mbed.h>
-#include "Motoren.h"
 #include "IRSensor.h"
-#include "Kamera.h"
 
-class Roboter : class IRSensor
+class Roboter
 {
-    
+
 public:
 
-    Roboter : IRSensor(distance,bit0,bit1,bit2,number)
-    
+    Roboter(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2,   PwmOut * pwmL, PwmOut* pwmR);
+
+    void bandeAusweichen();
+    float readSensor1();
 
+private:
+    IRSensor sensors[6];
+
+    PwmOut* pwmL;
+    PwmOut* pwmR;
 
 
 
 
-
-
-
-
-
-
-
+};
 
 
 
-
-
-
-
-
-
-
-
-
-#endif 
\ No newline at end of file
+#endif
\ No newline at end of file
--- a/main.cpp	Tue Mar 21 12:42:01 2017 +0000
+++ b/main.cpp	Tue Apr 04 11:55:54 2017 +0000
@@ -4,27 +4,35 @@
 DigitalOut led(LED1);
 
 //Periphery for distance sensors
-AnalogIn distance(PB_1); 
+AnalogIn distance(PB_1);
 DigitalOut enable(PC_1);
 DigitalOut bit0(PH_1);
 DigitalOut bit1(PC_2);
 DigitalOut bit2(PC_3);
 IRSensor sensors[6];
 
+PwmOut pwmL( PA_8 );
+PwmOut pwmR( PA_9 );
+
 //motor stuff
 DigitalOut enableMotorDriver(PB_2);
-PwmOut pwmL(PA_8);
-PwmOut pwmR(PA_9);
 
 //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);
 
-int main(){
-    
-    
-    
-    
-    
-return 0; 
-}
\ No newline at end of file
+int main()
+{
+    enable = 1;
+    enableMotorDriver = 1;
+
+    while(1) {
+
+        roboter1.bandeAusweichen();
+       // roboter.readSensor1();
+        
+        wait(0.1f);
+
+    }
+}