Gruppe 3
/
PES4
xx
Fork of PES1 by
main.cpp@7:edb4e0cfc0d1, 2017-04-11 (annotated)
- Committer:
- itslinear
- Date:
- Tue Apr 11 15:42:22 2017 +0000
- Revision:
- 7:edb4e0cfc0d1
- Parent:
- 6:4af735d26b7a
- Child:
- 8:6d9cd5ad332d
aktuell
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
itslinear | 0:306a2438de17 | 1 | #include <mbed.h> |
itslinear | 0:306a2438de17 | 2 | #include "Roboter.h" |
itslinear | 0:306a2438de17 | 3 | |
itslinear | 0:306a2438de17 | 4 | DigitalOut led(LED1); |
itslinear | 0:306a2438de17 | 5 | |
itslinear | 0:306a2438de17 | 6 | //Periphery for distance sensors |
itslinear | 1:4e84271a70c6 | 7 | AnalogIn distance(PB_1); |
itslinear | 0:306a2438de17 | 8 | DigitalOut enable(PC_1); |
itslinear | 0:306a2438de17 | 9 | DigitalOut bit0(PH_1); |
itslinear | 0:306a2438de17 | 10 | DigitalOut bit1(PC_2); |
itslinear | 0:306a2438de17 | 11 | DigitalOut bit2(PC_3); |
itslinear | 0:306a2438de17 | 12 | IRSensor sensors[6]; |
itslinear | 0:306a2438de17 | 13 | |
schneju2 | 2:953263712480 | 14 | // Periphery for servos |
itslinear | 4:fdcf3b5009c6 | 15 | Servo servos1(PB_7); |
itslinear | 4:fdcf3b5009c6 | 16 | Servo servos2(PA_6); |
itslinear | 4:fdcf3b5009c6 | 17 | |
itslinear | 6:4af735d26b7a | 18 | //Periphery for limit switch |
itslinear | 4:fdcf3b5009c6 | 19 | DigitalIn limitSwitch1(PA_10); |
itslinear | 6:4af735d26b7a | 20 | DigitalIn limitSwitch2(PB_13); |
schneju2 | 2:953263712480 | 21 | |
itslinear | 6:4af735d26b7a | 22 | //Periphery for Switch ON/OFF |
schneju2 | 5:f48b2609c328 | 23 | |
itslinear | 7:edb4e0cfc0d1 | 24 | DigitalIn switchOnOff(USER_BUTTON); |
schneju2 | 5:f48b2609c328 | 25 | |
itslinear | 0:306a2438de17 | 26 | //motor stuff |
itslinear | 0:306a2438de17 | 27 | DigitalOut enableMotorDriver(PB_2); |
itslinear | 3:24e098715b78 | 28 | PwmOut pwmL( PA_8 ); |
itslinear | 3:24e098715b78 | 29 | PwmOut pwmR( PA_9 ); |
itslinear | 0:306a2438de17 | 30 | |
itslinear | 0:306a2438de17 | 31 | //indicator leds arround robot |
itslinear | 0:306a2438de17 | 32 | DigitalOut leds[] = { PC_8, PC_6, PB_12, PA_7, PC_0, PC_9 }; |
itslinear | 0:306a2438de17 | 33 | |
itslinear | 4:fdcf3b5009c6 | 34 | Roboter roboter1(&distance, &bit0, &bit1, &bit2, &pwmL, &pwmR, &servos1,&servos2, &limitSwitch1, &limitSwitch2); |
itslinear | 0:306a2438de17 | 35 | |
itslinear | 1:4e84271a70c6 | 36 | int main() |
itslinear | 1:4e84271a70c6 | 37 | { |
itslinear | 6:4af735d26b7a | 38 | enable = 1; // Sensoren einschalten |
itslinear | 6:4af735d26b7a | 39 | enableMotorDriver = 1; // Schaltet die Motoren ein |
itslinear | 7:edb4e0cfc0d1 | 40 | pwmL.period(0.00005f); // Setzt die Periode auf 50 μs |
itslinear | 7:edb4e0cfc0d1 | 41 | pwmR.period(0.00005f); |
itslinear | 6:4af735d26b7a | 42 | |
itslinear | 7:edb4e0cfc0d1 | 43 | int state = 1; // Diese Variable gibt an in welchem State man sich befindet |
itslinear | 3:24e098715b78 | 44 | |
itslinear | 7:edb4e0cfc0d1 | 45 | /*if ( kamera() == 1) { |
itslinear | 6:4af735d26b7a | 46 | state = 4; |
itslinear | 7:edb4e0cfc0d1 | 47 | } // Die Kamera erkennt ein grünen Klotz*/ |
itslinear | 6:4af735d26b7a | 48 | while(1) { |
itslinear | 6:4af735d26b7a | 49 | |
itslinear | 6:4af735d26b7a | 50 | switch(state) { |
itslinear | 6:4af735d26b7a | 51 | |
itslinear | 6:4af735d26b7a | 52 | case 1: // Roboter Anschalten mit Knopf |
itslinear | 6:4af735d26b7a | 53 | |
itslinear | 6:4af735d26b7a | 54 | if (switchOnOff == 1) { |
itslinear | 6:4af735d26b7a | 55 | state = 2; |
itslinear | 6:4af735d26b7a | 56 | } |
itslinear | 7:edb4e0cfc0d1 | 57 | |
itslinear | 6:4af735d26b7a | 58 | break; |
itslinear | 6:4af735d26b7a | 59 | |
itslinear | 6:4af735d26b7a | 60 | case 2: |
itslinear | 6:4af735d26b7a | 61 | roboter1.bandeAusweichen(); |
itslinear | 6:4af735d26b7a | 62 | static int time1 = 0; |
itslinear | 6:4af735d26b7a | 63 | if(time1 < 10) { // Im Kreis drehen für 1s |
itslinear | 6:4af735d26b7a | 64 | pwmL = 0.4f; |
itslinear | 6:4af735d26b7a | 65 | pwmR = 0.4f; |
itslinear | 6:4af735d26b7a | 66 | time1 ++; |
itslinear | 6:4af735d26b7a | 67 | } else { |
itslinear | 6:4af735d26b7a | 68 | time1 = 0; |
itslinear | 6:4af735d26b7a | 69 | pwmL = 0.5f; |
itslinear | 6:4af735d26b7a | 70 | pwmR = 0.5f; |
itslinear | 6:4af735d26b7a | 71 | state = 3; |
itslinear | 6:4af735d26b7a | 72 | } |
itslinear | 6:4af735d26b7a | 73 | break; |
itslinear | 6:4af735d26b7a | 74 | |
itslinear | 3:24e098715b78 | 75 | |
itslinear | 6:4af735d26b7a | 76 | case 3: |
itslinear | 6:4af735d26b7a | 77 | roboter1.bandeAusweichen(); |
itslinear | 6:4af735d26b7a | 78 | static int time2 = 0; |
itslinear | 6:4af735d26b7a | 79 | if(time2 < 10) { // gerade aus fahren |
itslinear | 6:4af735d26b7a | 80 | pwmL = 0.6f; |
itslinear | 6:4af735d26b7a | 81 | pwmR = 0.4f; |
itslinear | 6:4af735d26b7a | 82 | time2 ++; |
itslinear | 6:4af735d26b7a | 83 | } else { |
itslinear | 6:4af735d26b7a | 84 | time2 = 0; |
itslinear | 6:4af735d26b7a | 85 | pwmL = 0.5f; |
itslinear | 6:4af735d26b7a | 86 | pwmR = 0.5f; |
itslinear | 6:4af735d26b7a | 87 | state = 2; |
itslinear | 6:4af735d26b7a | 88 | } |
itslinear | 6:4af735d26b7a | 89 | break; |
itslinear | 6:4af735d26b7a | 90 | |
itslinear | 6:4af735d26b7a | 91 | |
itslinear | 6:4af735d26b7a | 92 | case 4: // Roboter erkennt gründer Klotz, Klotz wird angefahren |
itslinear | 3:24e098715b78 | 93 | |
itslinear | 7:edb4e0cfc0d1 | 94 | |
itslinear | 6:4af735d26b7a | 95 | break; |
itslinear | 6:4af735d26b7a | 96 | |
itslinear | 6:4af735d26b7a | 97 | case 5: // Aufnehmen des Klotzes |
itslinear | 6:4af735d26b7a | 98 | |
itslinear | 6:4af735d26b7a | 99 | |
itslinear | 7:edb4e0cfc0d1 | 100 | |
itslinear | 6:4af735d26b7a | 101 | break; |
itslinear | 6:4af735d26b7a | 102 | |
itslinear | 7:edb4e0cfc0d1 | 103 | |
itslinear | 6:4af735d26b7a | 104 | } |
itslinear | 6:4af735d26b7a | 105 | |
itslinear | 6:4af735d26b7a | 106 | wait(0.1f); |
itslinear | 6:4af735d26b7a | 107 | |
itslinear | 6:4af735d26b7a | 108 | } |
schneju2 | 5:f48b2609c328 | 109 | |
schneju2 | 5:f48b2609c328 | 110 | } |
itslinear | 1:4e84271a70c6 | 111 |