Taiki Maruyama
/
charyaaaaaaaaa
kaahddhgfhgfghgf
System/Process/Process.cpp@11:de0dc9fba6c9, 2019-02-23 (annotated)
- Committer:
- kishibekairohan
- Date:
- Sat Feb 23 05:39:54 2019 +0000
- Revision:
- 11:de0dc9fba6c9
- Parent:
- 10:a81546661fb5
- Child:
- 12:419fc52505ee
aaa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
t_yamamoto | 8:cb53beff4bb2 | 1 | //2018/02/24のやつ |
t_yamamoto | 5:a802ab60df1b | 2 | |
t_yamamoto | 0:562021ed1ba9 | 3 | #include "Process.h" |
t_yamamoto | 0:562021ed1ba9 | 4 | |
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 | ・リミットスイッチの割り当てを決める |
takayama_ryo | 9:49e851ad441e | 18 | #define 0_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 | |
kishibekairohan | 10:a81546661fb5 | 25 | #define TIRE_LF |
takayama_ryo | 9:49e851ad441e | 26 | #define TIRE_LB 1 |
takayama_ryo | 9:49e851ad441e | 27 | #define TIRE_RB 2 |
takayama_ryo | 9:49e851ad441e | 28 | #define TIRE_RF 3 |
takayama_ryo | 9:49e851ad441e | 29 | #define ARM_M 4 |
takayama_ryo | 9:49e851ad441e | 30 | |
takayama_ryo | 9:49e851ad441e | 31 | #define Air1_pin A7 |
takayama_ryo | 9:49e851ad441e | 32 | #define Air2_pin A6 |
takayama_ryo | 9:49e851ad441e | 33 | #define Air3_pin A5 |
kishibekairohan | 10:a81546661fb5 | 34 | #define ARM_T 3 |
takayama_ryo | 9:49e851ad441e | 35 | |
kishibekairohan | 11:de0dc9fba6c9 | 36 | |
kishibekairohan | 10:a81546661fb5 | 37 | const int omni[15][15]= { |
takayama_ryo | 9:49e851ad441e | 38 | { 0, 2, 6, 15, 26, 41, 59, 80, 80, 80, 80, 80, 80, 80, 80}, |
takayama_ryo | 9:49e851ad441e | 39 | { -2, 0, 2, 6, 15, 26, 41, 59, 61, 65, 73, 80, 80, 80, 80}, |
takayama_ryo | 9:49e851ad441e | 40 | { -6, -2, 0, 2, 6, 15, 26, 41, 43, 47, 56, 67, 80, 80, 80}, |
takayama_ryo | 9:49e851ad441e | 41 | { -15, -6, -2, 0, 2, 6, 15, 26, 28, 33, 41, 52, 67, 80, 80}, |
takayama_ryo | 9:49e851ad441e | 42 | { -26, -15, -6, -2, 0, 2, 6, 15, 17, 21, 29, 41, 56, 73, 80}, |
takayama_ryo | 9:49e851ad441e | 43 | { -41, -26, -15, -6, -2, 0, 2, 6, 8, 13, 21, 33, 48, 65, 80}, |
takayama_ryo | 9:49e851ad441e | 44 | { -59, -41, -26, -15, -6, -2, 0, 2, 4, 8, 16, 28, 42, 61, 80}, |
takayama_ryo | 9:49e851ad441e | 45 | { -80, -59, -41, -26, -15, -6, -2, 0, 2, 6, 15, 26, 41, 59, 80}, |
takayama_ryo | 9:49e851ad441e | 46 | { -80, -61, -42, -28, -16, -8, -4, -2, 0, 2, 6, 15, 26, 41, 59}, |
takayama_ryo | 9:49e851ad441e | 47 | { -80, -65, -48, -33, -21, -13, -8, -6, -2, 0, 2, 6, 15, 26, 41}, |
takayama_ryo | 9:49e851ad441e | 48 | { -80, -73, -56, -41, -29, -21, -17, -15, -6, -2, 0, 2, 6, 15, 26}, |
takayama_ryo | 9:49e851ad441e | 49 | { -80, -80, -67, -52, -41, -33, -28, -26, -15, -6, -2, 0, 2, 6, 15}, |
takayama_ryo | 9:49e851ad441e | 50 | { -80, -80, -80, -67, -56, -47, -43, -41, -26, -15, -6, -2, 0, 2, 6}, |
takayama_ryo | 9:49e851ad441e | 51 | { -80, -80, -80, -80, -73, -65, -61, -59, -41, -26, -15, -6, -2, 0, 2}, |
takayama_ryo | 9:49e851ad441e | 52 | { -80, -80, -80, -80, -80, -80, -80, -80, -59, -41, -26, -15, -6, -2, 0} |
takayama_ryo | 9:49e851ad441e | 53 | }; |
takayama_ryo | 9:49e851ad441e | 54 | |
takayama_ryo | 9:49e851ad441e | 55 | const int curve[15] = {-64, -47, -33, -21, -12, -5, -1, 0, 1, 5, 12, 21, 33, 47, 64}; |
t_yamamoto | 0:562021ed1ba9 | 56 | |
t_yamamoto | 0:562021ed1ba9 | 57 | |
t_yamamoto | 0:562021ed1ba9 | 58 | |
takayama_ryo | 9:49e851ad441e | 59 | uint8_t SetStatus(int); |
kishibekairohan | 10:a81546661fb5 | 60 | uint8_t SetStatus(int pwmVal) |
kishibekairohan | 10:a81546661fb5 | 61 | { |
takayama_ryo | 9:49e851ad441e | 62 | if(pwmVal < 0) return BACK; |
takayama_ryo | 9:49e851ad441e | 63 | else if(pwmVal > 0) return FOR; |
takayama_ryo | 9:49e851ad441e | 64 | else if(pwmVal == 0) return BRAKE; |
takayama_ryo | 9:49e851ad441e | 65 | } |
takayama_ryo | 9:49e851ad441e | 66 | uint8_t SetPWM(int); |
kishibekairohan | 10:a81546661fb5 | 67 | uint8_t SetPWM(int pwmVal) |
kishibekairohan | 10:a81546661fb5 | 68 | { |
takayama_ryo | 9:49e851ad441e | 69 | if(pwmVal == 0 || pwmVal > 80 || pwmVal < -80) return 80; |
takayama_ryo | 9:49e851ad441e | 70 | else return abs(pwmVal); |
takayama_ryo | 9:49e851ad441e | 71 | } |
t_yamamoto | 0:562021ed1ba9 | 72 | |
t_yamamoto | 0:562021ed1ba9 | 73 | //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ |
t_yamamoto | 0:562021ed1ba9 | 74 | //_____________________ |
t_yamamoto | 0:562021ed1ba9 | 75 | |
t_yamamoto | 8:cb53beff4bb2 | 76 | //#define USE_USB_SERIAL |
t_yamamoto | 0:562021ed1ba9 | 77 | #ifdef USE_USB_SERIAL |
t_yamamoto | 0:562021ed1ba9 | 78 | Serial pc(SERIAL_TX, SERIAL_RX); |
t_yamamoto | 0:562021ed1ba9 | 79 | #endif |
t_yamamoto | 0:562021ed1ba9 | 80 | XBEE::ControllerData *controller; |
t_yamamoto | 0:562021ed1ba9 | 81 | MOTOR::MotorStatus motor[MOUNTING_MOTOR_NUM]; |
t_yamamoto | 0:562021ed1ba9 | 82 | |
takayama_ryo | 9:49e851ad441e | 83 | |
takayama_ryo | 9:49e851ad441e | 84 | |
t_yamamoto | 0:562021ed1ba9 | 85 | using namespace SWITCH; |
takayama_ryo | 9:49e851ad441e | 86 | ///////////////////////////////// |
takayama_ryo | 9:49e851ad441e | 87 | DigitalOut AirPin[] = { |
takayama_ryo | 9:49e851ad441e | 88 | DigitalOut(Air1_pin), |
takayama_ryo | 9:49e851ad441e | 89 | DigitalOut(Air2_pin), |
takayama_ryo | 9:49e851ad441e | 90 | DigitalOut(Air3_pin), |
takayama_ryo | 9:49e851ad441e | 91 | }; |
t_yamamoto | 0:562021ed1ba9 | 92 | |
kishibekairohan | 10:a81546661fb5 | 93 | void AirOut(int pin,int mode) |
kishibekairohan | 10:a81546661fb5 | 94 | { |
kishibekairohan | 10:a81546661fb5 | 95 | if(mode==1) { |
takayama_ryo | 9:49e851ad441e | 96 | AirPin[pin]=1; |
kishibekairohan | 10:a81546661fb5 | 97 | } else if(mode==0) { |
takayama_ryo | 9:49e851ad441e | 98 | AirPin[pin]=0; |
kishibekairohan | 10:a81546661fb5 | 99 | } else { |
kishibekairohan | 10:a81546661fb5 | 100 | AirPin[pin]=0; |
takayama_ryo | 9:49e851ad441e | 101 | } |
takayama_ryo | 9:49e851ad441e | 102 | } |
takayama_ryo | 9:49e851ad441e | 103 | ////////////////////////////////// |
kishibekairohan | 10:a81546661fb5 | 104 | void SystemProcess(void) |
kishibekairohan | 10:a81546661fb5 | 105 | { |
t_yamamoto | 0:562021ed1ba9 | 106 | while(true) { |
t_yamamoto | 0:562021ed1ba9 | 107 | controller = XBEE::Controller::GetData(); |
t_yamamoto | 0:562021ed1ba9 | 108 | //____________________________ |
kishibekairohan | 10:a81546661fb5 | 109 | /*------------------------ HOW TO WRITE ------------------------/ |
t_yamamoto | 0:562021ed1ba9 | 110 | |
kishibekairohan | 10:a81546661fb5 | 111 | ここにメインのプログラムを書く |
t_yamamoto | 0:562021ed1ba9 | 112 | |
kishibekairohan | 10:a81546661fb5 | 113 | ・コントローラから受け取ったデータをもとに動作のプログラムを書く |
kishibekairohan | 10:a81546661fb5 | 114 | (コントローラのデータは controller-> で取る) |
t_yamamoto | 0:562021ed1ba9 | 115 | |
kishibekairohan | 10:a81546661fb5 | 116 | if(controller->Button.RIGHT) { |
kishibekairohan | 10:a81546661fb5 | 117 | motor[TIRE_L].dir = FOR; |
kishibekairohan | 10:a81546661fb5 | 118 | motor[TIRE_R].dir = BACK; |
kishibekairohan | 10:a81546661fb5 | 119 | motor[TIRE_L].pwm = 12.3; |
kishibekairohan | 10:a81546661fb5 | 120 | motor[TIRE_R].pwm = 12.3; |
kishibekairohan | 10:a81546661fb5 | 121 | } |
t_yamamoto | 0:562021ed1ba9 | 122 | |
kishibekairohan | 10:a81546661fb5 | 123 | motor[0].dirは FOR (正転) |
kishibekairohan | 10:a81546661fb5 | 124 | BACK (逆転) |
kishibekairohan | 10:a81546661fb5 | 125 | BRAKE (ブレーキ) |
kishibekairohan | 10:a81546661fb5 | 126 | FREE (フリー) |
kishibekairohan | 10:a81546661fb5 | 127 | |
kishibekairohan | 10:a81546661fb5 | 128 | motor[0].pwmは 0.0(%) ~ 100.0(%) |
kishibekairohan | 10:a81546661fb5 | 129 | |
kishibekairohan | 10:a81546661fb5 | 130 | controllerは XBee.hの構造体の中身 |
kishibekairohan | 10:a81546661fb5 | 131 | |
kishibekairohan | 10:a81546661fb5 | 132 | (AnalogL・Rを使いたかったら、頑張って考える or 聞いてください) |
kishibekairohan | 10:a81546661fb5 | 133 | |
kishibekairohan | 10:a81546661fb5 | 134 | ・リミットスイッチの値をもとに動作のプログラムを書く |
t_yamamoto | 0:562021ed1ba9 | 135 | |
kishibekairohan | 10:a81546661fb5 | 136 | if(Switch::CheckPushed(0_L)) |
kishibekairohan | 10:a81546661fb5 | 137 | { |
kishibekairohan | 10:a81546661fb5 | 138 | if(controller->Button.L) |
kishibekairohan | 10:a81546661fb5 | 139 | { |
kishibekairohan | 10:a81546661fb5 | 140 | motor[0].dir = FOR; |
kishibekairohan | 10:a81546661fb5 | 141 | motor[0].pwm = 80.0; |
kishibekairohan | 10:a81546661fb5 | 142 | } |
kishibekairohan | 10:a81546661fb5 | 143 | if(motor[0].dir == BACK) |
kishibekairohan | 10:a81546661fb5 | 144 | { |
kishibekairohan | 10:a81546661fb5 | 145 | motor[0].dir = BRAKE; |
kishibekairohan | 10:a81546661fb5 | 146 | } |
kishibekairohan | 10:a81546661fb5 | 147 | } |
t_yamamoto | 0:562021ed1ba9 | 148 | |
kishibekairohan | 10:a81546661fb5 | 149 | →関数 Switch::CheckPushed の引数はリミットスイッチの名前 (limitSw[0]みたいな), 返り値はbool型 (true or false) |
kishibekairohan | 10:a81546661fb5 | 150 | |
kishibekairohan | 10:a81546661fb5 | 151 | ・他にもやりたいことがあったら自由にどうぞ |
kishibekairohan | 10:a81546661fb5 | 152 | |
kishibekairohan | 10:a81546661fb5 | 153 | ps.わからないことがあったら聞いてください |
kishibekairohan | 10:a81546661fb5 | 154 | |
kishibekairohan | 10:a81546661fb5 | 155 | /------------------------ HOW TO WRITE ------------------------*/ |
kishibekairohan | 10:a81546661fb5 | 156 | //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ |
kishibekairohan | 10:a81546661fb5 | 157 | |
kishibekairohan | 10:a81546661fb5 | 158 | |
kishibekairohan | 10:a81546661fb5 | 159 | if(controller->AnalogL.X >= 6 && controller->AnalogL.X <= 8 && controller->AnalogL.Y >= 6 && controller->AnalogL.Y <= 8) { |
kishibekairohan | 10:a81546661fb5 | 160 | motor[TIRE_LF].dir = FREE; |
kishibekairohan | 10:a81546661fb5 | 161 | motor[TIRE_LB].dir = FREE; |
kishibekairohan | 10:a81546661fb5 | 162 | motor[TIRE_RB].dir = FREE; |
kishibekairohan | 10:a81546661fb5 | 163 | motor[TIRE_RF].dir = FREE; |
t_yamamoto | 0:562021ed1ba9 | 164 | } |
t_yamamoto | 0:562021ed1ba9 | 165 | |
kishibekairohan | 10:a81546661fb5 | 166 | if(controller->AnalogR.X >= 6 && controller->AnalogR.X <= 8 && controller->AnalogR.Y >= 6 && controller->AnalogR.Y <= 8) { |
kishibekairohan | 10:a81546661fb5 | 167 | motor[TIRE_LF].dir = FREE; |
kishibekairohan | 10:a81546661fb5 | 168 | motor[TIRE_LB].dir = FREE; |
kishibekairohan | 10:a81546661fb5 | 169 | motor[TIRE_RB].dir = FREE; |
kishibekairohan | 10:a81546661fb5 | 170 | motor[TIRE_RF].dir = FREE; |
kishibekairohan | 10:a81546661fb5 | 171 | } |
kishibekairohan | 10:a81546661fb5 | 172 | |
kishibekairohan | 10:a81546661fb5 | 173 | motor[TIRE_RF].dir = SetStatus(-omni[controller->AnalogL.Y][14-controller->AnalogL.X] + curve[controller->AnalogR.X]); |
kishibekairohan | 10:a81546661fb5 | 174 | motor[TIRE_LF].dir = SetStatus(omni[controller->AnalogL.Y][controller->AnalogL.X] + curve[controller->AnalogR.X]); |
kishibekairohan | 10:a81546661fb5 | 175 | motor[TIRE_RB].dir = SetStatus(-omni[14-controller->AnalogL.X][14-controller->AnalogL.Y] + curve[controller->AnalogR.X]); |
kishibekairohan | 10:a81546661fb5 | 176 | motor[TIRE_LB].dir = SetStatus(omni[controller->AnalogL.X][14-controller->AnalogL.Y] + curve[controller->AnalogR.X]); |
t_yamamoto | 0:562021ed1ba9 | 177 | |
kishibekairohan | 10:a81546661fb5 | 178 | motor[TIRE_RF].pwm = SetPWM(omni[controller->AnalogL.Y][14-controller->AnalogL.X]) ; |
kishibekairohan | 10:a81546661fb5 | 179 | motor[TIRE_LF].pwm = SetPWM(omni[controller->AnalogL.Y][controller->AnalogL.X]) ; |
kishibekairohan | 10:a81546661fb5 | 180 | motor[TIRE_RB].pwm = SetPWM(omni[14-controller->AnalogL.X][14-controller->AnalogL.Y]) ; |
kishibekairohan | 10:a81546661fb5 | 181 | motor[TIRE_LB].pwm = SetPWM(omni[controller->AnalogL.X][14-controller->AnalogL.Y]) ; |
t_yamamoto | 0:562021ed1ba9 | 182 | |
kishibekairohan | 10:a81546661fb5 | 183 | if(controller->Button.R) { |
kishibekairohan | 10:a81546661fb5 | 184 | AirOut(0,1); |
kishibekairohan | 10:a81546661fb5 | 185 | } |
kishibekairohan | 10:a81546661fb5 | 186 | if(controller->Button.L) { |
kishibekairohan | 10:a81546661fb5 | 187 | AirOut(0,0); |
kishibekairohan | 10:a81546661fb5 | 188 | } |
t_yamamoto | 0:562021ed1ba9 | 189 | |
kishibekairohan | 10:a81546661fb5 | 190 | if(controller->Button.A) { |
kishibekairohan | 10:a81546661fb5 | 191 | AirOut(1,1); |
kishibekairohan | 10:a81546661fb5 | 192 | } |
kishibekairohan | 10:a81546661fb5 | 193 | if(controller->Button.B) { |
kishibekairohan | 10:a81546661fb5 | 194 | AirOut(1,0); |
kishibekairohan | 10:a81546661fb5 | 195 | } |
kishibekairohan | 10:a81546661fb5 | 196 | |
kishibekairohan | 10:a81546661fb5 | 197 | if(controller->Button.X) { |
kishibekairohan | 10:a81546661fb5 | 198 | AirOut(2,1); |
kishibekairohan | 10:a81546661fb5 | 199 | } |
kishibekairohan | 10:a81546661fb5 | 200 | if(controller->Button.Y) { |
kishibekairohan | 10:a81546661fb5 | 201 | AirOut(2,0); |
kishibekairohan | 10:a81546661fb5 | 202 | } |
kishibekairohan | 10:a81546661fb5 | 203 | |
kishibekairohan | 10:a81546661fb5 | 204 | if(controller->Button.UP) { |
kishibekairohan | 10:a81546661fb5 | 205 | if(Switch::checkPushed(ARM_T)){ |
kishibekairohan | 10:a81546661fb5 | 206 | motor[ARM_M].dir = BRAKE; |
kishibekairohan | 10:a81546661fb5 | 207 | motor[ARM_M].pwm = 50; |
kishibekairohan | 10:a81546661fb5 | 208 | }else{ |
kishibekairohan | 10:a81546661fb5 | 209 | motor[ARM_M].dir = BACK; |
kishibekairohan | 10:a81546661fb5 | 210 | motor[ARM_M].pwm = 50; |
kishibekairohan | 10:a81546661fb5 | 211 | } |
kishibekairohan | 10:a81546661fb5 | 212 | }else if(controller->Button.DOWN) { |
kishibekairohan | 10:a81546661fb5 | 213 | motor[ARM_M].dir = FOR; |
kishibekairohan | 10:a81546661fb5 | 214 | motor[ARM_M].pwm = 50; |
kishibekairohan | 10:a81546661fb5 | 215 | }else { |
kishibekairohan | 10:a81546661fb5 | 216 | motor[ARM_M].dir = FREE; |
kishibekairohan | 10:a81546661fb5 | 217 | } |
kishibekairohan | 10:a81546661fb5 | 218 | |
kishibekairohan | 10:a81546661fb5 | 219 | |
t_yamamoto | 0:562021ed1ba9 | 220 | |
t_yamamoto | 0:562021ed1ba9 | 221 | |
t_yamamoto | 0:562021ed1ba9 | 222 | |
t_yamamoto | 0:562021ed1ba9 | 223 | |
t_yamamoto | 0:562021ed1ba9 | 224 | //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ |
t_yamamoto | 0:562021ed1ba9 | 225 | //____________________________ |
t_yamamoto | 0:562021ed1ba9 | 226 | |
t_yamamoto | 0:562021ed1ba9 | 227 | MOTOR::Motor::Update(motor); |
t_yamamoto | 0:562021ed1ba9 | 228 | } |
t_yamamoto | 0:562021ed1ba9 | 229 | } |
t_yamamoto | 0:562021ed1ba9 | 230 |