Martin Werluschnig
/
BertlTemplate2_Linienfahren
BertlTemplate2_Linienfahren
BertlTemplate_Linienfahren.cpp@5:b1a4eed391a6, 2018-11-15 (annotated)
- Committer:
- martwerl
- Date:
- Thu Nov 15 17:50:41 2018 +0000
- Revision:
- 5:b1a4eed391a6
BertlTemplate2_Linienfahren
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
martwerl | 5:b1a4eed391a6 | 1 | |
martwerl | 5:b1a4eed391a6 | 2 | #include "mbed.h" |
martwerl | 5:b1a4eed391a6 | 3 | #include "Serial_HL.h" |
martwerl | 5:b1a4eed391a6 | 4 | #include "Bertl14.h" |
martwerl | 5:b1a4eed391a6 | 5 | #include "BertlObjects.h" |
martwerl | 5:b1a4eed391a6 | 6 | |
martwerl | 5:b1a4eed391a6 | 7 | // main=2^0 LS ENC 2^2 |
martwerl | 5:b1a4eed391a6 | 8 | BusOut boardPow(p30, P1_6, P1_7); |
martwerl | 5:b1a4eed391a6 | 9 | |
martwerl | 5:b1a4eed391a6 | 10 | // ls5 nur beim Betrl15 |
martwerl | 5:b1a4eed391a6 | 11 | // AnalogInHL ls1(p18), ls2(p16), ls3(p19), ls4(p17); // B14 |
martwerl | 5:b1a4eed391a6 | 12 | |
martwerl | 5:b1a4eed391a6 | 13 | AnalogInHL ls1(p18), ls2(p16), ls3(p20), ls4(p19), ls5(p17); // B15 |
martwerl | 5:b1a4eed391a6 | 14 | |
martwerl | 5:b1a4eed391a6 | 15 | int main(void) |
martwerl | 5:b1a4eed391a6 | 16 | { |
martwerl | 5:b1a4eed391a6 | 17 | boardPow=3; wait_ms(10); |
martwerl | 5:b1a4eed391a6 | 18 | InitBertl(); |
martwerl | 5:b1a4eed391a6 | 19 | pex.useISR=0; leds=9; |
martwerl | 5:b1a4eed391a6 | 20 | pex.ClearLeds(); |
martwerl | 5:b1a4eed391a6 | 21 | |
martwerl | 5:b1a4eed391a6 | 22 | bool rechts = 0;//flag, welche kurve zuletzt dran war |
martwerl | 5:b1a4eed391a6 | 23 | bool links = 0; |
martwerl | 5:b1a4eed391a6 | 24 | |
martwerl | 5:b1a4eed391a6 | 25 | while(1) |
martwerl | 5:b1a4eed391a6 | 26 | { |
martwerl | 5:b1a4eed391a6 | 27 | wait_ms(10); |
martwerl | 5:b1a4eed391a6 | 28 | |
martwerl | 5:b1a4eed391a6 | 29 | if(ls1.Read()>600) |
martwerl | 5:b1a4eed391a6 | 30 | { |
martwerl | 5:b1a4eed391a6 | 31 | mL.SetPow(0.3); mR.SetPow(0.1);//rechtskrve |
martwerl | 5:b1a4eed391a6 | 32 | rechts = 1; |
martwerl | 5:b1a4eed391a6 | 33 | } |
martwerl | 5:b1a4eed391a6 | 34 | else if(ls4.Read()>600) |
martwerl | 5:b1a4eed391a6 | 35 | { |
martwerl | 5:b1a4eed391a6 | 36 | mL.SetPow(0.1); mR.SetPow(0.3);//linkskurve |
martwerl | 5:b1a4eed391a6 | 37 | links = 1; |
martwerl | 5:b1a4eed391a6 | 38 | } |
martwerl | 5:b1a4eed391a6 | 39 | else if(ls1.Read()<200 && ls4.Read()<200 && ls2.Read()>200 && ls3.Read()>200) |
martwerl | 5:b1a4eed391a6 | 40 | { |
martwerl | 5:b1a4eed391a6 | 41 | mL.SetPow(0.3); mR.SetPow(0.3);//geradeaus |
martwerl | 5:b1a4eed391a6 | 42 | rechts = 0; |
martwerl | 5:b1a4eed391a6 | 43 | links = 0; |
martwerl | 5:b1a4eed391a6 | 44 | } |
martwerl | 5:b1a4eed391a6 | 45 | else if(ls1.Read()<200 && ls4.Read()<200 && ls2.Read()<200 && ls3.Read()<200 && ls5.Read()<200)//wenn alle unter 200, je nachdem was die letzte kurve war --> andere richtung |
martwerl | 5:b1a4eed391a6 | 46 | { |
martwerl | 5:b1a4eed391a6 | 47 | if(links == 1) |
martwerl | 5:b1a4eed391a6 | 48 | { |
martwerl | 5:b1a4eed391a6 | 49 | mL.SetPow(0.1); mR.SetPow(0.3);//linkskurve |
martwerl | 5:b1a4eed391a6 | 50 | rechts = 0;//zurücksetzen |
martwerl | 5:b1a4eed391a6 | 51 | } |
martwerl | 5:b1a4eed391a6 | 52 | else if (rechts == 1) |
martwerl | 5:b1a4eed391a6 | 53 | { |
martwerl | 5:b1a4eed391a6 | 54 | mL.SetPow(0.3); mR.SetPow(0.1);//rechtskurve |
martwerl | 5:b1a4eed391a6 | 55 | links = 0; |
martwerl | 5:b1a4eed391a6 | 56 | } |
martwerl | 5:b1a4eed391a6 | 57 | else |
martwerl | 5:b1a4eed391a6 | 58 | { |
martwerl | 5:b1a4eed391a6 | 59 | mL.SetPow(0.3); mR.SetPow(0.3);//geradeaus |
martwerl | 5:b1a4eed391a6 | 60 | } |
martwerl | 5:b1a4eed391a6 | 61 | } |
martwerl | 5:b1a4eed391a6 | 62 | } |
martwerl | 5:b1a4eed391a6 | 63 | return 1; |
martwerl | 5:b1a4eed391a6 | 64 | } |
martwerl | 5:b1a4eed391a6 | 65 | |
martwerl | 5:b1a4eed391a6 | 66 |