![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
xx
Fork of PES1 by
main.cpp@18:6547e54ac803, 2017-05-09 (annotated)
- Committer:
- itslinear
- Date:
- Tue May 09 13:21:49 2017 +0000
- Revision:
- 18:6547e54ac803
- Parent:
- 17:caf5ae550f2e
f?r holdi;
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:6547e54ac803 | 4 | |
itslinear | 18:6547e54ac803 | 5 | //Periphery for Encoder |
itslinear | 18:6547e54ac803 | 6 | EncoderCounter counterLeft(PB_6, PB_7); |
itslinear | 18:6547e54ac803 | 7 | EncoderCounter counterRight(PA_6, PC_7); |
itslinear | 18:6547e54ac803 | 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:6547e54ac803 | 19 | Servo servo1(PB_13); //Greiferservo Anschluss D2 |
itslinear | 18:6547e54ac803 | 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:6547e54ac803 | 33 | // Erstellen eines Roboterobjekts |
itslinear | 18:6547e54ac803 | 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:6547e54ac803 | 38 | int state = 0; // Diese Variable gibt an in welchem State man sich befindet |
itslinear | 18:6547e54ac803 | 39 | int tempState = 2; // Wird benötig um zwischen Kameraauswertung und fahren zu wechseln |
itslinear | 18:6547e54ac803 | 40 | enable = 1; // Sensoren einschalten |
itslinear | 18:6547e54ac803 | 41 | float camValue; |
itslinear | 18:6547e54ac803 | 42 | servo1 = 0.0f; // Startpos. Greifer |
itslinear | 18:6547e54ac803 | 43 | servo2 = 0.0f; // Startpos. Arm |
itslinear | 18:6547e54ac803 | 44 | //wait(1); |
itslinear | 9:d9e46f9c9e40 | 45 | |
itslinear | 9:d9e46f9c9e40 | 46 | while(1) { |
itslinear | 9:d9e46f9c9e40 | 47 | |
itslinear | 18:6547e54ac803 | 48 | /* |
itslinear | 18:6547e54ac803 | 49 | |
itslinear | 18:6547e54ac803 | 50 | //printf("%d\n", state); |
itslinear | 6:4af735d26b7a | 51 | |
itslinear | 6:4af735d26b7a | 52 | switch(state) { |
itslinear | 6:4af735d26b7a | 53 | |
itslinear | 12:b9faf8637183 | 54 | case 0: // Roboter Anschalten mit Knopf |
Shukle | 16:0a1703438e8b | 55 | printf("0"); |
itslinear | 6:4af735d26b7a | 56 | |
itslinear | 18:6547e54ac803 | 57 | if (switchOnOff == 0) { // Bei Betätigung des Userbuttons wird das Programm gestartet |
itslinear | 18:6547e54ac803 | 58 | state = 5; |
itslinear | 9:d9e46f9c9e40 | 59 | } |
itslinear | 7:edb4e0cfc0d1 | 60 | |
itslinear | 9:d9e46f9c9e40 | 61 | break; |
itslinear | 6:4af735d26b7a | 62 | |
itslinear | 12:b9faf8637183 | 63 | case 1: |
itslinear | 18:6547e54ac803 | 64 | //printf("1"); |
itslinear | 18:6547e54ac803 | 65 | camValue = readCamera(); |
itslinear | 18:6547e54ac803 | 66 | state = roboter1.stateAuswahl(camValue, tempState); // Case-Auswahl aufgrund von der Kamera |
Shukle | 16:0a1703438e8b | 67 | break; |
itslinear | 12:b9faf8637183 | 68 | |
itslinear | 9:d9e46f9c9e40 | 69 | case 2: |
itslinear | 18:6547e54ac803 | 70 | //printf("2"); |
itslinear | 18:6547e54ac803 | 71 | state = roboter1.kreisFahren(); // Im Kreis fahren |
itslinear | 18:6547e54ac803 | 72 | tempState = 2; |
itslinear | 9:d9e46f9c9e40 | 73 | break; |
itslinear | 6:4af735d26b7a | 74 | |
itslinear | 3:24e098715b78 | 75 | |
itslinear | 9:d9e46f9c9e40 | 76 | case 3: |
itslinear | 18:6547e54ac803 | 77 | //printf("3"); |
itslinear | 18:6547e54ac803 | 78 | roboter1.bandeAusweichen(); // Hindernissen ausweichen |
itslinear | 18:6547e54ac803 | 79 | state = roboter1.geradeFahren(); // Gerade Fahren |
itslinear | 18:6547e54ac803 | 80 | tempState = 3; |
itslinear | 9:d9e46f9c9e40 | 81 | break; |
itslinear | 6:4af735d26b7a | 82 | |
itslinear | 6:4af735d26b7a | 83 | |
itslinear | 18:6547e54ac803 | 84 | case 4: |
itslinear | 18:6547e54ac803 | 85 | //printf("4"); |
itslinear | 18:6547e54ac803 | 86 | roboter1.bandeAusweichen(); // Hindernissen ausweichen |
itslinear | 18:6547e54ac803 | 87 | roboter1.anfahren(camValue); // Roboter erkennt gründer Klotz, Klotz wird angefahren |
itslinear | 13:7eba9911e196 | 88 | state = 1; |
itslinear | 9:d9e46f9c9e40 | 89 | break; |
itslinear | 9:d9e46f9c9e40 | 90 | |
itslinear | 18:6547e54ac803 | 91 | case 5: |
itslinear | 18:6547e54ac803 | 92 | //printf("5"); |
itslinear | 18:6547e54ac803 | 93 | state = roboter1.pickup(); // Aufnehmen des Klotzes |
itslinear | 9:d9e46f9c9e40 | 94 | break; |
itslinear | 9:d9e46f9c9e40 | 95 | |
itslinear | 9:d9e46f9c9e40 | 96 | default: |
itslinear | 9:d9e46f9c9e40 | 97 | break; |
itslinear | 9:d9e46f9c9e40 | 98 | |
itslinear | 6:4af735d26b7a | 99 | } |
itslinear | 18:6547e54ac803 | 100 | */ |
itslinear | 18:6547e54ac803 | 101 | wait(0.01f); |
schneju2 | 5:f48b2609c328 | 102 | } |
itslinear | 9:d9e46f9c9e40 | 103 | } |