xx

Dependencies:   Servo mbed pixy

Fork of PES1 by Gruppe 3

Committer:
itslinear
Date:
Tue Apr 11 14:53:18 2017 +0000
Revision:
6:4af735d26b7a
Parent:
4:fdcf3b5009c6
Child:
8:6d9cd5ad332d
new

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;
itslinear 6:4af735d26b7a 44 }
itslinear 0:306a2438de17 45
itslinear 1:4e84271a70c6 46 if(sensors[0].read() < x && sensors[5] > x) { // sensor vorne, roboter dreht nach links
itslinear 1:4e84271a70c6 47 offsetDir = -0.05;
itslinear 1:4e84271a70c6 48 offsetLin = 0;
itslinear 1:4e84271a70c6 49 }
itslinear 6:4af735d26b7a 50
itslinear 1:4e84271a70c6 51 if(sensors[1] < x) { // sensor rechts, roboter dreht nach links
itslinear 1:4e84271a70c6 52 offsetDir = -0.05;
itslinear 1:4e84271a70c6 53 offsetLin = 0;
itslinear 0:306a2438de17 54 }
itslinear 6:4af735d26b7a 55
itslinear 1:4e84271a70c6 56 if(sensors[5] < x && sensors[1]>(x+0.02f)) { // sensor links, roboter dreht nach rechts
itslinear 1:4e84271a70c6 57 offsetDir = 0.05;
itslinear 1:4e84271a70c6 58 offsetLin = 0;
itslinear 1:4e84271a70c6 59 }
itslinear 1:4e84271a70c6 60
itslinear 1:4e84271a70c6 61 *pwmL = 0.5f+offsetDir+offsetLin; // Setzt die Duty-Cycle auf 50%
itslinear 1:4e84271a70c6 62 *pwmR = 0.5f+offsetDir-offsetLin;
itslinear 1:4e84271a70c6 63
itslinear 3:24e098715b78 64 }
schneju2 2:953263712480 65
schneju2 2:953263712480 66
schneju2 2:953263712480 67
itslinear 1:4e84271a70c6 68
itslinear 3:24e098715b78 69 void Roboter::pickup ()
itslinear 3:24e098715b78 70 {
itslinear 3:24e098715b78 71
itslinear 0:306a2438de17 72
schneju2 2:953263712480 73
itslinear 3:24e098715b78 74 }