![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Roboter
Roboter.cpp@2:953263712480, 2017-04-04 (annotated)
- Committer:
- schneju2
- Date:
- Tue Apr 04 13:22:24 2017 +0000
- Revision:
- 2:953263712480
- Parent:
- 1:4e84271a70c6
- Child:
- 3:24e098715b78
mit servos
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 | |
schneju2 | 2:953263712480 | 4 | Roboter::Roboter(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, PwmOut* pwmL, PwmOut* pwmR, Servo* s1, Servo* s2) |
itslinear | 1:4e84271a70c6 | 5 | { |
itslinear | 0:306a2438de17 | 6 | |
itslinear | 1:4e84271a70c6 | 7 | sensors[0].init( distance, bit0, bit1, bit2, 0); |
itslinear | 1:4e84271a70c6 | 8 | sensors[1].init( distance, bit0, bit1, bit2, 1); |
itslinear | 1:4e84271a70c6 | 9 | sensors[2].init( distance, bit0, bit1, bit2, 2); |
itslinear | 1:4e84271a70c6 | 10 | sensors[3].init( distance, bit0, bit1, bit2, 3); |
itslinear | 1:4e84271a70c6 | 11 | sensors[4].init( distance, bit0, bit1, bit2, 4); |
itslinear | 1:4e84271a70c6 | 12 | sensors[5].init( distance, bit0, bit1, bit2, 5); |
itslinear | 0:306a2438de17 | 13 | |
itslinear | 1:4e84271a70c6 | 14 | this->pwmR = pwmR; |
itslinear | 1:4e84271a70c6 | 15 | this->pwmL = pwmL; |
itslinear | 1:4e84271a70c6 | 16 | |
itslinear | 1:4e84271a70c6 | 17 | pwmL->period(0.00005f); // Setzt die Periode auf 50 μs |
itslinear | 1:4e84271a70c6 | 18 | pwmR->period(0.00005f); |
itslinear | 1:4e84271a70c6 | 19 | |
itslinear | 1:4e84271a70c6 | 20 | } |
itslinear | 1:4e84271a70c6 | 21 | |
itslinear | 1:4e84271a70c6 | 22 | float Roboter::readSensor1() |
itslinear | 0:306a2438de17 | 23 | { |
itslinear | 1:4e84271a70c6 | 24 | return sensors[0].read(); |
itslinear | 1:4e84271a70c6 | 25 | |
itslinear | 0:306a2438de17 | 26 | } |
itslinear | 0:306a2438de17 | 27 | |
itslinear | 1:4e84271a70c6 | 28 | |
itslinear | 1:4e84271a70c6 | 29 | void Roboter::bandeAusweichen() |
itslinear | 0:306a2438de17 | 30 | { |
itslinear | 1:4e84271a70c6 | 31 | float offsetDir; |
itslinear | 1:4e84271a70c6 | 32 | float offsetLin; |
itslinear | 1:4e84271a70c6 | 33 | |
itslinear | 1:4e84271a70c6 | 34 | float x=0.13f; // Distanz ab welcher sensoren reagieren sollen |
itslinear | 1:4e84271a70c6 | 35 | |
itslinear | 1:4e84271a70c6 | 36 | |
itslinear | 1:4e84271a70c6 | 37 | offsetDir = 0; |
itslinear | 1:4e84271a70c6 | 38 | offsetLin = 0.1; |
itslinear | 1:4e84271a70c6 | 39 | |
itslinear | 0:306a2438de17 | 40 | |
itslinear | 1:4e84271a70c6 | 41 | if(sensors[0].read() < x && sensors[5] > x) { // sensor vorne, roboter dreht nach links |
itslinear | 1:4e84271a70c6 | 42 | offsetDir = -0.05; |
itslinear | 1:4e84271a70c6 | 43 | offsetLin = 0; |
itslinear | 1:4e84271a70c6 | 44 | } |
itslinear | 1:4e84271a70c6 | 45 | if(sensors[1] < x) { // sensor rechts, roboter dreht nach links |
itslinear | 1:4e84271a70c6 | 46 | offsetDir = -0.05; |
itslinear | 1:4e84271a70c6 | 47 | offsetLin = 0; |
itslinear | 0:306a2438de17 | 48 | } |
itslinear | 1:4e84271a70c6 | 49 | if(sensors[5] < x && sensors[1]>(x+0.02f)) { // sensor links, roboter dreht nach rechts |
itslinear | 1:4e84271a70c6 | 50 | offsetDir = 0.05; |
itslinear | 1:4e84271a70c6 | 51 | offsetLin = 0; |
itslinear | 1:4e84271a70c6 | 52 | } |
itslinear | 1:4e84271a70c6 | 53 | |
itslinear | 1:4e84271a70c6 | 54 | *pwmL = 0.5f+offsetDir+offsetLin; // Setzt die Duty-Cycle auf 50% |
itslinear | 1:4e84271a70c6 | 55 | *pwmR = 0.5f+offsetDir-offsetLin; |
itslinear | 1:4e84271a70c6 | 56 | |
schneju2 | 2:953263712480 | 57 | wait(0.1); |
schneju2 | 2:953263712480 | 58 | } |
schneju2 | 2:953263712480 | 59 | |
schneju2 | 2:953263712480 | 60 | |
schneju2 | 2:953263712480 | 61 | |
itslinear | 1:4e84271a70c6 | 62 | |
schneju2 | 2:953263712480 | 63 | void Roboter::pickup (){ |
schneju2 | 2:953263712480 | 64 | |
schneju2 | 2:953263712480 | 65 | |
schneju2 | 2:953263712480 | 66 | |
schneju2 | 2:953263712480 | 67 | |
schneju2 | 2:953263712480 | 68 | } |
itslinear | 0:306a2438de17 | 69 | |
schneju2 | 2:953263712480 | 70 |