Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PES1 by
main.cpp@21:69ee872b8ee9, 2017-05-16 (annotated)
- Committer:
- itslinear
- Date:
- Tue May 16 16:09:08 2017 +0000
- Revision:
- 21:69ee872b8ee9
- Parent:
- 20:a90e5b54bf7b
sieg
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 | 20:a90e5b54bf7b | 40 | int temp = 0; |
| itslinear | 18:3ee1b02ed3aa | 41 | enable = 1; // Sensoren einschalten |
| itslinear | 18:3ee1b02ed3aa | 42 | servo1.Enable(1500,20000); |
| itslinear | 18:3ee1b02ed3aa | 43 | servo2.Enable(700,20000); |
| itslinear | 19:adae367247d4 | 44 | wait(1); |
| itslinear | 18:3ee1b02ed3aa | 45 | float camValue; |
| itslinear | 9:d9e46f9c9e40 | 46 | |
| itslinear | 9:d9e46f9c9e40 | 47 | while(1) { |
| itslinear | 9:d9e46f9c9e40 | 48 | |
| itslinear | 18:3ee1b02ed3aa | 49 | //printf("%d\n", state); |
| itslinear | 6:4af735d26b7a | 50 | |
| itslinear | 6:4af735d26b7a | 51 | switch(state) { |
| itslinear | 6:4af735d26b7a | 52 | |
| itslinear | 12:b9faf8637183 | 53 | case 0: // Roboter Anschalten mit Knopf |
| Shukle | 16:0a1703438e8b | 54 | printf("0"); |
| itslinear | 6:4af735d26b7a | 55 | |
| itslinear | 19:adae367247d4 | 56 | if (switchOnOff == 0) { // Bei Betätigung des Userbuttons wird das Programm gestartet |
| itslinear | 12:b9faf8637183 | 57 | state = 1; |
| itslinear | 9:d9e46f9c9e40 | 58 | } |
| itslinear | 7:edb4e0cfc0d1 | 59 | |
| itslinear | 9:d9e46f9c9e40 | 60 | break; |
| itslinear | 6:4af735d26b7a | 61 | |
| itslinear | 12:b9faf8637183 | 62 | case 1: |
| itslinear | 18:3ee1b02ed3aa | 63 | //printf("1"); |
| itslinear | 19:adae367247d4 | 64 | camValue = readCamera(state); |
| itslinear | 20:a90e5b54bf7b | 65 | state = roboter1.stateAuswahl(camValue, tempState, temp); // Case-Auswahl aufgrund von der Kamera |
| Shukle | 16:0a1703438e8b | 66 | break; |
| itslinear | 12:b9faf8637183 | 67 | |
| itslinear | 9:d9e46f9c9e40 | 68 | case 2: |
| itslinear | 18:3ee1b02ed3aa | 69 | //printf("2"); |
| itslinear | 20:a90e5b54bf7b | 70 | tempState = 2; |
| itslinear | 20:a90e5b54bf7b | 71 | temp = 0; |
| itslinear | 18:3ee1b02ed3aa | 72 | state = roboter1.kreisFahren(); // Im Kreis fahren |
| itslinear | 9:d9e46f9c9e40 | 73 | break; |
| itslinear | 6:4af735d26b7a | 74 | |
| itslinear | 3:24e098715b78 | 75 | |
| itslinear | 9:d9e46f9c9e40 | 76 | case 3: |
| itslinear | 18:3ee1b02ed3aa | 77 | //printf("3"); |
| itslinear | 20:a90e5b54bf7b | 78 | tempState = 3; |
| itslinear | 20:a90e5b54bf7b | 79 | temp = 0; |
| itslinear | 19:adae367247d4 | 80 | roboter1.ausweichen1(); // Hindernissen ausweichen |
| itslinear | 18:3ee1b02ed3aa | 81 | state = roboter1.geradeFahren(); // Gerade Fahren |
| itslinear | 9:d9e46f9c9e40 | 82 | break; |
| itslinear | 6:4af735d26b7a | 83 | |
| itslinear | 6:4af735d26b7a | 84 | |
| itslinear | 18:3ee1b02ed3aa | 85 | case 4: |
| itslinear | 18:3ee1b02ed3aa | 86 | //printf("4"); |
| itslinear | 20:a90e5b54bf7b | 87 | tempState = 2; |
| itslinear | 21:69ee872b8ee9 | 88 | temp = 0; |
| itslinear | 19:adae367247d4 | 89 | roboter1.anfahren(camValue); // Roboter erkennt grünen Klotz, Klotz wird angefahren |
| itslinear | 19:adae367247d4 | 90 | state = roboter1.readSensors(); |
| itslinear | 9:d9e46f9c9e40 | 91 | break; |
| itslinear | 9:d9e46f9c9e40 | 92 | |
| itslinear | 18:3ee1b02ed3aa | 93 | case 5: |
| itslinear | 18:3ee1b02ed3aa | 94 | //printf("5"); |
| itslinear | 18:3ee1b02ed3aa | 95 | state = roboter1.pickup(); // Aufnehmen des Klotzes |
| itslinear | 20:a90e5b54bf7b | 96 | temp = 5; |
| itslinear | 9:d9e46f9c9e40 | 97 | break; |
| itslinear | 9:d9e46f9c9e40 | 98 | |
| itslinear | 19:adae367247d4 | 99 | case 6: |
| itslinear | 19:adae367247d4 | 100 | //printf("6"); |
| itslinear | 20:a90e5b54bf7b | 101 | temp =0; |
| itslinear | 19:adae367247d4 | 102 | state = roboter1.ausweichen2(); // Hindernissen ausweichen während Klotz angefahren wird |
| itslinear | 20:a90e5b54bf7b | 103 | break; |
| itslinear | 20:a90e5b54bf7b | 104 | |
| itslinear | 19:adae367247d4 | 105 | case 7: |
| itslinear | 20:a90e5b54bf7b | 106 | //printf("7"); |
| itslinear | 20:a90e5b54bf7b | 107 | temp = 0; |
| itslinear | 20:a90e5b54bf7b | 108 | state = roboter1.back(); |
| itslinear | 20:a90e5b54bf7b | 109 | break; |
| itslinear | 20:a90e5b54bf7b | 110 | |
| itslinear | 9:d9e46f9c9e40 | 111 | default: |
| itslinear | 9:d9e46f9c9e40 | 112 | break; |
| itslinear | 9:d9e46f9c9e40 | 113 | |
| itslinear | 6:4af735d26b7a | 114 | } |
| itslinear | 20:a90e5b54bf7b | 115 | //printf("%d\n", state); |
| itslinear | 20:a90e5b54bf7b | 116 | wait(0.001f); |
| schneju2 | 5:f48b2609c328 | 117 | } |
| itslinear | 9:d9e46f9c9e40 | 118 | } |
