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