yoka konishi
/
a1_SPI_slave_arm_shudouki
手動機アーム、ヌクレオ基盤のプログラムです(9/4)
Fork of a_SPI_slave_arm_shudouki by
main.cpp@2:df4d6f7952b6, 2017-08-24 (annotated)
- Committer:
- yoka06
- Date:
- Thu Aug 24 14:21:45 2017 +0000
- Revision:
- 2:df4d6f7952b6
- Parent:
- 1:9e95f48ea988
- Child:
- 3:f200ae8fea88
?
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 | 2:df4d6f7952b6 | 11 | RcServo sA(PB_0,500,2400,180); //PwmOutのpin,minpulsewidth,maxpulsewidth,motionrange |
yoka06 | 2:df4d6f7952b6 | 12 | RcServo sB(PA_9,500,2100,180); |
yoka06 | 2:df4d6f7952b6 | 13 | RcServo sC(PA_10,500,2100,180); |
yoka06 | 2:df4d6f7952b6 | 14 | RcServo sD(PA_11,500,3000,180); |
yoka06 | 2:df4d6f7952b6 | 15 | RcServo sE(PA_2,500,2400,180); |
yoka06 | 0:bf93b3e87029 | 16 | RcServo sF(PA_3,500,3000,180); |
yoka06 | 2:df4d6f7952b6 | 17 | RcServo sG(PA_8,500,2400,180); |
yoka06 | 2:df4d6f7952b6 | 18 | M1 mH(PB_7,PB_6); //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 | 2:df4d6f7952b6 | 70 | mH.move(0.5); |
yoka06 | 2:df4d6f7952b6 | 71 | wait(1); |
yoka06 | 2:df4d6f7952b6 | 72 | mH.move(0); |
yoka06 | 2:df4d6f7952b6 | 73 | |
yoka06 | 0:bf93b3e87029 | 74 | } |
yoka06 | 0:bf93b3e87029 | 75 | |
yoka06 | 0:bf93b3e87029 | 76 | if(d==1) { |
yoka06 | 0:bf93b3e87029 | 77 | // if((ButtonState >> BUTTONCIRCLE)&1 == 1) { // 〇でタンク回収 |
yoka06 | 0:bf93b3e87029 | 78 | sA.set_deg(90); |
yoka06 | 0:bf93b3e87029 | 79 | sE.set_deg(90); |
yoka06 | 1:9e95f48ea988 | 80 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 81 | sD.set_deg(0); |
yoka06 | 1:9e95f48ea988 | 82 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 83 | sE.set_deg(120); |
yoka06 | 1:9e95f48ea988 | 84 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 85 | sD.set_deg(90); |
yoka06 | 1:9e95f48ea988 | 86 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 87 | sE.set_deg(90); |
yoka06 | 1:9e95f48ea988 | 88 | sA.set_deg(158); |
yoka06 | 1:9e95f48ea988 | 89 | |
yoka06 | 0:bf93b3e87029 | 90 | } |
yoka06 | 0:bf93b3e87029 | 91 | |
yoka06 | 0:bf93b3e87029 | 92 | if(e==1) { |
yoka06 | 0:bf93b3e87029 | 93 | // if((ButtonState >> BUTTONRIGHT)&1 == 1) { // ‣でタンク掃き出し |
yoka06 | 2:df4d6f7952b6 | 94 | mH.move(-0.5); |
yoka06 | 2:df4d6f7952b6 | 95 | wait(1); |
yoka06 | 2:df4d6f7952b6 | 96 | mH.move(0); |
yoka06 | 0:bf93b3e87029 | 97 | } |
yoka06 | 0:bf93b3e87029 | 98 | |
yoka06 | 0:bf93b3e87029 | 99 | if(f==1) { |
yoka06 | 0:bf93b3e87029 | 100 | // if((ButtonState >> BUTTONDOWN)&1 == 1) { // ▼で待機 |
yoka06 | 0:bf93b3e87029 | 101 | sF.set_deg(180); |
yoka06 | 0:bf93b3e87029 | 102 | sG.set_deg(120); |
yoka06 | 1:9e95f48ea988 | 103 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 104 | sA.set_deg(180); |
yoka06 | 1:9e95f48ea988 | 105 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 106 | sD.set_deg(0); |
yoka06 | 1:9e95f48ea988 | 107 | |
yoka06 | 0:bf93b3e87029 | 108 | } |
yoka06 | 0:bf93b3e87029 | 109 | if(g==1) { |
yoka06 | 0:bf93b3e87029 | 110 | // if((ButtonState >> BUTTONCROSS)&1 == 1) { // ×でサンプル受け取り |
yoka06 | 0:bf93b3e87029 | 111 | sG.set_deg(90); |
yoka06 | 1:9e95f48ea988 | 112 | wait(0.7); |
yoka06 | 1:9e95f48ea988 | 113 | sF.set_deg(90); |
yoka06 | 1:9e95f48ea988 | 114 | |
yoka06 | 0:bf93b3e87029 | 115 | } |
yoka06 | 0:bf93b3e87029 | 116 | if(h==1) { |
yoka06 | 0:bf93b3e87029 | 117 | // if((ButtonState >> BUTTONSQUARE)&1 == 1) { // □でサンプル設置 |
yoka06 | 0:bf93b3e87029 | 118 | sG.set_deg(120); |
yoka06 | 0:bf93b3e87029 | 119 | } |
yoka06 | 0:bf93b3e87029 | 120 | } |
yoka06 | 0:bf93b3e87029 | 121 | } |
yoka06 | 1:9e95f48ea988 | 122 | |
yoka06 | 1:9e95f48ea988 | 123 |