にいむら にいむら
/
NRPmainprogram2019
aa
System/Process/Process.cpp@1:e1e9671724e7, 2020-01-25 (annotated)
- Committer:
- niimurasyou
- Date:
- Sat Jan 25 02:55:50 2020 +0000
- Revision:
- 1:e1e9671724e7
- Parent:
- 0:2e7a61458dc3
aa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
M_souta | 0:2e7a61458dc3 | 1 | #include "Process.h" |
M_souta | 0:2e7a61458dc3 | 2 | #include "mbed.h" |
M_souta | 0:2e7a61458dc3 | 3 | #include "../../Communication/XBee/XBee.h" |
M_souta | 0:2e7a61458dc3 | 4 | #include "../../Input/Switch/Switch.h" |
M_souta | 0:2e7a61458dc3 | 5 | #include "../../Output/Motor/Motor.h" |
M_souta | 0:2e7a61458dc3 | 6 | |
niimurasyou | 1:e1e9671724e7 | 7 | //_____________________ |
niimurasyou | 1:e1e9671724e7 | 8 | /*---------------- HOW TO WRITE ----------------/ |
niimurasyou | 1:e1e9671724e7 | 9 | |
niimurasyou | 1:e1e9671724e7 | 10 | ・motor の割り当てを決める |
niimurasyou | 1:e1e9671724e7 | 11 | #define TIRE_L 1 |
niimurasyou | 1:e1e9671724e7 | 12 | |
niimurasyou | 1:e1e9671724e7 | 13 | ・リミットスイッチの割り当てを決める |
niimurasyou | 1:e1e9671724e7 | 14 | #define ARM_L 1 |
niimurasyou | 1:e1e9671724e7 | 15 | |
niimurasyou | 1:e1e9671724e7 | 16 | ・他にも自由に定義してもいいです (pwmとか) |
niimurasyou | 1:e1e9671724e7 | 17 | |
niimurasyou | 1:e1e9671724e7 | 18 | /---------------- HOW TO WRITE ----------------*/ |
niimurasyou | 1:e1e9671724e7 | 19 | //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ |
niimurasyou | 1:e1e9671724e7 | 20 | |
niimurasyou | 1:e1e9671724e7 | 21 | #define a 0 |
niimurasyou | 1:e1e9671724e7 | 22 | #define b 1 |
niimurasyou | 1:e1e9671724e7 | 23 | #define c 2 |
niimurasyou | 1:e1e9671724e7 | 24 | #define d 3 |
niimurasyou | 1:e1e9671724e7 | 25 | #define e 4 |
niimurasyou | 1:e1e9671724e7 | 26 | #define ARMlim 0 |
niimurasyou | 1:e1e9671724e7 | 27 | #define lim 1 |
niimurasyou | 1:e1e9671724e7 | 28 | |
niimurasyou | 1:e1e9671724e7 | 29 | |
niimurasyou | 1:e1e9671724e7 | 30 | int Air0=0; |
niimurasyou | 1:e1e9671724e7 | 31 | int Air1=1; |
niimurasyou | 1:e1e9671724e7 | 32 | int homes=0; |
niimurasyou | 1:e1e9671724e7 | 33 | |
niimurasyou | 1:e1e9671724e7 | 34 | |
M_souta | 0:2e7a61458dc3 | 35 | |
niimurasyou | 1:e1e9671724e7 | 36 | //////////////////関数、タイマーの宣言/////////////// |
niimurasyou | 1:e1e9671724e7 | 37 | DigitalOut Air[]= { |
niimurasyou | 1:e1e9671724e7 | 38 | DigitalOut(A5), |
niimurasyou | 1:e1e9671724e7 | 39 | DigitalOut(A4), |
niimurasyou | 1:e1e9671724e7 | 40 | }; |
niimurasyou | 1:e1e9671724e7 | 41 | Timer Airtime; |
niimurasyou | 1:e1e9671724e7 | 42 | Timer home; |
niimurasyou | 1:e1e9671724e7 | 43 | void AirOut(int pin,int mode) |
niimurasyou | 1:e1e9671724e7 | 44 | { |
niimurasyou | 1:e1e9671724e7 | 45 | Air[pin]=mode; |
niimurasyou | 1:e1e9671724e7 | 46 | } |
niimurasyou | 1:e1e9671724e7 | 47 | //////////// |
niimurasyou | 1:e1e9671724e7 | 48 | float s=Airtime.read();//エアータイム |
niimurasyou | 1:e1e9671724e7 | 49 | |
niimurasyou | 1:e1e9671724e7 | 50 | int a_array[15][15] = { |
niimurasyou | 1:e1e9671724e7 | 51 | {-80, -70, -60, -50, -40, -20, -10, 0, 10, 20, 40, 50, 60, 70, 80}, |
niimurasyou | 1:e1e9671724e7 | 52 | {-79, -69, -55, -47, -35, -20, -10, 0, 10, 20, 35, 47, 55, 69, 79}, |
niimurasyou | 1:e1e9671724e7 | 53 | {-77, -68, -50, -45, -30, -20, -10, 0, 10, 20, 30, 45, 50, 68, 77}, |
niimurasyou | 1:e1e9671724e7 | 54 | {-75, -67, -49, -40, -25, -20, -10, 0, 10, 20, 25, 40, 49, 67, 75}, |
niimurasyou | 1:e1e9671724e7 | 55 | {-73, -66, -48, -37, -20, -20, -10, 0, 10, 20, 20, 37, 48, 66, 73}, |
niimurasyou | 1:e1e9671724e7 | 56 | {-71, -62, -46, -32, -20, -10, 0, 0, 0, 10, 20, 32, 46, 62, 71}, |
niimurasyou | 1:e1e9671724e7 | 57 | {-70, -60, -45, -30, -20, -10, 0, 0, 0, 10, 20, 30, 45, 60, 70}, |
niimurasyou | 1:e1e9671724e7 | 58 | {-71, -62, -46, -32, 10, -10, 0, 0, 0, 10, 20, 32, 46, 62, 71}, |
niimurasyou | 1:e1e9671724e7 | 59 | {-72, -64, -47, -35, 20, -10, -10, 0, 10, 10, 20, 35, 47, 64, 72}, |
niimurasyou | 1:e1e9671724e7 | 60 | {-73, -66, -48, -37, -20, -20, -10, 0, 10, 20, 20, 37, 48, 66, 73}, |
niimurasyou | 1:e1e9671724e7 | 61 | {-75, -67, -49, -40, 40, -20, -10, 0, 10, 20, 25, 40, 49, 67, 75}, |
niimurasyou | 1:e1e9671724e7 | 62 | {-77, -68, -50, -45, 60, -20, -10, 0, 10, 20, 30, 45, 50, 68, 77}, |
niimurasyou | 1:e1e9671724e7 | 63 | {-79, -69, -55, -47, 70, -20, -10, 0, 10, 20, 35, 47, 55, 69, 79}, |
niimurasyou | 1:e1e9671724e7 | 64 | {-80, -70, -60, -50, -40, -20, -10, 0, 10, 20, 40, 50, 60, 70, 80}, |
niimurasyou | 1:e1e9671724e7 | 65 | {-80, -70, -60, -50, -40, -20,s-10, 0, 10, 20, 40, 50, 60, 70, 80} |
niimurasyou | 1:e1e9671724e7 | 66 | }; |
M_souta | 0:2e7a61458dc3 | 67 | |
niimurasyou | 1:e1e9671724e7 | 68 | int b_array[15][15] = { |
niimurasyou | 1:e1e9671724e7 | 69 | {80, 80, 80, 77, 75, 72, 71, 70, 60, 50, 40, 30, 20, 10, 0}, |
niimurasyou | 1:e1e9671724e7 | 70 | {80, 80, 75, 70, 65, 60, 55, 50, 45, 40, 30, 20, 10, 0, -10}, |
niimurasyou | 1:e1e9671724e7 | 71 | {80, 71, 70, 60, 55, 50, 45, 40, 35, 30, 20, 10, 0, -10, -13}, |
niimurasyou | 1:e1e9671724e7 | 72 | {60, 60, 57, 50, 45, 40, 35, 30, 25, 20, 10, 0, -10, -13, -17}, |
niimurasyou | 1:e1e9671724e7 | 73 | {50, 50, 50, 40, 35, 30, 23, 20, 15, 10, 0, -10, -15, -17, -20}, |
niimurasyou | 1:e1e9671724e7 | 74 | {45, 45, 43, 35, 30, 25, 10, 10, 10, 0, -10, -15, -20, -20, -25}, |
niimurasyou | 1:e1e9671724e7 | 75 | {40, 37, 35, 30, 25, 20, 0, 0, 0, -10, -15, -20, -25, -25, -30}, |
niimurasyou | 1:e1e9671724e7 | 76 | {35, 30, 30, 25, 20, 15, 0, 0, 0, -15, -20, -25, -30, -30, -35}, |
niimurasyou | 1:e1e9671724e7 | 77 | {30, 25, 25, 20, 15, 10, 0, 0, 0, -20, -25, -30, -35, -37, -40}, |
niimurasyou | 1:e1e9671724e7 | 78 | {20, 17, 15, 10, 0, -10, -15,-20, -23, -30,-35,-40,-50,-50, -50}, |
niimurasyou | 1:e1e9671724e7 | 79 | {17, 13, 10, 0, -10, -20, -25,-30, -35, -40,-45,-50,-57,-60, -60}, |
niimurasyou | 1:e1e9671724e7 | 80 | {13, 10, 0, -10, -20, -30, -35,-40, -45, -50,-55,-60, -70, -71, -80}, |
niimurasyou | 1:e1e9671724e7 | 81 | {10, 0, -10, -20, -30, -40, -45,-50, -55, -60,-65,-70,-75,-80, -80}, |
niimurasyou | 1:e1e9671724e7 | 82 | {0, -10, -20, -30, -40, -50, -60,-70, -71, -72,-75,-77,-80,-80, -80}, |
niimurasyou | 1:e1e9671724e7 | 83 | {0, -10, -20, -30, -40, -50, -60,-70, -71, -72,-75,-77,-80,-80, -80} |
niimurasyou | 1:e1e9671724e7 | 84 | }; |
niimurasyou | 1:e1e9671724e7 | 85 | |
niimurasyou | 1:e1e9671724e7 | 86 | int c_array[15][15] = { |
niimurasyou | 1:e1e9671724e7 | 87 | {0, 10, 20, 30, 40, 50, 60,70, 71, 72, 75, 77, 80, 80, 80}, |
niimurasyou | 1:e1e9671724e7 | 88 | {-10, 0, 10, 20, 30, 40, 45,50, 55, 60,65,70,75,80,80}, |
niimurasyou | 1:e1e9671724e7 | 89 | {-13, -10, 0, 10, 20, 30, 35,40, 45, 50,55,60,70,71,80}, |
niimurasyou | 1:e1e9671724e7 | 90 | {-17, -13, -10, 0, 10, 20, 25,30, 35, 40,45,50,57,60,60}, |
niimurasyou | 1:e1e9671724e7 | 91 | {-20, -17, -15, -10, 0, 10, 15,20, 23, 30,35,40,50,50,50}, |
niimurasyou | 1:e1e9671724e7 | 92 | {-25, -20, -20, -15, -10, 0, 10,10, 10, 25,30,35,43,45,45}, |
niimurasyou | 1:e1e9671724e7 | 93 | {-30, -25, -25, -20, -15, -10, 0,0, 0, 20,25,30,35,37,40}, |
niimurasyou | 1:e1e9671724e7 | 94 | {-35, -30, -30, -25, -20, -15, 0,0, 0, 15,20,25,30,30,35}, |
niimurasyou | 1:e1e9671724e7 | 95 | {-40, -37, -35, -30, -25, -20, 0,0, 0, 10,15,20,25,25,30}, |
niimurasyou | 1:e1e9671724e7 | 96 | {-50, -50, -50, -40, -35, -30, -23,-20, -15, -10,0,10,15,17,20}, |
niimurasyou | 1:e1e9671724e7 | 97 | {-60, -60, -57, -50, -45, -40, -35,-30, -25, -20,-10,0,10,13,17}, |
niimurasyou | 1:e1e9671724e7 | 98 | {-80, -71, -70, -60, -55, -50, -45,-40, -35, -30,-20,-10,0,10,13}, |
niimurasyou | 1:e1e9671724e7 | 99 | {-80, -80, -75, -70, -65, -60, -55,-50, -45, -40,-30,-20,-10,0,10}, |
niimurasyou | 1:e1e9671724e7 | 100 | {-80, -80, -80, -77, -75, -72, -71,-70, -60, -50,-40,-30,-20,-10,0}, |
niimurasyou | 1:e1e9671724e7 | 101 | {-80, -80, -80, -77, -75, -72, -71,-70, -60, -50,-40,-30,-20,-10,0} |
niimurasyou | 1:e1e9671724e7 | 102 | }; |
niimurasyou | 1:e1e9671724e7 | 103 | |
niimurasyou | 1:e1e9671724e7 | 104 | |
niimurasyou | 1:e1e9671724e7 | 105 | |
niimurasyou | 1:e1e9671724e7 | 106 | |
niimurasyou | 1:e1e9671724e7 | 107 | |
niimurasyou | 1:e1e9671724e7 | 108 | |
niimurasyou | 1:e1e9671724e7 | 109 | #define usiro 0 |
niimurasyou | 1:e1e9671724e7 | 110 | #define mae 0 |
niimurasyou | 1:e1e9671724e7 | 111 | uint8_t motorData[5]; |
niimurasyou | 1:e1e9671724e7 | 112 | uint8_t pwmData[5]; |
niimurasyou | 1:e1e9671724e7 | 113 | |
niimurasyou | 1:e1e9671724e7 | 114 | int conlx; |
niimurasyou | 1:e1e9671724e7 | 115 | int conly; |
niimurasyou | 1:e1e9671724e7 | 116 | int conrx; |
niimurasyou | 1:e1e9671724e7 | 117 | int conry; |
niimurasyou | 1:e1e9671724e7 | 118 | |
niimurasyou | 1:e1e9671724e7 | 119 | int mode=1; |
niimurasyou | 1:e1e9671724e7 | 120 | |
niimurasyou | 1:e1e9671724e7 | 121 | //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ |
niimurasyou | 1:e1e9671724e7 | 122 | //_____________________ |
niimurasyou | 1:e1e9671724e7 | 123 | |
niimurasyou | 1:e1e9671724e7 | 124 | //#define USE_USB_SERIAL |
M_souta | 0:2e7a61458dc3 | 125 | #ifdef USE_USB_SERIAL |
niimurasyou | 1:e1e9671724e7 | 126 | Serial pc(SERIAL_TX, SERIAL_RX); |
M_souta | 0:2e7a61458dc3 | 127 | #endif |
M_souta | 0:2e7a61458dc3 | 128 | XBEE::ControllerData *controller; |
M_souta | 0:2e7a61458dc3 | 129 | MOTOR::MotorStatus motor[MOUNTING_MOTOR_NUM]; |
M_souta | 0:2e7a61458dc3 | 130 | |
M_souta | 0:2e7a61458dc3 | 131 | using namespace SWITCH; |
M_souta | 0:2e7a61458dc3 | 132 | |
niimurasyou | 1:e1e9671724e7 | 133 | void SystemProcess(void) |
niimurasyou | 1:e1e9671724e7 | 134 | { |
niimurasyou | 1:e1e9671724e7 | 135 | while(true) { |
M_souta | 0:2e7a61458dc3 | 136 | controller = XBEE::Controller::GetData(); |
niimurasyou | 1:e1e9671724e7 | 137 | //____________________________ |
niimurasyou | 1:e1e9671724e7 | 138 | /*------------------------ HOW TO WRITE ------------------------/ |
niimurasyou | 1:e1e9671724e7 | 139 | |
niimurasyou | 1:e1e9671724e7 | 140 | ここにメインのプログラムを書く |
niimurasyou | 1:e1e9671724e7 | 141 | |
niimurasyou | 1:e1e9671724e7 | 142 | ・コントローラから受け取ったデータをもとに動作のプログラムを書く |
niimurasyou | 1:e1e9671724e7 | 143 | (コントローラのデータは controller-> で取る) |
niimurasyou | 1:e1e9671724e7 | 144 | |
niimurasyou | 1:e1e9671724e7 | 145 | if(controller->Button.RIGHT) { |
niimurasyou | 1:e1e9671724e7 | 146 | motor[TIRE_L].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 147 | motor[TIRE_R].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 148 | motor[TIRE_L].pwm = 12.3; |
niimurasyou | 1:e1e9671724e7 | 149 | motor[TIRE_R].pwm = 12.3; |
niimurasyou | 1:e1e9671724e7 | 150 | } |
niimurasyou | 1:e1e9671724e7 | 151 | |
niimurasyou | 1:e1e9671724e7 | 152 | motor[0].dirは FOR (正転) |
niimurasyou | 1:e1e9671724e7 | 153 | BACK (逆転) |
niimurasyou | 1:e1e9671724e7 | 154 | BRAKE (ブレーキ) |
niimurasyou | 1:e1e9671724e7 | 155 | FREE (フリー) |
niimurasyou | 1:e1e9671724e7 | 156 | |
niimurasyou | 1:e1e9671724e7 | 157 | motor[0].pwmは 0.0(%) ~ 100.0(%) |
niimurasyou | 1:e1e9671724e7 | 158 | |
niimurasyou | 1:e1e9671724e7 | 159 | controllerは XBee.hの構造体の中身 |
niimurasyou | 1:e1e9671724e7 | 160 | |
niimurasyou | 1:e1e9671724e7 | 161 | (AnalogL・Rを使いたかったら、頑張って考える or 聞いてください) |
niimurasyou | 1:e1e9671724e7 | 162 | |
niimurasyou | 1:e1e9671724e7 | 163 | ・リミットスイッチの値をもとに動作のプログラムを書く |
niimurasyou | 1:e1e9671724e7 | 164 | |
niimurasyou | 1:e1e9671724e7 | 165 | if(Switch::CheckPushed(ARM_L)) |
niimurasyou | 1:e1e9671724e7 | 166 | { |
niimurasyou | 1:e1e9671724e7 | 167 | if(controller->Button.L) |
niimurasyou | 1:e1e9671724e7 | 168 | { |
niimurasyou | 1:e1e9671724e7 | 169 | motor[ARM].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 170 | motor[ARM].pwm = 80.0; |
niimurasyou | 1:e1e9671724e7 | 171 | } |
niimurasyou | 1:e1e9671724e7 | 172 | if(motor[ARM].dir == BACK) |
niimurasyou | 1:e1e9671724e7 | 173 | { |
niimurasyou | 1:e1e9671724e7 | 174 | motor[ARM].dir = BRAKE; |
niimurasyou | 1:e1e9671724e7 | 175 | } |
niimurasyou | 1:e1e9671724e7 | 176 | } |
niimurasyou | 1:e1e9671724e7 | 177 | |
niimurasyou | 1:e1e9671724e7 | 178 | →関数 Switch::CheckPushed の引数はリミットスイッチの名前 (limitSw[0]みたいな), 返り値はbool型 (true or false) |
niimurasyou | 1:e1e9671724e7 | 179 | |
niimurasyou | 1:e1e9671724e7 | 180 | ・他にもやりたいことがあったら自由にどうぞ |
M_souta | 0:2e7a61458dc3 | 181 | |
niimurasyou | 1:e1e9671724e7 | 182 | ps.わからないことがあったら聞いてください |
niimurasyou | 1:e1e9671724e7 | 183 | |
niimurasyou | 1:e1e9671724e7 | 184 | /------------------------ HOW TO WRITE ------------------------*/ |
niimurasyou | 1:e1e9671724e7 | 185 | //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ |
niimurasyou | 1:e1e9671724e7 | 186 | |
niimurasyou | 1:e1e9671724e7 | 187 | conlx = controller->AnalogL.X; |
niimurasyou | 1:e1e9671724e7 | 188 | conly = controller->AnalogL.Y; |
niimurasyou | 1:e1e9671724e7 | 189 | conrx = controller->AnalogR.X; |
niimurasyou | 1:e1e9671724e7 | 190 | conry = controller->AnalogR.Y; |
niimurasyou | 1:e1e9671724e7 | 191 | //conba = controller->Button.A; |
niimurasyou | 1:e1e9671724e7 | 192 | //conbb = controller->Button.B; |
niimurasyou | 1:e1e9671724e7 | 193 | //conby = controller->Button.Y; |
niimurasyou | 1:e1e9671724e7 | 194 | //conbx = controller->Button.X; |
niimurasyou | 1:e1e9671724e7 | 195 | |
niimurasyou | 1:e1e9671724e7 | 196 | if(a_array[conly][conlx]<0) { |
niimurasyou | 1:e1e9671724e7 | 197 | motor[a].pwm = (-1*a_array[conly][conlx]*100)/80; |
niimurasyou | 1:e1e9671724e7 | 198 | motor[a].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 199 | } else if(a_array[conly][conlx] > 0) { |
niimurasyou | 1:e1e9671724e7 | 200 | motor[a].pwm = (a_array[conly][conlx]*100)/80; |
niimurasyou | 1:e1e9671724e7 | 201 | motor[a].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 202 | } else if(a_array[conly][conlx] == 0) { |
niimurasyou | 1:e1e9671724e7 | 203 | if(conry < 6) { |
niimurasyou | 1:e1e9671724e7 | 204 | motor[a].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 205 | motor[b].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 206 | motor[c].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 207 | motor[a].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 208 | motor[b].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 209 | motor[c].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 210 | } else if(conry > 8) { |
niimurasyou | 1:e1e9671724e7 | 211 | motor[a].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 212 | motor[b].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 213 | motor[c].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 214 | motor[a].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 215 | motor[b].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 216 | motor[c].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 217 | } else { |
niimurasyou | 1:e1e9671724e7 | 218 | motor[a].dir = BRAKE; |
niimurasyou | 1:e1e9671724e7 | 219 | motor[b].dir = BRAKE; |
niimurasyou | 1:e1e9671724e7 | 220 | motor[c].dir = BRAKE; |
niimurasyou | 1:e1e9671724e7 | 221 | motor[a].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 222 | motor[b].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 223 | motor[c].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 224 | } |
niimurasyou | 1:e1e9671724e7 | 225 | } |
M_souta | 0:2e7a61458dc3 | 226 | |
niimurasyou | 1:e1e9671724e7 | 227 | if(b_array[conly][conlx] <0 ) { |
niimurasyou | 1:e1e9671724e7 | 228 | motor[b].pwm = (-1*b_array[conly][conlx]*100)/80; |
niimurasyou | 1:e1e9671724e7 | 229 | motor[b].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 230 | } else if(b_array[conly][conlx] > 0) { |
niimurasyou | 1:e1e9671724e7 | 231 | motor[b].pwm = (b_array[conly][conlx]*100)/80; |
niimurasyou | 1:e1e9671724e7 | 232 | motor[b].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 233 | } else if(a_array[conly][conlx] == 0 ) { |
niimurasyou | 1:e1e9671724e7 | 234 | if(conrx < 6 ) { |
niimurasyou | 1:e1e9671724e7 | 235 | motor[a].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 236 | motor[b].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 237 | motor[c].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 238 | motor[a].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 239 | motor[b].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 240 | motor[c].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 241 | } else if(conrx > 8) { |
niimurasyou | 1:e1e9671724e7 | 242 | motor[a].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 243 | motor[b].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 244 | motor[c].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 245 | motor[a].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 246 | motor[b].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 247 | motor[c].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 248 | } else { |
niimurasyou | 1:e1e9671724e7 | 249 | motor[a].dir = BRAKE; |
niimurasyou | 1:e1e9671724e7 | 250 | motor[b].dir = BRAKE; |
niimurasyou | 1:e1e9671724e7 | 251 | motor[c].dir = BRAKE; |
niimurasyou | 1:e1e9671724e7 | 252 | motor[a].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 253 | motor[b].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 254 | motor[c].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 255 | } |
niimurasyou | 1:e1e9671724e7 | 256 | } |
niimurasyou | 1:e1e9671724e7 | 257 | |
niimurasyou | 1:e1e9671724e7 | 258 | if(c_array[conly][conlx] <0 ) { |
niimurasyou | 1:e1e9671724e7 | 259 | motor[c].pwm =(-1*c_array[conly][conlx]*100)/80; |
niimurasyou | 1:e1e9671724e7 | 260 | motor[c].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 261 | } else if(c_array[conly][conlx] > 0) { |
niimurasyou | 1:e1e9671724e7 | 262 | motor[c].pwm =(c_array[conly][conlx]*100)/80; |
niimurasyou | 1:e1e9671724e7 | 263 | motor[c].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 264 | } else if(a_array[conly][conlx] == 0 ) { |
niimurasyou | 1:e1e9671724e7 | 265 | if(conrx < 6 ) { |
niimurasyou | 1:e1e9671724e7 | 266 | motor[a].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 267 | motor[b].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 268 | motor[c].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 269 | motor[a].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 270 | motor[b].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 271 | motor[c].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 272 | } else if(conrx > 8) { |
niimurasyou | 1:e1e9671724e7 | 273 | motor[a].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 274 | motor[b].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 275 | motor[c].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 276 | motor[a].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 277 | motor[b].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 278 | motor[c].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 279 | } else { |
niimurasyou | 1:e1e9671724e7 | 280 | motor[a].dir = BRAKE; |
niimurasyou | 1:e1e9671724e7 | 281 | motor[b].dir = BRAKE; |
niimurasyou | 1:e1e9671724e7 | 282 | motor[c].dir = BRAKE; |
niimurasyou | 1:e1e9671724e7 | 283 | motor[a].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 284 | motor[b].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 285 | motor[c].pwm = 100.0; |
niimurasyou | 1:e1e9671724e7 | 286 | } |
niimurasyou | 1:e1e9671724e7 | 287 | } |
M_souta | 0:2e7a61458dc3 | 288 | |
niimurasyou | 1:e1e9671724e7 | 289 | ////////////課題1//////////// |
niimurasyou | 1:e1e9671724e7 | 290 | if(controller->Button.X) { |
niimurasyou | 1:e1e9671724e7 | 291 | if(Switch::CheckPushed(ARMlim)) { |
niimurasyou | 1:e1e9671724e7 | 292 | motor[d].dir = BRAKE; |
niimurasyou | 1:e1e9671724e7 | 293 | motor[d].pwm = 100; |
niimurasyou | 1:e1e9671724e7 | 294 | } else { |
niimurasyou | 1:e1e9671724e7 | 295 | motor[d].dir = FOR; |
niimurasyou | 1:e1e9671724e7 | 296 | motor[d].pwm = 100; |
niimurasyou | 1:e1e9671724e7 | 297 | } |
niimurasyou | 1:e1e9671724e7 | 298 | } else if(controller->Button.Y) { |
niimurasyou | 1:e1e9671724e7 | 299 | motor[d].dir = BACK; |
niimurasyou | 1:e1e9671724e7 | 300 | motor[d].pwm = 100; |
niimurasyou | 1:e1e9671724e7 | 301 | } else { |
niimurasyou | 1:e1e9671724e7 | 302 | motor[d].dir = BRAKE; |
niimurasyou | 1:e1e9671724e7 | 303 | motor[d].pwm = 100; |
niimurasyou | 1:e1e9671724e7 | 304 | } |
niimurasyou | 1:e1e9671724e7 | 305 | if(controller->Button.A) { |
niimurasyou | 1:e1e9671724e7 | 306 | AirOut(Air0,1); |
niimurasyou | 1:e1e9671724e7 | 307 | } else if(controller->Button.B) { |
niimurasyou | 1:e1e9671724e7 | 308 | AirOut(Air0,0); |
niimurasyou | 1:e1e9671724e7 | 309 | } |
niimurasyou | 1:e1e9671724e7 | 310 | //////////////課題2///////////////////// |
niimurasyou | 1:e1e9671724e7 | 311 | s=Airtime.read(); |
niimurasyou | 1:e1e9671724e7 | 312 | if((controller->Button.ZL)&&(mode==1)) { |
niimurasyou | 1:e1e9671724e7 | 313 | mode=2; |
niimurasyou | 1:e1e9671724e7 | 314 | Airtime.start(); |
niimurasyou | 1:e1e9671724e7 | 315 | } |
niimurasyou | 1:e1e9671724e7 | 316 | if((mode==2)&&(s>=1)) { |
niimurasyou | 1:e1e9671724e7 | 317 | mode=3; |
niimurasyou | 1:e1e9671724e7 | 318 | } |
niimurasyou | 1:e1e9671724e7 | 319 | if((mode==3)&&(s>=3)) { |
niimurasyou | 1:e1e9671724e7 | 320 | mode=4; |
niimurasyou | 1:e1e9671724e7 | 321 | } |
niimurasyou | 1:e1e9671724e7 | 322 | if((mode==4)&&(!(Switch::CheckPushed(lim)))) { |
niimurasyou | 1:e1e9671724e7 | 323 | mode=5; |
niimurasyou | 1:e1e9671724e7 | 324 | Airtime.stop(); |
niimurasyou | 1:e1e9671724e7 | 325 | Airtime.reset(); |
niimurasyou | 1:e1e9671724e7 | 326 | } |
niimurasyou | 1:e1e9671724e7 | 327 | if((mode==5)&&(Switch::CheckPushed(lim))) { |
niimurasyou | 1:e1e9671724e7 | 328 | mode=1; |
niimurasyou | 1:e1e9671724e7 | 329 | } |
niimurasyou | 1:e1e9671724e7 | 330 | |
niimurasyou | 1:e1e9671724e7 | 331 | if(mode==1) { |
niimurasyou | 1:e1e9671724e7 | 332 | AirOut(1,1); |
niimurasyou | 1:e1e9671724e7 | 333 | motor[4].dir=BRAKE; |
niimurasyou | 1:e1e9671724e7 | 334 | motor[4].pwm=100; |
niimurasyou | 1:e1e9671724e7 | 335 | } else if(mode==2) { |
niimurasyou | 1:e1e9671724e7 | 336 | AirOut(1,0); |
niimurasyou | 1:e1e9671724e7 | 337 | } else if(mode==3) { |
niimurasyou | 1:e1e9671724e7 | 338 | AirOut(1,1); |
niimurasyou | 1:e1e9671724e7 | 339 | } else if(mode==4) { |
niimurasyou | 1:e1e9671724e7 | 340 | motor[4].dir=FOR; |
niimurasyou | 1:e1e9671724e7 | 341 | motor[4].pwm=50; |
niimurasyou | 1:e1e9671724e7 | 342 | } else if(mode==5) { |
niimurasyou | 1:e1e9671724e7 | 343 | motor[4].dir=FOR; |
niimurasyou | 1:e1e9671724e7 | 344 | motor[4].pwm=50; |
niimurasyou | 1:e1e9671724e7 | 345 | } else { |
niimurasyou | 1:e1e9671724e7 | 346 | mode=1; |
niimurasyou | 1:e1e9671724e7 | 347 | AirOut(1,1); |
niimurasyou | 1:e1e9671724e7 | 348 | } |
niimurasyou | 1:e1e9671724e7 | 349 | if(controller->Button.L) { |
niimurasyou | 1:e1e9671724e7 | 350 | motor[4].dir=FOR; |
niimurasyou | 1:e1e9671724e7 | 351 | motor[4].pwm=10; |
niimurasyou | 1:e1e9671724e7 | 352 | } |
niimurasyou | 1:e1e9671724e7 | 353 | //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ |
niimurasyou | 1:e1e9671724e7 | 354 | //___________________________ |
M_souta | 0:2e7a61458dc3 | 355 | |
M_souta | 0:2e7a61458dc3 | 356 | |
niimurasyou | 1:e1e9671724e7 | 357 | |
M_souta | 0:2e7a61458dc3 | 358 | MOTOR::Motor::Update(motor); |
M_souta | 0:2e7a61458dc3 | 359 | } |
niimurasyou | 1:e1e9671724e7 | 360 | } |