![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
vf
Dependencies: Servo ServoArm mbed
Fork of PES_Official by
Sources/main.cpp@7:6fed0dcae9c1, 2017-05-02 (annotated)
- Committer:
- EpicG10
- Date:
- Tue May 02 08:00:19 2017 +0000
- Revision:
- 7:6fed0dcae9c1
- Parent:
- 6:ba26dd3251b3
- Child:
- 10:f76476943a6c
u
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
beacon | 0:d267b248eff4 | 1 | #include "mbed.h" |
beacon | 0:d267b248eff4 | 2 | #include "Robot.h" |
beacon | 4:67d7177c213f | 3 | #include "Declarations.h" |
beacon | 0:d267b248eff4 | 4 | |
beacon | 0:d267b248eff4 | 5 | #include <cstdlib> |
beacon | 0:d267b248eff4 | 6 | |
beacon | 4:67d7177c213f | 7 | //DistanceSensors related bottom: |
beacon | 0:d267b248eff4 | 8 | Serial pc(SERIAL_TX, SERIAL_RX); |
beacon | 0:d267b248eff4 | 9 | |
beacon | 0:d267b248eff4 | 10 | AnalogIn sensorVoltage(PB_1); |
beacon | 0:d267b248eff4 | 11 | DigitalOut enable(PC_1); |
beacon | 0:d267b248eff4 | 12 | DigitalOut bit0(PH_1); |
beacon | 0:d267b248eff4 | 13 | DigitalOut bit1(PC_2); |
beacon | 0:d267b248eff4 | 14 | DigitalOut bit2(PC_3); |
beacon | 1:388c915756f5 | 15 | |
beacon | 4:67d7177c213f | 16 | //DistanceSensors top: |
beacon | 4:67d7177c213f | 17 | AnalogIn frontS(A1); |
beacon | 4:67d7177c213f | 18 | AnalogIn leftS(A2); |
beacon | 4:67d7177c213f | 19 | AnalogIn rightS(A3); |
beacon | 4:67d7177c213f | 20 | |
beacon | 1:388c915756f5 | 21 | //Leds related: |
beacon | 1:388c915756f5 | 22 | DigitalOut leds[6] = { PC_8, PC_6, PB_12, PA_7, PC_0, PC_9 }; |
beacon | 0:d267b248eff4 | 23 | |
beacon | 1:388c915756f5 | 24 | //motor related: |
beacon | 1:388c915756f5 | 25 | PwmOut left(PA_8); |
beacon | 1:388c915756f5 | 26 | PwmOut right(PA_9); |
beacon | 0:d267b248eff4 | 27 | |
beacon | 1:388c915756f5 | 28 | DigitalOut powerSignal(PB_2); |
beacon | 1:388c915756f5 | 29 | DigitalIn errorSignal(PB_14); |
beacon | 1:388c915756f5 | 30 | DigitalIn overtemperatur(PB_15); |
beacon | 1:388c915756f5 | 31 | |
beacon | 4:67d7177c213f | 32 | //Arm: |
beacon | 6:ba26dd3251b3 | 33 | Servo servoArm(PA_6); |
beacon | 4:67d7177c213f | 34 | |
beacon | 1:388c915756f5 | 35 | //Farbsensor: |
beacon | 1:388c915756f5 | 36 | AnalogIn FarbVoltage(A0); |
beacon | 1:388c915756f5 | 37 | |
beacon | 6:ba26dd3251b3 | 38 | Robot sam( &left, &right, &powerSignal, leds, &FarbVoltage, &frontS, &leftS, &rightS, &servoArm); //Implement the Farbsensor into the Robot init function!! |
beacon | 1:388c915756f5 | 39 | |
beacon | 0:d267b248eff4 | 40 | |
beacon | 0:d267b248eff4 | 41 | |
beacon | 6:ba26dd3251b3 | 42 | /* * / |
beacon | 1:388c915756f5 | 43 | int main(){ |
beacon | 4:67d7177c213f | 44 | initializeDistanceSensors(); //Initialises IR-Sensors. |
beacon | 4:67d7177c213f | 45 | int counter = 0; //Counts how many times the robot has turned, before driving |
beacon | 4:67d7177c213f | 46 | int timer = 0; //Is used, to reset the robot. Returns time in [0.1s] |
beacon | 4:67d7177c213f | 47 | //int lastFun = -1; //Is used, to check if the same action in Robot::search() was made multiple times. |
beacon | 4:67d7177c213f | 48 | int found = 0; //0:= no block available, 1 := a lego is ready to be picked up |
beacon | 0:d267b248eff4 | 49 | |
beacon | 4:67d7177c213f | 50 | while( 1 ){ |
beacon | 4:67d7177c213f | 51 | if ( timer > TIMEOUT ){ |
beacon | 4:67d7177c213f | 52 | NVIC_SystemReset(); //Resets Sam. |
beacon | 4:67d7177c213f | 53 | } |
beacon | 4:67d7177c213f | 54 | else if (found == 0){ |
beacon | 4:67d7177c213f | 55 | sam.search(&counter, &timer, &found); |
beacon | 4:67d7177c213f | 56 | } |
beacon | 4:67d7177c213f | 57 | else{ |
beacon | 4:67d7177c213f | 58 | //pick up lego |
beacon | 4:67d7177c213f | 59 | //found = 0; |
beacon | 5:1aaf5de776ff | 60 | sam.stop(); //Nur zum Testen |
beacon | 4:67d7177c213f | 61 | } |
beacon | 1:388c915756f5 | 62 | |
beacon | 1:388c915756f5 | 63 | wait( 0.1f ); |
beacon | 0:d267b248eff4 | 64 | } |
beacon | 0:d267b248eff4 | 65 | return 0; |
beacon | 4:67d7177c213f | 66 | } |
beacon | 4:67d7177c213f | 67 | |
beacon | 4:67d7177c213f | 68 | /* * / |
beacon | 4:67d7177c213f | 69 | int main(){ |
beacon | 4:67d7177c213f | 70 | |
beacon | 4:67d7177c213f | 71 | initializeDistanceSensors(); |
beacon | 4:67d7177c213f | 72 | sam.stop(); |
beacon | 4:67d7177c213f | 73 | |
beacon | 4:67d7177c213f | 74 | while ( 1 ){ |
beacon | 4:67d7177c213f | 75 | for (int i=0; i<6; i++){ |
beacon | 4:67d7177c213f | 76 | sam.sensors[i] < NEAR ? sam.leds[i] = 1 : sam.leds[i] = 0; |
beacon | 4:67d7177c213f | 77 | } |
beacon | 4:67d7177c213f | 78 | |
beacon | 4:67d7177c213f | 79 | sam.turnLeftS(); |
beacon | 4:67d7177c213f | 80 | |
beacon | 4:67d7177c213f | 81 | while (sam.sensors[FWD] < NEAR){ |
beacon | 4:67d7177c213f | 82 | wait(0.05f); |
beacon | 4:67d7177c213f | 83 | sam.stop(); |
beacon | 4:67d7177c213f | 84 | } |
beacon | 4:67d7177c213f | 85 | |
beacon | 4:67d7177c213f | 86 | } |
beacon | 4:67d7177c213f | 87 | return 0; |
beacon | 4:67d7177c213f | 88 | } |
beacon | 4:67d7177c213f | 89 | /* */ |
beacon | 4:67d7177c213f | 90 | |
beacon | 4:67d7177c213f | 91 | /* * / |
beacon | 4:67d7177c213f | 92 | int main(){ |
beacon | 4:67d7177c213f | 93 | for(float p=0; p<1.0; p += 0.1) { |
beacon | 4:67d7177c213f | 94 | // arm = p; |
beacon | 4:67d7177c213f | 95 | wait(0.2); |
beacon | 4:67d7177c213f | 96 | } |
beacon | 4:67d7177c213f | 97 | } |
beacon | 6:ba26dd3251b3 | 98 | /* */ |
beacon | 6:ba26dd3251b3 | 99 | |
beacon | 6:ba26dd3251b3 | 100 | /* */ |
beacon | 6:ba26dd3251b3 | 101 | int main(){ |
beacon | 6:ba26dd3251b3 | 102 | sam.stop(); |
beacon | 6:ba26dd3251b3 | 103 | int done = 0; //1:= finished process; 0:= not finished |
beacon | 6:ba26dd3251b3 | 104 | int fun = 0; //just to test. |
EpicG10 | 7:6fed0dcae9c1 | 105 | int start = 0; |
EpicG10 | 7:6fed0dcae9c1 | 106 | |
EpicG10 | 7:6fed0dcae9c1 | 107 | |
beacon | 6:ba26dd3251b3 | 108 | while(1){ |
beacon | 6:ba26dd3251b3 | 109 | if(fun == 0){ |
beacon | 6:ba26dd3251b3 | 110 | done = 0; |
beacon | 6:ba26dd3251b3 | 111 | sam.Arm.collecttoback(&done); |
EpicG10 | 7:6fed0dcae9c1 | 112 | done == 0 ? fun = 0 : fun = 1; |
beacon | 6:ba26dd3251b3 | 113 | } |
beacon | 6:ba26dd3251b3 | 114 | else if(fun == 1){ |
beacon | 6:ba26dd3251b3 | 115 | done = 0; |
beacon | 6:ba26dd3251b3 | 116 | sam.Arm.backtocollect(&done); |
beacon | 6:ba26dd3251b3 | 117 | done == 0 ? fun = 1 : fun = 2; |
beacon | 6:ba26dd3251b3 | 118 | } |
beacon | 6:ba26dd3251b3 | 119 | else if(fun == 2){ |
beacon | 6:ba26dd3251b3 | 120 | done = 0; |
beacon | 6:ba26dd3251b3 | 121 | sam.Arm.collecttodown(&done); |
beacon | 6:ba26dd3251b3 | 122 | done == 0 ? fun = 2 : fun = 3; |
beacon | 6:ba26dd3251b3 | 123 | } |
beacon | 6:ba26dd3251b3 | 124 | else if(fun == 3){ |
beacon | 6:ba26dd3251b3 | 125 | done = 0; |
beacon | 6:ba26dd3251b3 | 126 | sam.Arm.downtocollect(&done); |
beacon | 6:ba26dd3251b3 | 127 | done == 0 ? fun = 3 : fun = 0; |
beacon | 6:ba26dd3251b3 | 128 | } |
beacon | 6:ba26dd3251b3 | 129 | wait(0.1); |
beacon | 6:ba26dd3251b3 | 130 | } |
beacon | 6:ba26dd3251b3 | 131 | } |