![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
für holdor
Fork of PES by
Roboter.cpp@17:caf5ae550f2e, 2017-04-25 (annotated)
- Committer:
- Shukle
- Date:
- Tue Apr 25 12:26:04 2017 +0000
- Revision:
- 17:caf5ae550f2e
- Parent:
- 9:d9e46f9c9e40
- Child:
- 20:c961dc550882
endschalter entfernt;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
itslinear | 0:306a2438de17 | 1 | #include "Roboter.h" |
itslinear | 0:306a2438de17 | 2 | |
itslinear | 0:306a2438de17 | 3 | |
Shukle | 17:caf5ae550f2e | 4 | Roboter::Roboter(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, PwmOut* pwmL, PwmOut* pwmR, Servo* s1, Servo* s2) |
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 | |
itslinear | 1:4e84271a70c6 | 20 | |
itslinear | 1:4e84271a70c6 | 21 | } |
itslinear | 1:4e84271a70c6 | 22 | |
itslinear | 1:4e84271a70c6 | 23 | float Roboter::readSensor1() |
itslinear | 0:306a2438de17 | 24 | { |
itslinear | 1:4e84271a70c6 | 25 | return sensors[0].read(); |
itslinear | 1:4e84271a70c6 | 26 | |
itslinear | 0:306a2438de17 | 27 | } |
itslinear | 0:306a2438de17 | 28 | |
itslinear | 1:4e84271a70c6 | 29 | |
itslinear | 1:4e84271a70c6 | 30 | void Roboter::bandeAusweichen() |
itslinear | 0:306a2438de17 | 31 | { |
itslinear | 1:4e84271a70c6 | 32 | float offsetDir; |
itslinear | 1:4e84271a70c6 | 33 | float offsetLin; |
itslinear | 1:4e84271a70c6 | 34 | |
itslinear | 1:4e84271a70c6 | 35 | float x=0.13f; // Distanz ab welcher sensoren reagieren sollen |
itslinear | 1:4e84271a70c6 | 36 | |
itslinear | 6:4af735d26b7a | 37 | offsetDir = 0; |
itslinear | 6:4af735d26b7a | 38 | offsetLin = 0; |
itslinear | 1:4e84271a70c6 | 39 | |
itslinear | 9:d9e46f9c9e40 | 40 | while(sensors[0] < x && sensors[1] < x && sensors[5] < x) { // alle sensoren aktiv, roboter fährt nach hinten |
itslinear | 9:d9e46f9c9e40 | 41 | offsetLin = 0.1f; |
itslinear | 9:d9e46f9c9e40 | 42 | *pwmL = 0.5f+offsetDir-offsetLin; // Setzt die Duty-Cycle auf 50% |
itslinear | 9:d9e46f9c9e40 | 43 | *pwmR = 0.5f+offsetDir+offsetLin; |
itslinear | 9:d9e46f9c9e40 | 44 | |
itslinear | 9:d9e46f9c9e40 | 45 | } |
itslinear | 9:d9e46f9c9e40 | 46 | |
itslinear | 9:d9e46f9c9e40 | 47 | while(sensors[0].read() < x && sensors[5] > x) { // sensor vorne, roboter dreht nach links |
itslinear | 9:d9e46f9c9e40 | 48 | offsetDir = -0.05; |
itslinear | 9:d9e46f9c9e40 | 49 | *pwmL = 0.5f+offsetDir+offsetLin; // Setzt die Duty-Cycle auf 50% |
itslinear | 9:d9e46f9c9e40 | 50 | *pwmR = 0.5f+offsetDir-offsetLin; |
itslinear | 9:d9e46f9c9e40 | 51 | |
itslinear | 6:4af735d26b7a | 52 | } |
itslinear | 0:306a2438de17 | 53 | |
itslinear | 9:d9e46f9c9e40 | 54 | while(sensors[1] < x) { // sensor rechts, roboter dreht nach links |
itslinear | 1:4e84271a70c6 | 55 | offsetDir = -0.05; |
itslinear | 9:d9e46f9c9e40 | 56 | *pwmL = 0.5f+offsetDir+offsetLin; // Setzt die Duty-Cycle auf 50% |
itslinear | 9:d9e46f9c9e40 | 57 | *pwmR = 0.5f+offsetDir-offsetLin; |
itslinear | 9:d9e46f9c9e40 | 58 | |
itslinear | 1:4e84271a70c6 | 59 | } |
itslinear | 1:4e84271a70c6 | 60 | |
itslinear | 9:d9e46f9c9e40 | 61 | while(sensors[5] < x && sensors[1]>(x+0.02f)) { // sensor links, roboter dreht nach rechts |
itslinear | 9:d9e46f9c9e40 | 62 | offsetDir = 0.08; |
itslinear | 9:d9e46f9c9e40 | 63 | *pwmL = 0.5f+offsetDir+offsetLin; // Setzt die Duty-Cycle auf 50% |
itslinear | 9:d9e46f9c9e40 | 64 | *pwmR = 0.5f+offsetDir-offsetLin; |
itslinear | 9:d9e46f9c9e40 | 65 | |
itslinear | 9:d9e46f9c9e40 | 66 | } |
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 | } |