![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
xx
Fork of PES1 by
main.cpp@5:f48b2609c328, 2017-04-11 (annotated)
- Committer:
- schneju2
- Date:
- Tue Apr 11 14:43:29 2017 +0000
- Revision:
- 5:f48b2609c328
- Parent:
- 4:fdcf3b5009c6
- Child:
- 6:4af735d26b7a
Main
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 | 4:fdcf3b5009c6 | 18 | //Periphery for limit switch |
itslinear | 4:fdcf3b5009c6 | 19 | DigitalIn limitSwitch1(PA_10); |
itslinear | 4:fdcf3b5009c6 | 20 | DigitalIn limitSwitch2(PB_13); |
schneju2 | 2:953263712480 | 21 | |
schneju2 | 5:f48b2609c328 | 22 | //Periphery for Swich ON/OFF |
schneju2 | 5:f48b2609c328 | 23 | |
schneju2 | 5:f48b2609c328 | 24 | DigitalIn swichOnOFF (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 | { |
schneju2 | 5:f48b2609c328 | 38 | enable = 1; // Sensoren einschalten |
schneju2 | 5:f48b2609c328 | 39 | enableMotorDriver = 1; // Schaltet die Motoren ein |
schneju2 | 5:f48b2609c328 | 40 | pwmL->period(0.00005f); // Setzt die Periode auf 50 μs |
schneju2 | 5:f48b2609c328 | 41 | pwmR->period(0.00005f); |
schneju2 | 5:f48b2609c328 | 42 | |
schneju2 | 5:f48b2609c328 | 43 | int state = 0; // Diese Variable gibt an in welchem State man sich befindet |
itslinear | 3:24e098715b78 | 44 | |
schneju2 | 5:f48b2609c328 | 45 | if ( kamera() == 1){ state = 4;) // Die Kamera erkennt ein grünen Klotz |
schneju2 | 5:f48b2609c328 | 46 | while(1) { |
itslinear | 3:24e098715b78 | 47 | |
schneju2 | 5:f48b2609c328 | 48 | swich(state){ |
schneju2 | 5:f48b2609c328 | 49 | |
schneju2 | 5:f48b2609c328 | 50 | case 1: // Roboter Anschalten mit Knopf |
schneju2 | 5:f48b2609c328 | 51 | |
schneju2 | 5:f48b2609c328 | 52 | if (swichOnOff == 1){ |
schneju2 | 5:f48b2609c328 | 53 | state = 2;} |
schneju2 | 5:f48b2609c328 | 54 | if (swichOnOff ==0){ |
schneju2 | 5:f48b2609c328 | 55 | state =1;) |
schneju2 | 5:f48b2609c328 | 56 | |
schneju2 | 5:f48b2609c328 | 57 | break; |
schneju2 | 5:f48b2609c328 | 58 | |
schneju2 | 5:f48b2609c328 | 59 | case 2: // Im Kreis drehen |
schneju2 | 5:f48b2609c328 | 60 | |
schneju2 | 5:f48b2609c328 | 61 | .... |
schneju2 | 5:f48b2609c328 | 62 | break; |
schneju2 | 5:f48b2609c328 | 63 | |
schneju2 | 5:f48b2609c328 | 64 | case 3: // gerade aus fahren |
schneju2 | 5:f48b2609c328 | 65 | |
schneju2 | 5:f48b2609c328 | 66 | .... |
schneju2 | 5:f48b2609c328 | 67 | break; |
schneju2 | 5:f48b2609c328 | 68 | |
schneju2 | 5:f48b2609c328 | 69 | case 4: // Roboter erkennt gründer Klotz, Klotz wird angefahren |
schneju2 | 5:f48b2609c328 | 70 | |
schneju2 | 5:f48b2609c328 | 71 | ... |
schneju2 | 5:f48b2609c328 | 72 | break; |
schneju2 | 5:f48b2609c328 | 73 | |
schneju2 | 5:f48b2609c328 | 74 | case 5: // Aufnehmen des Klotzes |
schneju2 | 5:f48b2609c328 | 75 | |
schneju2 | 5:f48b2609c328 | 76 | |
schneju2 | 5:f48b2609c328 | 77 | ..... |
schneju2 | 5:f48b2609c328 | 78 | break; |
schneju2 | 5:f48b2609c328 | 79 | |
schneju2 | 5:f48b2609c328 | 80 | |
schneju2 | 5:f48b2609c328 | 81 | default |
schneju2 | 5:f48b2609c328 | 82 | |
schneju2 | 5:f48b2609c328 | 83 | ... break ; } |
itslinear | 3:24e098715b78 | 84 | |
itslinear | 1:4e84271a70c6 | 85 | wait(0.1f); |
schneju2 | 5:f48b2609c328 | 86 | |
schneju2 | 5:f48b2609c328 | 87 | } |
itslinear | 1:4e84271a70c6 | 88 | |
itslinear | 1:4e84271a70c6 | 89 | } |
schneju2 | 2:953263712480 | 90 |