hallo

Dependencies:   Servo mbed pixy

Fork of PES1 by Gruppe 3

Committer:
schneju2
Date:
Tue Apr 18 12:09:46 2017 +0000
Revision:
8:6d9cd5ad332d
Parent:
6:4af735d26b7a
Child:
9:d9e46f9c9e40
neu

Who changed what in which revision?

UserRevisionLine numberNew contents of line
itslinear 0:306a2438de17 1 #include "Roboter.h"
itslinear 0:306a2438de17 2
itslinear 0:306a2438de17 3
itslinear 4:fdcf3b5009c6 4 Roboter::Roboter(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, PwmOut* pwmL, PwmOut* pwmR, Servo* s1, Servo* s2,DigitalIn* switch1, DigitalIn* switch2)
itslinear 4:fdcf3b5009c6 5
itslinear 1:4e84271a70c6 6 {
itslinear 0:306a2438de17 7
itslinear 1:4e84271a70c6 8 sensors[0].init( distance, bit0, bit1, bit2, 0);
itslinear 1:4e84271a70c6 9 sensors[1].init( distance, bit0, bit1, bit2, 1);
itslinear 1:4e84271a70c6 10 sensors[2].init( distance, bit0, bit1, bit2, 2);
itslinear 1:4e84271a70c6 11 sensors[3].init( distance, bit0, bit1, bit2, 3);
itslinear 1:4e84271a70c6 12 sensors[4].init( distance, bit0, bit1, bit2, 4);
itslinear 1:4e84271a70c6 13 sensors[5].init( distance, bit0, bit1, bit2, 5);
itslinear 0:306a2438de17 14
itslinear 1:4e84271a70c6 15 this->pwmR = pwmR;
itslinear 1:4e84271a70c6 16 this->pwmL = pwmL;
itslinear 4:fdcf3b5009c6 17 this->s1 = s1;
itslinear 4:fdcf3b5009c6 18 this->s2 = s2;
itslinear 4:fdcf3b5009c6 19 this->switch1 = switch1;
itslinear 4:fdcf3b5009c6 20 this->switch2 = switch2;
itslinear 4:fdcf3b5009c6 21
itslinear 1:4e84271a70c6 22
itslinear 1:4e84271a70c6 23 }
itslinear 1:4e84271a70c6 24
itslinear 1:4e84271a70c6 25 float Roboter::readSensor1()
itslinear 0:306a2438de17 26 {
itslinear 1:4e84271a70c6 27 return sensors[0].read();
itslinear 1:4e84271a70c6 28
itslinear 0:306a2438de17 29 }
itslinear 0:306a2438de17 30
itslinear 1:4e84271a70c6 31
itslinear 1:4e84271a70c6 32 void Roboter::bandeAusweichen()
itslinear 0:306a2438de17 33 {
itslinear 1:4e84271a70c6 34 float offsetDir;
itslinear 1:4e84271a70c6 35 float offsetLin;
itslinear 1:4e84271a70c6 36
itslinear 1:4e84271a70c6 37 float x=0.13f; // Distanz ab welcher sensoren reagieren sollen
itslinear 1:4e84271a70c6 38
itslinear 6:4af735d26b7a 39 offsetDir = 0;
itslinear 6:4af735d26b7a 40 offsetLin = 0;
itslinear 1:4e84271a70c6 41
itslinear 6:4af735d26b7a 42 if(sensors[0] < x && sensors[1] < x && sensors[5] < x) { // alle sensoren aktiv, roboter fährt nach hinten
itslinear 6:4af735d26b7a 43 offsetLin = -0.1f;
schneju2 8:6d9cd5ad332d 44 printf("Alle sensoren aktiv");
itslinear 6:4af735d26b7a 45 }
itslinear 0:306a2438de17 46
itslinear 1:4e84271a70c6 47 if(sensors[0].read() < x && sensors[5] > x) { // sensor vorne, roboter dreht nach links
itslinear 1:4e84271a70c6 48 offsetDir = -0.05;
itslinear 1:4e84271a70c6 49 offsetLin = 0;
schneju2 8:6d9cd5ad332d 50 printf(" sensoren vorne");
itslinear 1:4e84271a70c6 51 }
itslinear 6:4af735d26b7a 52
itslinear 1:4e84271a70c6 53 if(sensors[1] < x) { // sensor rechts, roboter dreht nach links
itslinear 1:4e84271a70c6 54 offsetDir = -0.05;
itslinear 1:4e84271a70c6 55 offsetLin = 0;
schneju2 8:6d9cd5ad332d 56 printf("sensor rechts");
itslinear 0:306a2438de17 57 }
itslinear 6:4af735d26b7a 58
itslinear 1:4e84271a70c6 59 if(sensors[5] < x && sensors[1]>(x+0.02f)) { // sensor links, roboter dreht nach rechts
itslinear 1:4e84271a70c6 60 offsetDir = 0.05;
itslinear 1:4e84271a70c6 61 offsetLin = 0;
schneju2 8:6d9cd5ad332d 62 printf("sensor links");
itslinear 1:4e84271a70c6 63 }
itslinear 1:4e84271a70c6 64
itslinear 1:4e84271a70c6 65 *pwmL = 0.5f+offsetDir+offsetLin; // Setzt die Duty-Cycle auf 50%
itslinear 1:4e84271a70c6 66 *pwmR = 0.5f+offsetDir-offsetLin;
itslinear 1:4e84271a70c6 67
itslinear 3:24e098715b78 68 }
schneju2 2:953263712480 69
schneju2 2:953263712480 70
schneju2 2:953263712480 71
itslinear 1:4e84271a70c6 72
itslinear 3:24e098715b78 73 void Roboter::pickup ()
itslinear 3:24e098715b78 74 {
itslinear 3:24e098715b78 75
itslinear 0:306a2438de17 76
schneju2 2:953263712480 77
itslinear 3:24e098715b78 78 }