yoka konishi
/
a1_SPI_slave_arm_shudouki
手動機アーム、ヌクレオ基盤のプログラムです(9/4)
Fork of a_SPI_slave_arm_shudouki by
main.cpp@1:9e95f48ea988, 2017-08-23 (annotated)
- Committer:
- yoka06
- Date:
- Wed Aug 23 04:43:58 2017 +0000
- Revision:
- 1:9e95f48ea988
- Parent:
- 0:bf93b3e87029
- Child:
- 2:df4d6f7952b6
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yoka06 | 0:bf93b3e87029 | 1 | #include "mbed.h" |
yoka06 | 0:bf93b3e87029 | 2 | #include "rc-servo.h" |
yoka06 | 0:bf93b3e87029 | 3 | #include "motor_1.h" |
yoka06 | 0:bf93b3e87029 | 4 | #include "motor_2.h" |
yoka06 | 0:bf93b3e87029 | 5 | |
yoka06 | 0:bf93b3e87029 | 6 | |
yoka06 | 0:bf93b3e87029 | 7 | int a,b,c,d,e,f,g,h; |
yoka06 | 0:bf93b3e87029 | 8 | |
yoka06 | 0:bf93b3e87029 | 9 | SPISlave spi(PA_7,PA_6,PA_5,PA_4); |
yoka06 | 0:bf93b3e87029 | 10 | |
yoka06 | 0:bf93b3e87029 | 11 | RcServo sA(PA_1,500,2400,180); //PwmOutのpin,minpulsewidth,maxpulsewidth,motionrange |
yoka06 | 0:bf93b3e87029 | 12 | RcServo sB(PB_4,500,2100,180); |
yoka06 | 0:bf93b3e87029 | 13 | RcServo sC(PB_5,500,2100,180); |
yoka06 | 0:bf93b3e87029 | 14 | RcServo sD(PA_2,500,3000,180); |
yoka06 | 0:bf93b3e87029 | 15 | RcServo sE(PA_11,500,2400,180); |
yoka06 | 0:bf93b3e87029 | 16 | RcServo sF(PA_3,500,3000,180); |
yoka06 | 0:bf93b3e87029 | 17 | RcServo sG(PF_0,500,2400,180); |
yoka06 | 0:bf93b3e87029 | 18 | M1 mH(PA_9,PA_10); //pwm*2 |
yoka06 | 0:bf93b3e87029 | 19 | |
yoka06 | 0:bf93b3e87029 | 20 | |
yoka06 | 0:bf93b3e87029 | 21 | |
yoka06 | 0:bf93b3e87029 | 22 | |
yoka06 | 0:bf93b3e87029 | 23 | |
yoka06 | 0:bf93b3e87029 | 24 | int main() |
yoka06 | 0:bf93b3e87029 | 25 | { |
yoka06 | 0:bf93b3e87029 | 26 | |
yoka06 | 0:bf93b3e87029 | 27 | spi.format(16,3); |
yoka06 | 0:bf93b3e87029 | 28 | spi.frequency(1000000); |
yoka06 | 0:bf93b3e87029 | 29 | |
yoka06 | 0:bf93b3e87029 | 30 | while(1) { |
yoka06 | 0:bf93b3e87029 | 31 | if (spi.receive()) { |
yoka06 | 0:bf93b3e87029 | 32 | |
yoka06 | 0:bf93b3e87029 | 33 | a=spi.read() & 0b1; |
yoka06 | 0:bf93b3e87029 | 34 | b=(spi.read() & 0b10)>>1; |
yoka06 | 0:bf93b3e87029 | 35 | c=(spi.read() & 0b100)>>2; |
yoka06 | 0:bf93b3e87029 | 36 | d=(spi.read() & 0b1000)>>3; |
yoka06 | 0:bf93b3e87029 | 37 | e=(spi.read() & 0b10000)>>4; |
yoka06 | 0:bf93b3e87029 | 38 | f=(spi.read() & 0b100000)>>5; |
yoka06 | 0:bf93b3e87029 | 39 | g=(spi.read() & 0b1000000)>>6; |
yoka06 | 0:bf93b3e87029 | 40 | h=(spi.read() & 0b10000000)>>7; |
yoka06 | 0:bf93b3e87029 | 41 | |
yoka06 | 0:bf93b3e87029 | 42 | } |
yoka06 | 0:bf93b3e87029 | 43 | |
yoka06 | 0:bf93b3e87029 | 44 | if(a==1) { |
yoka06 | 0:bf93b3e87029 | 45 | // if((ButtonState >> BUTTONUP)&1 == 1) { // ▲で燃料用アーム展開 |
yoka06 | 0:bf93b3e87029 | 46 | sD.set_deg(90); |
yoka06 | 1:9e95f48ea988 | 47 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 48 | sA.set_deg(62); |
yoka06 | 1:9e95f48ea988 | 49 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 50 | sB.set_deg(180); |
yoka06 | 1:9e95f48ea988 | 51 | sC.set_deg(0); |
yoka06 | 1:9e95f48ea988 | 52 | } |
yoka06 | 0:bf93b3e87029 | 53 | |
yoka06 | 1:9e95f48ea988 | 54 | |
yoka06 | 0:bf93b3e87029 | 55 | |
yoka06 | 0:bf93b3e87029 | 56 | if(b==1) { |
yoka06 | 0:bf93b3e87029 | 57 | // if((ButtonState >> BUTTONTRIANGEL)&1 == 1) { // △で燃料回収 |
yoka06 | 0:bf93b3e87029 | 58 | sB.set_deg(0); |
yoka06 | 0:bf93b3e87029 | 59 | sC.set_deg(180); |
yoka06 | 1:9e95f48ea988 | 60 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 61 | sA.set_deg(152); |
yoka06 | 1:9e95f48ea988 | 62 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 63 | sD.set_deg(180); |
yoka06 | 1:9e95f48ea988 | 64 | sE.set_deg(120); |
yoka06 | 1:9e95f48ea988 | 65 | |
yoka06 | 0:bf93b3e87029 | 66 | } |
yoka06 | 0:bf93b3e87029 | 67 | |
yoka06 | 0:bf93b3e87029 | 68 | if(c==1) { |
yoka06 | 0:bf93b3e87029 | 69 | // if((ButtonState >> BUTTONLEFT)&1 == 1) { // ◀で燃料掃き出し |
yoka06 | 0:bf93b3e87029 | 70 | // ??保留 |
yoka06 | 0:bf93b3e87029 | 71 | } |
yoka06 | 0:bf93b3e87029 | 72 | |
yoka06 | 0:bf93b3e87029 | 73 | if(d==1) { |
yoka06 | 0:bf93b3e87029 | 74 | // if((ButtonState >> BUTTONCIRCLE)&1 == 1) { // 〇でタンク回収 |
yoka06 | 0:bf93b3e87029 | 75 | sA.set_deg(90); |
yoka06 | 0:bf93b3e87029 | 76 | sE.set_deg(90); |
yoka06 | 1:9e95f48ea988 | 77 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 78 | sD.set_deg(0); |
yoka06 | 1:9e95f48ea988 | 79 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 80 | sE.set_deg(120); |
yoka06 | 1:9e95f48ea988 | 81 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 82 | sD.set_deg(90); |
yoka06 | 1:9e95f48ea988 | 83 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 84 | sE.set_deg(90); |
yoka06 | 1:9e95f48ea988 | 85 | sA.set_deg(158); |
yoka06 | 1:9e95f48ea988 | 86 | |
yoka06 | 0:bf93b3e87029 | 87 | } |
yoka06 | 0:bf93b3e87029 | 88 | |
yoka06 | 0:bf93b3e87029 | 89 | if(e==1) { |
yoka06 | 0:bf93b3e87029 | 90 | // if((ButtonState >> BUTTONRIGHT)&1 == 1) { // ‣でタンク掃き出し |
yoka06 | 0:bf93b3e87029 | 91 | //??保留 |
yoka06 | 0:bf93b3e87029 | 92 | } |
yoka06 | 0:bf93b3e87029 | 93 | |
yoka06 | 0:bf93b3e87029 | 94 | if(f==1) { |
yoka06 | 0:bf93b3e87029 | 95 | // if((ButtonState >> BUTTONDOWN)&1 == 1) { // ▼で待機 |
yoka06 | 0:bf93b3e87029 | 96 | sF.set_deg(180); |
yoka06 | 0:bf93b3e87029 | 97 | sG.set_deg(120); |
yoka06 | 1:9e95f48ea988 | 98 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 99 | sA.set_deg(180); |
yoka06 | 1:9e95f48ea988 | 100 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 101 | sD.set_deg(0); |
yoka06 | 1:9e95f48ea988 | 102 | |
yoka06 | 0:bf93b3e87029 | 103 | } |
yoka06 | 0:bf93b3e87029 | 104 | if(g==1) { |
yoka06 | 0:bf93b3e87029 | 105 | // if((ButtonState >> BUTTONCROSS)&1 == 1) { // ×でサンプル受け取り |
yoka06 | 0:bf93b3e87029 | 106 | sG.set_deg(90); |
yoka06 | 1:9e95f48ea988 | 107 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 108 | sF.set_deg(90); |
yoka06 | 1:9e95f48ea988 | 109 | |
yoka06 | 0:bf93b3e87029 | 110 | } |
yoka06 | 0:bf93b3e87029 | 111 | if(h==1) { |
yoka06 | 0:bf93b3e87029 | 112 | // if((ButtonState >> BUTTONSQUARE)&1 == 1) { // □でサンプル設置 |
yoka06 | 0:bf93b3e87029 | 113 | sG.set_deg(120); |
yoka06 | 0:bf93b3e87029 | 114 | } |
yoka06 | 0:bf93b3e87029 | 115 | } |
yoka06 | 0:bf93b3e87029 | 116 | } |
yoka06 | 1:9e95f48ea988 | 117 | |
yoka06 | 1:9e95f48ea988 | 118 |