![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
hallo
Fork of PES1 by
main.cpp@19:adae367247d4, 2017-05-12 (annotated)
- Committer:
- itslinear
- Date:
- Fri May 12 12:25:34 2017 +0000
- Revision:
- 19:adae367247d4
- Parent:
- 18:3ee1b02ed3aa
- Child:
- 20:a90e5b54bf7b
hallo balz
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 | 18:3ee1b02ed3aa | 4 | |
itslinear | 18:3ee1b02ed3aa | 5 | //Periphery for Encoder |
itslinear | 18:3ee1b02ed3aa | 6 | EncoderCounter counterLeft(PB_6, PB_7); |
itslinear | 18:3ee1b02ed3aa | 7 | EncoderCounter counterRight(PA_6, PC_7); |
itslinear | 18:3ee1b02ed3aa | 8 | |
itslinear | 0:306a2438de17 | 9 | |
itslinear | 0:306a2438de17 | 10 | //Periphery for distance sensors |
itslinear | 1:4e84271a70c6 | 11 | AnalogIn distance(PB_1); |
itslinear | 0:306a2438de17 | 12 | DigitalOut enable(PC_1); |
itslinear | 0:306a2438de17 | 13 | DigitalOut bit0(PH_1); |
itslinear | 0:306a2438de17 | 14 | DigitalOut bit1(PC_2); |
itslinear | 0:306a2438de17 | 15 | DigitalOut bit2(PC_3); |
itslinear | 0:306a2438de17 | 16 | IRSensor sensors[6]; |
itslinear | 0:306a2438de17 | 17 | |
schneju2 | 2:953263712480 | 18 | // Periphery for servos |
itslinear | 18:3ee1b02ed3aa | 19 | Servo servo1(PB_13); //Greiferservo Anschluss D2 |
itslinear | 18:3ee1b02ed3aa | 20 | Servo servo2(PA_10); //Armservo Anschluss D0 |
itslinear | 4:fdcf3b5009c6 | 21 | |
itslinear | 6:4af735d26b7a | 22 | //Periphery for Switch ON/OFF |
itslinear | 7:edb4e0cfc0d1 | 23 | DigitalIn switchOnOff(USER_BUTTON); |
schneju2 | 5:f48b2609c328 | 24 | |
itslinear | 0:306a2438de17 | 25 | //motor stuff |
itslinear | 0:306a2438de17 | 26 | DigitalOut enableMotorDriver(PB_2); |
itslinear | 3:24e098715b78 | 27 | PwmOut pwmL( PA_8 ); |
itslinear | 3:24e098715b78 | 28 | PwmOut pwmR( PA_9 ); |
itslinear | 0:306a2438de17 | 29 | |
itslinear | 0:306a2438de17 | 30 | //indicator leds arround robot |
itslinear | 0:306a2438de17 | 31 | DigitalOut leds[] = { PC_8, PC_6, PB_12, PA_7, PC_0, PC_9 }; |
itslinear | 0:306a2438de17 | 32 | |
itslinear | 18:3ee1b02ed3aa | 33 | // Erstellen eines Roboterobjekts |
itslinear | 18:3ee1b02ed3aa | 34 | Roboter roboter1(&distance, &bit0, &bit1, &bit2, &pwmL, &pwmR, &servo1, &servo2, &counterLeft, &counterRight, &enableMotorDriver); |
itslinear | 0:306a2438de17 | 35 | |
itslinear | 1:4e84271a70c6 | 36 | int main() |
itslinear | 1:4e84271a70c6 | 37 | { |
itslinear | 18:3ee1b02ed3aa | 38 | int state = 0; // Diese Variable gibt an in welchem State man sich befindet |
itslinear | 18:3ee1b02ed3aa | 39 | int tempState = 2; // Wird benötig um zwischen Kameraauswertung und fahren zu wechseln |
itslinear | 18:3ee1b02ed3aa | 40 | enable = 1; // Sensoren einschalten |
itslinear | 18:3ee1b02ed3aa | 41 | servo1.Enable(1500,20000); |
itslinear | 18:3ee1b02ed3aa | 42 | servo2.Enable(700,20000); |
itslinear | 19:adae367247d4 | 43 | wait(1); |
itslinear | 18:3ee1b02ed3aa | 44 | float camValue; |
itslinear | 9:d9e46f9c9e40 | 45 | |
itslinear | 9:d9e46f9c9e40 | 46 | while(1) { |
itslinear | 9:d9e46f9c9e40 | 47 | |
itslinear | 18:3ee1b02ed3aa | 48 | //printf("%d\n", state); |
itslinear | 6:4af735d26b7a | 49 | |
itslinear | 6:4af735d26b7a | 50 | switch(state) { |
itslinear | 6:4af735d26b7a | 51 | |
itslinear | 12:b9faf8637183 | 52 | case 0: // Roboter Anschalten mit Knopf |
Shukle | 16:0a1703438e8b | 53 | printf("0"); |
itslinear | 6:4af735d26b7a | 54 | |
itslinear | 19:adae367247d4 | 55 | if (switchOnOff == 0) { // Bei Betätigung des Userbuttons wird das Programm gestartet |
itslinear | 12:b9faf8637183 | 56 | state = 1; |
itslinear | 9:d9e46f9c9e40 | 57 | } |
itslinear | 7:edb4e0cfc0d1 | 58 | |
itslinear | 9:d9e46f9c9e40 | 59 | break; |
itslinear | 6:4af735d26b7a | 60 | |
itslinear | 12:b9faf8637183 | 61 | case 1: |
itslinear | 18:3ee1b02ed3aa | 62 | //printf("1"); |
itslinear | 19:adae367247d4 | 63 | camValue = readCamera(state); |
itslinear | 18:3ee1b02ed3aa | 64 | state = roboter1.stateAuswahl(camValue, tempState); // Case-Auswahl aufgrund von der Kamera |
Shukle | 16:0a1703438e8b | 65 | break; |
itslinear | 12:b9faf8637183 | 66 | |
itslinear | 9:d9e46f9c9e40 | 67 | case 2: |
itslinear | 18:3ee1b02ed3aa | 68 | //printf("2"); |
itslinear | 18:3ee1b02ed3aa | 69 | state = roboter1.kreisFahren(); // Im Kreis fahren |
itslinear | 18:3ee1b02ed3aa | 70 | tempState = 2; |
itslinear | 9:d9e46f9c9e40 | 71 | break; |
itslinear | 6:4af735d26b7a | 72 | |
itslinear | 3:24e098715b78 | 73 | |
itslinear | 9:d9e46f9c9e40 | 74 | case 3: |
itslinear | 18:3ee1b02ed3aa | 75 | //printf("3"); |
itslinear | 19:adae367247d4 | 76 | roboter1.ausweichen1(); // Hindernissen ausweichen |
itslinear | 18:3ee1b02ed3aa | 77 | state = roboter1.geradeFahren(); // Gerade Fahren |
itslinear | 18:3ee1b02ed3aa | 78 | tempState = 3; |
itslinear | 9:d9e46f9c9e40 | 79 | break; |
itslinear | 6:4af735d26b7a | 80 | |
itslinear | 6:4af735d26b7a | 81 | |
itslinear | 18:3ee1b02ed3aa | 82 | case 4: |
itslinear | 18:3ee1b02ed3aa | 83 | //printf("4"); |
itslinear | 19:adae367247d4 | 84 | roboter1.anfahren(camValue); // Roboter erkennt grünen Klotz, Klotz wird angefahren |
itslinear | 19:adae367247d4 | 85 | state = roboter1.readSensors(); |
itslinear | 9:d9e46f9c9e40 | 86 | break; |
itslinear | 9:d9e46f9c9e40 | 87 | |
itslinear | 18:3ee1b02ed3aa | 88 | case 5: |
itslinear | 18:3ee1b02ed3aa | 89 | //printf("5"); |
itslinear | 18:3ee1b02ed3aa | 90 | state = roboter1.pickup(); // Aufnehmen des Klotzes |
itslinear | 9:d9e46f9c9e40 | 91 | break; |
itslinear | 9:d9e46f9c9e40 | 92 | |
itslinear | 19:adae367247d4 | 93 | case 6: |
itslinear | 19:adae367247d4 | 94 | //printf("6"); |
itslinear | 19:adae367247d4 | 95 | state = roboter1.ausweichen2(); // Hindernissen ausweichen während Klotz angefahren wird |
itslinear | 19:adae367247d4 | 96 | |
itslinear | 19:adae367247d4 | 97 | case 7: |
itslinear | 19:adae367247d4 | 98 | //printf("7"); |
itslinear | 19:adae367247d4 | 99 | //state = roboter1.back(); |
itslinear | 9:d9e46f9c9e40 | 100 | default: |
itslinear | 9:d9e46f9c9e40 | 101 | break; |
itslinear | 9:d9e46f9c9e40 | 102 | |
itslinear | 6:4af735d26b7a | 103 | } |
itslinear | 19:adae367247d4 | 104 | |
itslinear | 19:adae367247d4 | 105 | wait(0.0001f); |
schneju2 | 5:f48b2609c328 | 106 | } |
itslinear | 9:d9e46f9c9e40 | 107 | } |