a
Dependencies: mbed LidarLitev2
main.cpp@0:48dbc1f972f1, 2019-09-29 (annotated)
- Committer:
- kazuryu
- Date:
- Sun Sep 29 09:41:46 2019 +0000
- Revision:
- 0:48dbc1f972f1
areyoukiddingme;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kazuryu | 0:48dbc1f972f1 | 1 | #include "mbed.h" |
kazuryu | 0:48dbc1f972f1 | 2 | #include "rori.h" |
kazuryu | 0:48dbc1f972f1 | 3 | |
kazuryu | 0:48dbc1f972f1 | 4 | DigitalIn ins(D12); |
kazuryu | 0:48dbc1f972f1 | 5 | DigitalIn intt(D5); |
kazuryu | 0:48dbc1f972f1 | 6 | PwmOut outs(D6); |
kazuryu | 0:48dbc1f972f1 | 7 | PwmOut outt(D3); |
kazuryu | 0:48dbc1f972f1 | 8 | DigitalOut outs_admin(D9); |
kazuryu | 0:48dbc1f972f1 | 9 | DigitalOut outt_admin(D4); |
kazuryu | 0:48dbc1f972f1 | 10 | //RORI roris(PA_0_ALT1,PA_1_ALT1); |
kazuryu | 0:48dbc1f972f1 | 11 | RORI rorit(PA_4_ALT0,PB_0_ALT0); |
kazuryu | 0:48dbc1f972f1 | 12 | Serial serial(USBTX,USBRX); |
kazuryu | 0:48dbc1f972f1 | 13 | |
kazuryu | 0:48dbc1f972f1 | 14 | /* |
kazuryu | 0:48dbc1f972f1 | 15 | DigitalIn ins(D13); |
kazuryu | 0:48dbc1f972f1 | 16 | DigitalIn intt(D11); |
kazuryu | 0:48dbc1f972f1 | 17 | PwmOut outs(D5); |
kazuryu | 0:48dbc1f972f1 | 18 | PwmOut outt(D3); |
kazuryu | 0:48dbc1f972f1 | 19 | DigitalOut outs_admin(D12); |
kazuryu | 0:48dbc1f972f1 | 20 | DigitalOut outt_admin(D10); |
kazuryu | 0:48dbc1f972f1 | 21 | RORI roris(PA_0_ALT1,PA_1_ALT1); |
kazuryu | 0:48dbc1f972f1 | 22 | RORI rorit(PA_4_ALT0,PB_0_ALT0); |
kazuryu | 0:48dbc1f972f1 | 23 | Serial serial(USBTX,USBRX); |
kazuryu | 0:48dbc1f972f1 | 24 | */ |
kazuryu | 0:48dbc1f972f1 | 25 | long roris_l = 0; |
kazuryu | 0:48dbc1f972f1 | 26 | long rorit_l = 0; |
kazuryu | 0:48dbc1f972f1 | 27 | int bunkais = 1024; |
kazuryu | 0:48dbc1f972f1 | 28 | int bunkait = 1024; |
kazuryu | 0:48dbc1f972f1 | 29 | float angs = 0; |
kazuryu | 0:48dbc1f972f1 | 30 | float angt = 0; |
kazuryu | 0:48dbc1f972f1 | 31 | int counts = 1; |
kazuryu | 0:48dbc1f972f1 | 32 | int countt = 1; |
kazuryu | 0:48dbc1f972f1 | 33 | bool start_lock = false; |
kazuryu | 0:48dbc1f972f1 | 34 | long lasts= 0; |
kazuryu | 0:48dbc1f972f1 | 35 | long lastt = 0; |
kazuryu | 0:48dbc1f972f1 | 36 | |
kazuryu | 0:48dbc1f972f1 | 37 | DigitalIn inlock_f(D2); |
kazuryu | 0:48dbc1f972f1 | 38 | PwmOut lock(D11); |
kazuryu | 0:48dbc1f972f1 | 39 | /* |
kazuryu | 0:48dbc1f972f1 | 40 | DigitalIn inlock_f(D15); |
kazuryu | 0:48dbc1f972f1 | 41 | PwmOut lock(D14); |
kazuryu | 0:48dbc1f972f1 | 42 | */ |
kazuryu | 0:48dbc1f972f1 | 43 | DigitalOut leds(D0); |
kazuryu | 0:48dbc1f972f1 | 44 | DigitalOut ledt(D1); |
kazuryu | 0:48dbc1f972f1 | 45 | bool flags = false; |
kazuryu | 0:48dbc1f972f1 | 46 | bool flagt = false; |
kazuryu | 0:48dbc1f972f1 | 47 | /* |
kazuryu | 0:48dbc1f972f1 | 48 | DigitalIn discr1(D14); |
kazuryu | 0:48dbc1f972f1 | 49 | DigitalIn discr2(D15); |
kazuryu | 0:48dbc1f972f1 | 50 | DigitalOut fieldColor(D13); |
kazuryu | 0:48dbc1f972f1 | 51 | DigitalOut cloth(D12); |
kazuryu | 0:48dbc1f972f1 | 52 | */ |
kazuryu | 0:48dbc1f972f1 | 53 | |
kazuryu | 0:48dbc1f972f1 | 54 | |
kazuryu | 0:48dbc1f972f1 | 55 | int main(){ |
kazuryu | 0:48dbc1f972f1 | 56 | ins.mode(PullDown); |
kazuryu | 0:48dbc1f972f1 | 57 | intt.mode(PullDown); |
kazuryu | 0:48dbc1f972f1 | 58 | inlock_f.mode(PullDown); |
kazuryu | 0:48dbc1f972f1 | 59 | |
kazuryu | 0:48dbc1f972f1 | 60 | outs.period_ms(1); |
kazuryu | 0:48dbc1f972f1 | 61 | lock.period_ms(1); |
kazuryu | 0:48dbc1f972f1 | 62 | while(1){ |
kazuryu | 0:48dbc1f972f1 | 63 | if(start_lock){ |
kazuryu | 0:48dbc1f972f1 | 64 | serial.printf("%s","start"); |
kazuryu | 0:48dbc1f972f1 | 65 | serial.printf("%d",inlock_f.read()); |
kazuryu | 0:48dbc1f972f1 | 66 | while(!inlock_f.read()){ |
kazuryu | 0:48dbc1f972f1 | 67 | lock = 0.2; |
kazuryu | 0:48dbc1f972f1 | 68 | serial.printf("%s\n","while"); |
kazuryu | 0:48dbc1f972f1 | 69 | } |
kazuryu | 0:48dbc1f972f1 | 70 | serial.printf("%s\n","out"); |
kazuryu | 0:48dbc1f972f1 | 71 | lock = 0; |
kazuryu | 0:48dbc1f972f1 | 72 | start_lock = false; |
kazuryu | 0:48dbc1f972f1 | 73 | } |
kazuryu | 0:48dbc1f972f1 | 74 | if(ins.read()){ |
kazuryu | 0:48dbc1f972f1 | 75 | outs = 0.1f; |
kazuryu | 0:48dbc1f972f1 | 76 | //roris.read(&roris_l);// |
kazuryu | 0:48dbc1f972f1 | 77 | if(roris_l == lasts){ |
kazuryu | 0:48dbc1f972f1 | 78 | flags = !flags; |
kazuryu | 0:48dbc1f972f1 | 79 | leds = (flags)?1:0; |
kazuryu | 0:48dbc1f972f1 | 80 | } |
kazuryu | 0:48dbc1f972f1 | 81 | angs = (float)roris_l/bunkais;//ang |
kazuryu | 0:48dbc1f972f1 | 82 | angs *= 360;//deg |
kazuryu | 0:48dbc1f972f1 | 83 | //serial.printf("%s",":"); |
kazuryu | 0:48dbc1f972f1 | 84 | //serial.printf("%f\n",angs); |
kazuryu | 0:48dbc1f972f1 | 85 | if(abs(angs) > 90*counts){ |
kazuryu | 0:48dbc1f972f1 | 86 | counts++; |
kazuryu | 0:48dbc1f972f1 | 87 | outs = 0; |
kazuryu | 0:48dbc1f972f1 | 88 | outs_admin = 1; |
kazuryu | 0:48dbc1f972f1 | 89 | wait(1); |
kazuryu | 0:48dbc1f972f1 | 90 | outs_admin = 0; |
kazuryu | 0:48dbc1f972f1 | 91 | } |
kazuryu | 0:48dbc1f972f1 | 92 | lasts = roris_l; |
kazuryu | 0:48dbc1f972f1 | 93 | |
kazuryu | 0:48dbc1f972f1 | 94 | }else{ |
kazuryu | 0:48dbc1f972f1 | 95 | outs = 0; |
kazuryu | 0:48dbc1f972f1 | 96 | } |
kazuryu | 0:48dbc1f972f1 | 97 | |
kazuryu | 0:48dbc1f972f1 | 98 | if(intt.read()){ |
kazuryu | 0:48dbc1f972f1 | 99 | outt = 0.1f; |
kazuryu | 0:48dbc1f972f1 | 100 | rorit.read(&rorit_l); |
kazuryu | 0:48dbc1f972f1 | 101 | if(rorit_l == lastt){ |
kazuryu | 0:48dbc1f972f1 | 102 | flagt = !flagt; |
kazuryu | 0:48dbc1f972f1 | 103 | ledt = (flagt)?:0; |
kazuryu | 0:48dbc1f972f1 | 104 | } |
kazuryu | 0:48dbc1f972f1 | 105 | angt = (float)rorit_l/bunkait; |
kazuryu | 0:48dbc1f972f1 | 106 | angt *= 360; |
kazuryu | 0:48dbc1f972f1 | 107 | if(abs(angt) > 120*countt){ |
kazuryu | 0:48dbc1f972f1 | 108 | countt++; |
kazuryu | 0:48dbc1f972f1 | 109 | outt = 0; |
kazuryu | 0:48dbc1f972f1 | 110 | outt_admin = 1; |
kazuryu | 0:48dbc1f972f1 | 111 | wait(0.5f); |
kazuryu | 0:48dbc1f972f1 | 112 | outt_admin = 0; |
kazuryu | 0:48dbc1f972f1 | 113 | } |
kazuryu | 0:48dbc1f972f1 | 114 | lastt = rorit_l; |
kazuryu | 0:48dbc1f972f1 | 115 | }else{ |
kazuryu | 0:48dbc1f972f1 | 116 | outt = 0; |
kazuryu | 0:48dbc1f972f1 | 117 | } |
kazuryu | 0:48dbc1f972f1 | 118 | |
kazuryu | 0:48dbc1f972f1 | 119 | } |
kazuryu | 0:48dbc1f972f1 | 120 | } |
kazuryu | 0:48dbc1f972f1 | 121 | /* |
kazuryu | 0:48dbc1f972f1 | 122 | int Discrimination(bool hoge){ |
kazuryu | 0:48dbc1f972f1 | 123 | bool discColor; |
kazuryu | 0:48dbc1f972f1 | 124 | bool discMode; |
kazuryu | 0:48dbc1f972f1 | 125 | discColor=discr1; |
kazuryu | 0:48dbc1f972f1 | 126 | discMode=discr2; |
kazuryu | 0:48dbc1f972f1 | 127 | if(hoge){ |
kazuryu | 0:48dbc1f972f1 | 128 | fieldColor=discr1; |
kazuryu | 0:48dbc1f972f1 | 129 | cloth=discr2; |
kazuryu | 0:48dbc1f972f1 | 130 | }else{ |
kazuryu | 0:48dbc1f972f1 | 131 | return 0; |
kazuryu | 0:48dbc1f972f1 | 132 | } |
kazuryu | 0:48dbc1f972f1 | 133 | return 1; |
kazuryu | 0:48dbc1f972f1 | 134 | } |
kazuryu | 0:48dbc1f972f1 | 135 | */ |