aa

Dependencies:   mbed TrapezoidControl QEI

Committer:
yabahiro
Date:
Wed Sep 25 11:42:58 2019 +0000
Revision:
37:7cfa39c41245
Parent:
36:788274604650
Child:
38:391a0c8e4c16
aa

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kishibekairohan 13:b6e02d6261d7 1
t_yamamoto 0:669ef71cba68 2 #include "mbed.h"
t_yamamoto 0:669ef71cba68 3 #include "Process.h"
7ka884 4:ba9df71868df 4 #include "QEI.h"
t_yamamoto 0:669ef71cba68 5
7ka884 4:ba9df71868df 6 #include "../../CommonLibraries/PID/PID.h"
t_yamamoto 0:669ef71cba68 7 #include "../../Communication/RS485/ActuatorHub/ActuatorHub.h"
yabahiro 21:1f1e9c585da8 8 #include "../../Communication/RS485/LineHub/LineHub.h"
t_yamamoto 0:669ef71cba68 9 #include "../../Communication/Controller/Controller.h"
t_yamamoto 0:669ef71cba68 10 #include "../../Input/ExternalInt/ExternalInt.h"
t_yamamoto 0:669ef71cba68 11 #include "../../Input/Switch/Switch.h"
t_yamamoto 0:669ef71cba68 12 #include "../../Input/Potentiometer/Potentiometer.h"
kishibekairohan 16:3f2c2d89372b 13 #include "../../Input/Encoder/Encoder.h"
t_yamamoto 0:669ef71cba68 14 #include "../../LED/LED.h"
t_yamamoto 0:669ef71cba68 15 #include "../../Safty/Safty.h"
t_yamamoto 0:669ef71cba68 16 #include "../Using.h"
t_yamamoto 0:669ef71cba68 17
t_yamamoto 0:669ef71cba68 18 using namespace SWITCH;
7ka884 4:ba9df71868df 19 using namespace PID_SPACE;
kishibekairohan 16:3f2c2d89372b 20 using namespace ENCODER;
yabahiro 21:1f1e9c585da8 21 using namespace LINEHUB;
t_yamamoto 0:669ef71cba68 22
t_yamamoto 0:669ef71cba68 23 static CONTROLLER::ControllerData *controller;
t_yamamoto 0:669ef71cba68 24 ACTUATORHUB::MOTOR::MotorStatus motor[MOUNTING_MOTOR_NUM];
t_yamamoto 0:669ef71cba68 25 ACTUATORHUB::SOLENOID::SolenoidStatus solenoid;
t_yamamoto 0:669ef71cba68 26
t_yamamoto 0:669ef71cba68 27 static bool lock;
t_yamamoto 0:669ef71cba68 28 static bool processChangeComp;
t_yamamoto 0:669ef71cba68 29 static int current;
t_yamamoto 0:669ef71cba68 30
t_yamamoto 0:669ef71cba68 31 static void AllActuatorReset();
t_yamamoto 0:669ef71cba68 32
t_yamamoto 0:669ef71cba68 33 #ifdef USE_SUBPROCESS
t_yamamoto 0:669ef71cba68 34 static void (*Process[USE_PROCESS_NUM])(void);
t_yamamoto 0:669ef71cba68 35 #endif
t_yamamoto 0:669ef71cba68 36
t_yamamoto 0:669ef71cba68 37 #pragma region USER-DEFINED_VARIABLES_AND_PROTOTYPE
t_yamamoto 0:669ef71cba68 38
t_yamamoto 0:669ef71cba68 39 /*Replace here with the definition code of your variables.*/
t_yamamoto 0:669ef71cba68 40
kishibekairohan 2:c015739085d3 41 Serial pc(USBTX, USBRX);
kishibekairohan 2:c015739085d3 42
kishibekairohan 16:3f2c2d89372b 43 //**************Encoder***************
kishibekairohan 16:3f2c2d89372b 44 const int PerRev = 256;
kishibekairohan 16:3f2c2d89372b 45 QEI ECD_0(ECD_A_0,ECD_B_0,NC,PerRev,QEI::X4_ENCODING);
kishibekairohan 16:3f2c2d89372b 46 QEI ECD_1(ECD_A_1,ECD_B_1,NC,PerRev,QEI::X4_ENCODING);
kishibekairohan 16:3f2c2d89372b 47 QEI ECD_2(ECD_A_2,ECD_B_2,NC,PerRev,QEI::X4_ENCODING);
kishibekairohan 16:3f2c2d89372b 48 QEI ECD_3(ECD_A_3,ECD_B_3,NC,PerRev,QEI::X4_ENCODING);
kishibekairohan 16:3f2c2d89372b 49 //**************Encoder***************
kishibekairohan 7:e88c5d47a3be 50
kishibekairohan 16:3f2c2d89372b 51 //**************Buzzer****************
kishibekairohan 11:028a150943b5 52 //DigitalOut buzzer(BUZZER_PIN);
kishibekairohan 9:f93fc79a49ea 53 void BuzzerTimer_func();
kishibekairohan 9:f93fc79a49ea 54 Ticker BuzzerTimer;
kishibekairohan 16:3f2c2d89372b 55 bool EMGflag = false;
yabahiro 21:1f1e9c585da8 56 //PWMOut buzzer(BUZZER_PIN);
kishibekairohan 16:3f2c2d89372b 57 //**************Buzzer****************
kishibekairohan 11:028a150943b5 58
kishibekairohan 11:028a150943b5 59 //************TapeLed*****************
kishibekairohan 11:028a150943b5 60 void TapeLedEms_func();
kishibekairohan 11:028a150943b5 61 TapeLedData tapeLED;
kishibekairohan 11:028a150943b5 62 TapeLedData sendLedData;
kishibekairohan 11:028a150943b5 63 TapeLED_Mode ledMode = Normal;
kishibekairohan 11:028a150943b5 64 Ticker tapeLedTimer;
kishibekairohan 11:028a150943b5 65 //************TapaLed*****************
kishibekairohan 16:3f2c2d89372b 66
M_souta 18:c694bae76e51 67 float tireProRPM[4];
M_souta 18:c694bae76e51 68 float tireTarRPM[4];
yabahiro 21:1f1e9c585da8 69 float tirepwm[4];
yabahiro 21:1f1e9c585da8 70
yabahiro 21:1f1e9c585da8 71 const int omni[15][15] = {
yabahiro 21:1f1e9c585da8 72 { 0, 5, 21, 47, 83, 130, 187, 255, 255, 255, 255, 255, 255, 255, 255 },
yabahiro 21:1f1e9c585da8 73 { -5, 0, 5, 21, 47, 83, 130, 187, 193, 208, 234, 255, 255, 255, 255 },
yabahiro 21:1f1e9c585da8 74 { -21, -5, 0, 5, 21, 47, 83, 130, 135, 151, 177, 213, 255, 255, 255 },
yabahiro 21:1f1e9c585da8 75 { -47, -21, 5, 0, 5, 21, 47, 83, 88, 104, 130, 167, 213, 255, 255 },
yabahiro 21:1f1e9c585da8 76 { -83, -47, -21, 5, 0, 5, 21, 47, 52, 68, 94, 130, 177, 234, 255 },
yabahiro 21:1f1e9c585da8 77 { -130, -83, -47, -21, 5, 0, 5, 21, 26, 42, 68, 104, 151, 208, 255 },
yabahiro 21:1f1e9c585da8 78 { -187, -130, -83, -47, -21, -5, 0, 5, 10, 26, 52, 88, 135, 193, 255 },
yabahiro 21:1f1e9c585da8 79 { -255, -187, -130, -83, -47, -21, -5, 0, 5, 21, 47, 83, 130, 187, 255 },
yabahiro 21:1f1e9c585da8 80 { -255, -193, -135, -88, -52, -26, -10, -5, 0, 5, 21, 47, 83, 130, 187 },
yabahiro 21:1f1e9c585da8 81 { -255, -208, -151, -104, -68, -42, -26, -21, -5, 0, 5, 21, 47, 83, 130 },
yabahiro 21:1f1e9c585da8 82 { -255, -234, -177, -130, -94, -68, -52, -47, -21, -7, 0, 7, 21, 47, 83 },
yabahiro 21:1f1e9c585da8 83 { -255, -255, -213, -167, -130, -104, -88, -83, -47, -21, -5, 0, 5, 21, 47 },
yabahiro 21:1f1e9c585da8 84 { -255, -255, -255, -213, -177, -151, -135, -130, -83, -47, -21, -5, 0, 5, 21 },
yabahiro 21:1f1e9c585da8 85 { -255, -255, -255, -255, -234, -208, -193, -187, -130, -83, -47, -21, -5, 0, 5 },
yabahiro 21:1f1e9c585da8 86 { -255, -255, -255, -255, -255, -255, -255, -255, -187, -130, -83, -47, -21, -5, 0 }
yabahiro 21:1f1e9c585da8 87 };
yabahiro 21:1f1e9c585da8 88
yabahiro 21:1f1e9c585da8 89 const int curve[15] = { -152, -98, -54, -18, 0, 0, 0, 0, 0, 0, 0, 18, 54, 98, 152 };
yabahiro 21:1f1e9c585da8 90 //{-200,-146,-102,-66,-36,-16,0,0,0,16,36,66,102,146,200}
yabahiro 21:1f1e9c585da8 91
yabahiro 21:1f1e9c585da8 92 uint8_t SetStatus(int);
yabahiro 21:1f1e9c585da8 93 uint8_t SetStatus(int pwmVal)
yabahiro 21:1f1e9c585da8 94 {
yabahiro 21:1f1e9c585da8 95 if (pwmVal < 0) return BACK;
yabahiro 21:1f1e9c585da8 96 else if (pwmVal > 0) return FOR;
yabahiro 21:1f1e9c585da8 97 else if (pwmVal == 0) return BRAKE;
yabahiro 21:1f1e9c585da8 98 else return BRAKE;
yabahiro 21:1f1e9c585da8 99 }
yabahiro 21:1f1e9c585da8 100 uint8_t Setpwm(int);
yabahiro 21:1f1e9c585da8 101 uint8_t Setpwm(int pwmVal)
yabahiro 21:1f1e9c585da8 102 {
yabahiro 21:1f1e9c585da8 103 if (pwmVal == 0 || pwmVal > 255 || pwmVal < -255) return 255;
yabahiro 21:1f1e9c585da8 104 else return abs(pwmVal);
yabahiro 21:1f1e9c585da8 105 }
M_souta 18:c694bae76e51 106
yabahiro 35:94f026ab4d30 107 void LedMode(int led)
yabahiro 35:94f026ab4d30 108 {
yabahiro 36:788274604650 109 switch(led) {
yabahiro 36:788274604650 110 case 1:
yabahiro 36:788274604650 111 POTENTIOMETER::dio[0]= 1;
yabahiro 36:788274604650 112 POTENTIOMETER::dio[1]= 0;
yabahiro 36:788274604650 113 POTENTIOMETER::dio[2]= 0;
yabahiro 36:788274604650 114 POTENTIOMETER::dio[3]= 0;
yabahiro 36:788274604650 115 break;
yabahiro 36:788274604650 116 case 2:
yabahiro 36:788274604650 117 POTENTIOMETER::dio[0]= 0;
yabahiro 36:788274604650 118 POTENTIOMETER::dio[1]= 1;
yabahiro 36:788274604650 119 POTENTIOMETER::dio[2]= 0;
yabahiro 36:788274604650 120 POTENTIOMETER::dio[3]= 0;
yabahiro 36:788274604650 121 break;
yabahiro 36:788274604650 122 case 3:
yabahiro 36:788274604650 123 POTENTIOMETER::dio[0]= 1;
yabahiro 36:788274604650 124 POTENTIOMETER::dio[1]= 1;
yabahiro 36:788274604650 125 POTENTIOMETER::dio[2]= 0;
yabahiro 36:788274604650 126 POTENTIOMETER::dio[3]= 0;
yabahiro 36:788274604650 127 break;
yabahiro 36:788274604650 128 case 4:
yabahiro 36:788274604650 129 POTENTIOMETER::dio[0]= 0;
yabahiro 36:788274604650 130 POTENTIOMETER::dio[1]= 0;
yabahiro 36:788274604650 131 POTENTIOMETER::dio[2]= 1;
yabahiro 36:788274604650 132 POTENTIOMETER::dio[3]= 0;
yabahiro 36:788274604650 133 break;
yabahiro 36:788274604650 134 }
yabahiro 35:94f026ab4d30 135 /*
yabahiro 35:94f026ab4d30 136 if(led/8>=1) {
yabahiro 36:788274604650 137 POTENTIOMETER::dio[3]= 1;
yabahiro 35:94f026ab4d30 138 led=led%8;
yabahiro 35:94f026ab4d30 139 } else {
yabahiro 36:788274604650 140 POTENTIOMETER::dio[3]= 0;
yabahiro 35:94f026ab4d30 141 }
yabahiro 35:94f026ab4d30 142
yabahiro 35:94f026ab4d30 143 if(led/4>=1) {
yabahiro 36:788274604650 144 POTENTIOMETER::dio[2]= 1;
yabahiro 36:788274604650 145 led=led%4;
yabahiro 36:788274604650 146 } else {
yabahiro 36:788274604650 147 POTENTIOMETER::dio[2]= 0;
yabahiro 36:788274604650 148 }
yabahiro 36:788274604650 149
yabahiro 36:788274604650 150 if(led/2>=1) {
yabahiro 35:94f026ab4d30 151 POTENTIOMETER::dio[1]= 1;
yabahiro 36:788274604650 152 led=led%2;
yabahiro 35:94f026ab4d30 153 } else {
yabahiro 35:94f026ab4d30 154 POTENTIOMETER::dio[1]= 0;
yabahiro 35:94f026ab4d30 155 }
yabahiro 35:94f026ab4d30 156
yabahiro 36:788274604650 157 if(led/1>=1) {
yabahiro 36:788274604650 158 POTENTIOMETER::dio[0]= 1;
yabahiro 36:788274604650 159 led=0;
yabahiro 35:94f026ab4d30 160 } else {
yabahiro 36:788274604650 161 POTENTIOMETER::dio[0]= 0;
yabahiro 35:94f026ab4d30 162 }
yabahiro 35:94f026ab4d30 163 */
yabahiro 35:94f026ab4d30 164 }
yabahiro 31:45f97698857b 165 int Twsh;
yabahiro 31:45f97698857b 166 bool UP_flag = false;
yabahiro 35:94f026ab4d30 167 bool SW_flag = false;
yabahiro 31:45f97698857b 168 bool Air_flag = false;
yabahiro 35:94f026ab4d30 169 bool zyouge;
yabahiro 31:45f97698857b 170 bool dz1=true;
yabahiro 31:45f97698857b 171 bool dz1i=false;
yabahiro 31:45f97698857b 172 bool dz2=true;
yabahiro 31:45f97698857b 173 bool dz2i=false;
yabahiro 31:45f97698857b 174 bool dz3=true;
yabahiro 31:45f97698857b 175 bool dz3i=false;
yabahiro 31:45f97698857b 176 bool dz4=true;
yabahiro 31:45f97698857b 177 bool dz4i=false;
yabahiro 31:45f97698857b 178 bool zone;
yabahiro 31:45f97698857b 179 bool through=false;
yabahiro 35:94f026ab4d30 180 bool counts=false;
yabahiro 36:788274604650 181 bool mtc=false;
yabahiro 36:788274604650 182 bool mtc2 = false;
yabahiro 31:45f97698857b 183
yabahiro 31:45f97698857b 184 int mode =1;
yabahiro 31:45f97698857b 185 int cross=0;//十字数える用
yabahiro 35:94f026ab4d30 186 int cros=0;
yabahiro 31:45f97698857b 187 int count=100000;//wait代替え
kishibekairohan 33:656aa14904a5 188
kishibekairohan 33:656aa14904a5 189 ///*********PWM調整用*********///
kishibekairohan 33:656aa14904a5 190 int fast =40;
kishibekairohan 33:656aa14904a5 191 int normal = 30;
kishibekairohan 33:656aa14904a5 192 int slow = 20;
yabahiro 31:45f97698857b 193
t_yamamoto 0:669ef71cba68 194 #pragma endregion USER-DEFINED_VARIABLES_AND_PROTOTYPE
t_yamamoto 0:669ef71cba68 195
t_yamamoto 0:669ef71cba68 196 #ifdef USE_SUBPROCESS
t_yamamoto 0:669ef71cba68 197 #if USE_PROCESS_NUM>0
t_yamamoto 0:669ef71cba68 198 static void Process0(void);
t_yamamoto 0:669ef71cba68 199 #endif
t_yamamoto 0:669ef71cba68 200 #if USE_PROCESS_NUM>1
t_yamamoto 0:669ef71cba68 201 static void Process1(void);
t_yamamoto 0:669ef71cba68 202 #endif
t_yamamoto 0:669ef71cba68 203 #if USE_PROCESS_NUM>2
t_yamamoto 0:669ef71cba68 204 static void Process2(void);
t_yamamoto 0:669ef71cba68 205 #endif
t_yamamoto 0:669ef71cba68 206 #if USE_PROCESS_NUM>3
t_yamamoto 0:669ef71cba68 207 static void Process3(void);
t_yamamoto 0:669ef71cba68 208 #endif
t_yamamoto 0:669ef71cba68 209 #if USE_PROCESS_NUM>4
t_yamamoto 0:669ef71cba68 210 static void Process4(void);
t_yamamoto 0:669ef71cba68 211 #endif
t_yamamoto 0:669ef71cba68 212 #if USE_PROCESS_NUM>5
t_yamamoto 0:669ef71cba68 213 static void Process5(void);
t_yamamoto 0:669ef71cba68 214 #endif
t_yamamoto 0:669ef71cba68 215 #if USE_PROCESS_NUM>6
t_yamamoto 0:669ef71cba68 216 static void Process6(void);
t_yamamoto 0:669ef71cba68 217 #endif
t_yamamoto 0:669ef71cba68 218 #if USE_PROCESS_NUM>7
t_yamamoto 0:669ef71cba68 219 static void Process7(void);
t_yamamoto 0:669ef71cba68 220 #endif
t_yamamoto 0:669ef71cba68 221 #if USE_PROCESS_NUM>8
t_yamamoto 0:669ef71cba68 222 static void Process8(void);
t_yamamoto 0:669ef71cba68 223 #endif
t_yamamoto 0:669ef71cba68 224 #if USE_PROCESS_NUM>9
t_yamamoto 0:669ef71cba68 225 static void Process9(void);
t_yamamoto 0:669ef71cba68 226 #endif
t_yamamoto 0:669ef71cba68 227 #endif
t_yamamoto 0:669ef71cba68 228
t_yamamoto 0:669ef71cba68 229 void SystemProcessInitialize()
t_yamamoto 0:669ef71cba68 230 {
yabahiro 21:1f1e9c585da8 231 #pragma region USER-DEFINED_VARIABLE_INIT
yabahiro 21:1f1e9c585da8 232 /*Replace here with the initialization code of your variables.*/
yabahiro 21:1f1e9c585da8 233 #pragma endregion USER-DEFINED_VARIABLE_INIT
t_yamamoto 0:669ef71cba68 234
yabahiro 21:1f1e9c585da8 235 lock = true;
yabahiro 21:1f1e9c585da8 236 processChangeComp = true;
yabahiro 21:1f1e9c585da8 237 current = DEFAULT_PROCESS;
t_yamamoto 0:669ef71cba68 238
yabahiro 21:1f1e9c585da8 239 #ifdef USE_SUBPROCESS
yabahiro 21:1f1e9c585da8 240 #if USE_PROCESS_NUM>0
yabahiro 21:1f1e9c585da8 241 Process[0] = Process0;
yabahiro 21:1f1e9c585da8 242 #endif
yabahiro 21:1f1e9c585da8 243 #if USE_PROCESS_NUM>1
yabahiro 21:1f1e9c585da8 244 Process[1] = Process1;
yabahiro 21:1f1e9c585da8 245 #endif
yabahiro 21:1f1e9c585da8 246 #if USE_PROCESS_NUM>2
yabahiro 21:1f1e9c585da8 247 Process[2] = Process2;
yabahiro 21:1f1e9c585da8 248 #endif
yabahiro 21:1f1e9c585da8 249 #if USE_PROCESS_NUM>3
yabahiro 21:1f1e9c585da8 250 Process[3] = Process3;
yabahiro 21:1f1e9c585da8 251 #endif
yabahiro 21:1f1e9c585da8 252 #if USE_PROCESS_NUM>4
yabahiro 21:1f1e9c585da8 253 Process[4] = Process4;
yabahiro 21:1f1e9c585da8 254 #endif
yabahiro 21:1f1e9c585da8 255 #if USE_PROCESS_NUM>5
yabahiro 21:1f1e9c585da8 256 Process[5] = Process5;
yabahiro 21:1f1e9c585da8 257 #endif
yabahiro 21:1f1e9c585da8 258 #if USE_PROCESS_NUM>6
yabahiro 21:1f1e9c585da8 259 Process[6] = Process6;
yabahiro 21:1f1e9c585da8 260 #endif
yabahiro 21:1f1e9c585da8 261 #if USE_PROCESS_NUM>7
yabahiro 21:1f1e9c585da8 262 Process[7] = Process7;
yabahiro 21:1f1e9c585da8 263 #endif
yabahiro 21:1f1e9c585da8 264 #if USE_PROCESS_NUM>8
yabahiro 21:1f1e9c585da8 265 Process[8] = Process8;
yabahiro 21:1f1e9c585da8 266 #endif
yabahiro 21:1f1e9c585da8 267 #if USE_PROCESS_NUM>9
yabahiro 21:1f1e9c585da8 268 Process[9] = Process9;
yabahiro 21:1f1e9c585da8 269 #endif
yabahiro 21:1f1e9c585da8 270 #endif
t_yamamoto 0:669ef71cba68 271 }
t_yamamoto 0:669ef71cba68 272
t_yamamoto 0:669ef71cba68 273 static void SystemProcessUpdate()
t_yamamoto 0:669ef71cba68 274 {
yabahiro 21:1f1e9c585da8 275 #ifdef USE_SUBPROCESS
yabahiro 21:1f1e9c585da8 276 if(controller->Button.HOME) lock = false;
yabahiro 21:1f1e9c585da8 277
yabahiro 21:1f1e9c585da8 278 if(controller->Button.START && processChangeComp) {
yabahiro 21:1f1e9c585da8 279 current++;
yabahiro 21:1f1e9c585da8 280 if (USE_PROCESS_NUM < current) current = USE_PROCESS_NUM;
yabahiro 21:1f1e9c585da8 281 processChangeComp = false;
yabahiro 21:1f1e9c585da8 282 } else if(controller->Button.SELECT && processChangeComp) {
yabahiro 21:1f1e9c585da8 283 current--;
yabahiro 21:1f1e9c585da8 284 if (current < 0) current = 0;
yabahiro 21:1f1e9c585da8 285 processChangeComp = false;
yabahiro 21:1f1e9c585da8 286 } else if(!controller->Button.SELECT && !controller->Button.START) processChangeComp = true;
yabahiro 21:1f1e9c585da8 287 #endif
yabahiro 21:1f1e9c585da8 288
yabahiro 21:1f1e9c585da8 289 #ifdef USE_MOTOR
yabahiro 21:1f1e9c585da8 290 ACTUATORHUB::MOTOR::Motor::Update(motor);
yabahiro 21:1f1e9c585da8 291 #endif
yabahiro 21:1f1e9c585da8 292
yabahiro 21:1f1e9c585da8 293 #ifdef USE_SOLENOID
yabahiro 21:1f1e9c585da8 294 ACTUATORHUB::SOLENOID::Solenoid::Update(solenoid);
yabahiro 21:1f1e9c585da8 295 #endif
yabahiro 21:1f1e9c585da8 296
yabahiro 21:1f1e9c585da8 297 #ifdef USE_RS485
yabahiro 21:1f1e9c585da8 298 ACTUATORHUB::ActuatorHub::Update();
yabahiro 21:1f1e9c585da8 299 #endif
yabahiro 21:1f1e9c585da8 300
yabahiro 21:1f1e9c585da8 301 }
yabahiro 21:1f1e9c585da8 302
yabahiro 21:1f1e9c585da8 303 int g[8];
yabahiro 21:1f1e9c585da8 304
yabahiro 21:1f1e9c585da8 305 void SystemProcess()
yabahiro 21:1f1e9c585da8 306 {
yabahiro 21:1f1e9c585da8 307 SystemProcessInitialize();
yabahiro 21:1f1e9c585da8 308
yabahiro 21:1f1e9c585da8 309 while(1) {
yabahiro 21:1f1e9c585da8 310 for(int i = 0; i < 8; i++) {
yabahiro 21:1f1e9c585da8 311 g[i] = LineHub::GetPara(i);
yabahiro 21:1f1e9c585da8 312 }
yabahiro 35:94f026ab4d30 313
yabahiro 36:788274604650 314 //printf("0:%d 1:%d 2:%d 3:%d 4:%d 5:%d 6:%d 9:%d\n\r",g[0],g[1],g[2],g[3],g[4],g[5],g[6],g[7]);
yabahiro 35:94f026ab4d30 315
yabahiro 21:1f1e9c585da8 316 #ifdef USE_MU
yabahiro 21:1f1e9c585da8 317 controller = CONTROLLER::Controller::GetData();
yabahiro 21:1f1e9c585da8 318 #endif
yabahiro 21:1f1e9c585da8 319
yabahiro 21:1f1e9c585da8 320 #ifdef USE_ERRORCHECK
yabahiro 21:1f1e9c585da8 321 if(SAFTY::ErrorCheck::Check() & SAFTY::Error::ControllerLost) {
yabahiro 21:1f1e9c585da8 322 CONTROLLER::Controller::DataReset();
yabahiro 21:1f1e9c585da8 323 AllActuatorReset();
yabahiro 21:1f1e9c585da8 324 lock = true;
yabahiro 21:1f1e9c585da8 325 } else
yabahiro 21:1f1e9c585da8 326 #endif
yabahiro 21:1f1e9c585da8 327 {
yabahiro 21:1f1e9c585da8 328
yabahiro 21:1f1e9c585da8 329 #ifdef USE_SUBPROCESS
yabahiro 21:1f1e9c585da8 330 if(!lock) {
yabahiro 21:1f1e9c585da8 331 Process[current]();
yabahiro 21:1f1e9c585da8 332 } else
yabahiro 21:1f1e9c585da8 333 #endif
yabahiro 21:1f1e9c585da8 334 {
yabahiro 21:1f1e9c585da8 335 //ロック時の処理
yabahiro 21:1f1e9c585da8 336 }
yabahiro 21:1f1e9c585da8 337 }
yabahiro 21:1f1e9c585da8 338 /*
yabahiro 21:1f1e9c585da8 339 //Emergency!
yabahiro 21:1f1e9c585da8 340 if(!EMG_0 && !EMG_1 && !EMGflag) {
yabahiro 21:1f1e9c585da8 341 buzzer = 0;
yabahiro 21:1f1e9c585da8 342 BuzzerTimer.attach(BuzzerTimer_func, 1);
yabahiro 21:1f1e9c585da8 343 EMGflag = true;
yabahiro 21:1f1e9c585da8 344 LED_DEBUG0 = 1;
yabahiro 21:1f1e9c585da8 345 }
yabahiro 21:1f1e9c585da8 346 if(EMG_0 && EMG_1 && EMGflag) {
yabahiro 21:1f1e9c585da8 347 buzzer = 1;
yabahiro 21:1f1e9c585da8 348 BuzzerTimer.detach();
yabahiro 21:1f1e9c585da8 349 EMGflag = false;
yabahiro 21:1f1e9c585da8 350 }
yabahiro 21:1f1e9c585da8 351 */
yabahiro 21:1f1e9c585da8 352 SystemProcessUpdate();
yabahiro 21:1f1e9c585da8 353 }
t_yamamoto 0:669ef71cba68 354 }
t_yamamoto 0:669ef71cba68 355
t_yamamoto 0:669ef71cba68 356 #pragma region PROCESS
t_yamamoto 0:669ef71cba68 357 #ifdef USE_SUBPROCESS
t_yamamoto 0:669ef71cba68 358 #if USE_PROCESS_NUM>0
yabahiro 21:1f1e9c585da8 359 static void Process0()
yabahiro 21:1f1e9c585da8 360 {
yabahiro 36:788274604650 361 mode=1;
yabahiro 36:788274604650 362 LedMode(1);
yabahiro 35:94f026ab4d30 363 if(ThSW) {
yabahiro 35:94f026ab4d30 364 Twsh=1;
yabahiro 35:94f026ab4d30 365 } else {
yabahiro 35:94f026ab4d30 366 Twsh=2;
yabahiro 31:45f97698857b 367 }
yabahiro 36:788274604650 368
yabahiro 25:38d4964e8aad 369 if(StertSW) {
yabahiro 36:788274604650 370 if(ZoneSW) {
yabahiro 31:45f97698857b 371 mode=1;
yabahiro 31:45f97698857b 372 current = 2;
yabahiro 31:45f97698857b 373 } else {
yabahiro 31:45f97698857b 374 mode=1;
yabahiro 36:788274604650 375 current = 4;
yabahiro 31:45f97698857b 376 }
yabahiro 25:38d4964e8aad 377 }
yabahiro 35:94f026ab4d30 378 if(DWSW) {
yabahiro 35:94f026ab4d30 379 zyouge=true;
yabahiro 35:94f026ab4d30 380 }
yabahiro 35:94f026ab4d30 381 if(AIRSW) {
yabahiro 35:94f026ab4d30 382 if(SW_flag==false) {
yabahiro 35:94f026ab4d30 383 if(Air_flag==false) {
yabahiro 35:94f026ab4d30 384 solenoid.solenoid3 = SOLENOID_ON;
yabahiro 35:94f026ab4d30 385 Air_flag=true;
yabahiro 35:94f026ab4d30 386 SW_flag=true;
yabahiro 35:94f026ab4d30 387 } else {
yabahiro 35:94f026ab4d30 388 solenoid.solenoid3 = SOLENOID_OFF;
yabahiro 35:94f026ab4d30 389 Air_flag=false;
yabahiro 35:94f026ab4d30 390 SW_flag=true;
yabahiro 35:94f026ab4d30 391 }
yabahiro 35:94f026ab4d30 392 }
yabahiro 35:94f026ab4d30 393 } else {
yabahiro 35:94f026ab4d30 394 SW_flag=false;
yabahiro 31:45f97698857b 395 }
yabahiro 31:45f97698857b 396
yabahiro 35:94f026ab4d30 397 if(zyouge) {
yabahiro 35:94f026ab4d30 398 if(Twsh==1) {
yabahiro 35:94f026ab4d30 399 motor[MOTOR_0].pwm = 220;
yabahiro 35:94f026ab4d30 400 motor[MOTOR_0].dir = FOR;
yabahiro 35:94f026ab4d30 401 if(UPLS) {
yabahiro 35:94f026ab4d30 402 motor[MOTOR_0].pwm = 100;
yabahiro 35:94f026ab4d30 403 motor[MOTOR_0].dir = BRAKE;
yabahiro 35:94f026ab4d30 404 zyouge=false;
yabahiro 35:94f026ab4d30 405 }
yabahiro 35:94f026ab4d30 406 }
yabahiro 35:94f026ab4d30 407 if(Twsh==2) {
yabahiro 37:7cfa39c41245 408 motor[MOTOR_0].pwm = 230;
yabahiro 35:94f026ab4d30 409 motor[MOTOR_0].dir = FOR;
yabahiro 35:94f026ab4d30 410 if(UPLS2) {
yabahiro 35:94f026ab4d30 411 motor[MOTOR_0].pwm = 100;
yabahiro 35:94f026ab4d30 412 motor[MOTOR_0].dir = BRAKE;
yabahiro 35:94f026ab4d30 413 zyouge=false;
yabahiro 35:94f026ab4d30 414 }
yabahiro 31:45f97698857b 415 }
yabahiro 37:7cfa39c41245 416 } else {
yabahiro 37:7cfa39c41245 417 motor[MOTOR_0].pwm = 100;
yabahiro 37:7cfa39c41245 418 motor[MOTOR_0].dir = BRAKE;
yabahiro 31:45f97698857b 419 }
yabahiro 35:94f026ab4d30 420 }
yabahiro 31:45f97698857b 421
t_yamamoto 0:669ef71cba68 422 #endif
t_yamamoto 0:669ef71cba68 423
t_yamamoto 0:669ef71cba68 424 #if USE_PROCESS_NUM>1
kishibekairohan 16:3f2c2d89372b 425 static void Process1()
t_yamamoto 0:669ef71cba68 426 {
yabahiro 36:788274604650 427 mtc=false;
yabahiro 36:788274604650 428 mtc2 = false;
yabahiro 36:788274604650 429 LedMode(2);
yabahiro 31:45f97698857b 430 mode=1;
yabahiro 27:545148741493 431 cross=0;
yabahiro 35:94f026ab4d30 432 Twsh=1;
yabahiro 21:1f1e9c585da8 433 motor[TIRE_FR].dir = SetStatus(-omni[controller->AnalogL.Y][14-controller->AnalogL.X] + curve[controller->AnalogR.X]);
yabahiro 21:1f1e9c585da8 434 motor[TIRE_FL].dir = SetStatus(omni[controller->AnalogL.Y][controller->AnalogL.X] + curve[controller->AnalogR.X]);
yabahiro 21:1f1e9c585da8 435 motor[TIRE_BR].dir = SetStatus(-omni[14-controller->AnalogL.X][14-controller->AnalogL.Y] + curve[controller->AnalogR.X]);
yabahiro 21:1f1e9c585da8 436 motor[TIRE_BL].dir = SetStatus(omni[controller->AnalogL.X][14-controller->AnalogL.Y] + curve[controller->AnalogR.X]);
yabahiro 21:1f1e9c585da8 437
yabahiro 21:1f1e9c585da8 438 motor[TIRE_FR].pwm = Setpwm(omni[controller->AnalogL.Y][14-controller->AnalogL.X]+ curve[controller->AnalogR.X])*0.2;
yabahiro 21:1f1e9c585da8 439 motor[TIRE_FL].pwm = Setpwm(omni[controller->AnalogL.Y][controller->AnalogL.X]+ curve[controller->AnalogR.X])*0.2;
yabahiro 21:1f1e9c585da8 440 motor[TIRE_BR].pwm = Setpwm(omni[14-controller->AnalogL.X][14-controller->AnalogL.Y]+ curve[controller->AnalogR.X])*0.2;
yabahiro 21:1f1e9c585da8 441 motor[TIRE_BL].pwm = Setpwm(omni[controller->AnalogL.X][14-controller->AnalogL.Y]+ curve[controller->AnalogR.X])*0.2;
yabahiro 21:1f1e9c585da8 442
yabahiro 21:1f1e9c585da8 443 if(controller->Button.UP||controller->Button.DOWN) {
yabahiro 21:1f1e9c585da8 444
yabahiro 21:1f1e9c585da8 445 if(controller->Button.UP) {
yabahiro 35:94f026ab4d30 446 motor[MOTOR_0].pwm =200;
yabahiro 21:1f1e9c585da8 447 motor[MOTOR_0].dir = FOR;
yabahiro 35:94f026ab4d30 448 if(UPLS) {
yabahiro 35:94f026ab4d30 449 motor[MOTOR_0].pwm = 0;
yabahiro 35:94f026ab4d30 450 motor[MOTOR_0].dir = BRAKE;
yabahiro 35:94f026ab4d30 451 }
yabahiro 21:1f1e9c585da8 452 }
yabahiro 21:1f1e9c585da8 453 if(controller->Button.DOWN) {
yabahiro 21:1f1e9c585da8 454 motor[MOTOR_0].pwm = 50;
yabahiro 21:1f1e9c585da8 455 motor[MOTOR_0].dir = BACK;
yabahiro 21:1f1e9c585da8 456 }
yabahiro 21:1f1e9c585da8 457 } else {
yabahiro 21:1f1e9c585da8 458 motor[MOTOR_0].pwm = 0;
yabahiro 21:1f1e9c585da8 459 motor[MOTOR_0].dir = BRAKE;
yabahiro 21:1f1e9c585da8 460 }
yabahiro 21:1f1e9c585da8 461
yabahiro 21:1f1e9c585da8 462 if(controller->Button.Y) {
yabahiro 21:1f1e9c585da8 463 if(dz2==true) {
yabahiro 21:1f1e9c585da8 464 if(dz2i==false) {
yabahiro 21:1f1e9c585da8 465 solenoid.solenoid2 = SOLENOID_ON;
yabahiro 21:1f1e9c585da8 466 dz2i=true;
yabahiro 21:1f1e9c585da8 467 } else {
yabahiro 21:1f1e9c585da8 468 solenoid.solenoid2 = SOLENOID_OFF;
yabahiro 21:1f1e9c585da8 469 dz2i=false;
yabahiro 21:1f1e9c585da8 470 }
yabahiro 21:1f1e9c585da8 471 dz2=false;
yabahiro 21:1f1e9c585da8 472 }
yabahiro 21:1f1e9c585da8 473 } else {
yabahiro 21:1f1e9c585da8 474 dz2=true;
yabahiro 21:1f1e9c585da8 475 }
yabahiro 21:1f1e9c585da8 476
yabahiro 21:1f1e9c585da8 477 if(controller->Button.A) {
yabahiro 21:1f1e9c585da8 478 if(dz3==true) {
yabahiro 21:1f1e9c585da8 479 if(dz3i==false) {
yabahiro 30:9450dc1d53cc 480
yabahiro 21:1f1e9c585da8 481 dz3i=true;
yabahiro 21:1f1e9c585da8 482 } else {
yabahiro 21:1f1e9c585da8 483 solenoid.solenoid3 = SOLENOID_OFF;
yabahiro 21:1f1e9c585da8 484 dz3i=false;
yabahiro 21:1f1e9c585da8 485 }
yabahiro 21:1f1e9c585da8 486 dz3=false;
yabahiro 21:1f1e9c585da8 487 }
yabahiro 21:1f1e9c585da8 488 } else {
yabahiro 21:1f1e9c585da8 489 dz3=true;
yabahiro 21:1f1e9c585da8 490 }
yabahiro 21:1f1e9c585da8 491
yabahiro 21:1f1e9c585da8 492 if(controller->Button.B) {
yabahiro 21:1f1e9c585da8 493 if(dz4==true) {
yabahiro 21:1f1e9c585da8 494 if(dz4i==false) {
yabahiro 21:1f1e9c585da8 495 solenoid.solenoid4 = SOLENOID_ON;
yabahiro 21:1f1e9c585da8 496 dz4i=true;
yabahiro 21:1f1e9c585da8 497 } else {
yabahiro 21:1f1e9c585da8 498 solenoid.solenoid4 = SOLENOID_OFF;
yabahiro 21:1f1e9c585da8 499 dz4i=false;
yabahiro 21:1f1e9c585da8 500 }
yabahiro 21:1f1e9c585da8 501 dz4=false;
yabahiro 21:1f1e9c585da8 502 }
yabahiro 21:1f1e9c585da8 503 } else {
yabahiro 21:1f1e9c585da8 504 dz4=true;
yabahiro 21:1f1e9c585da8 505 }
yabahiro 21:1f1e9c585da8 506 /*
yabahiro 21:1f1e9c585da8 507 if(controller->Button.RIGHT){
yabahiro 21:1f1e9c585da8 508 motor[MOTOR_1].dir = FOR;
yabahiro 21:1f1e9c585da8 509 motor[MOTOR_1].pwm = 60;
yabahiro 21:1f1e9c585da8 510 if (ARM_1){
yabahiro 21:1f1e9c585da8 511 motor[MOTOR_1].dir = BRAKE;
yabahiro 21:1f1e9c585da8 512 }
yabahiro 21:1f1e9c585da8 513 }
yabahiro 21:1f1e9c585da8 514 else if(controller->Button.LEFT){
yabahiro 21:1f1e9c585da8 515 motor[MOTOR_1].dir = BACK;
yabahiro 21:1f1e9c585da8 516 motor[MOTOR_1].pwm = 60;
yabahiro 21:1f1e9c585da8 517 if (ARM_0){
yabahiro 21:1f1e9c585da8 518 motor[MOTOR_1].dir = BRAKE;
yabahiro 21:1f1e9c585da8 519 }
yabahiro 21:1f1e9c585da8 520 }
yabahiro 21:1f1e9c585da8 521 */
t_yamamoto 0:669ef71cba68 522 }
t_yamamoto 0:669ef71cba68 523 #endif
t_yamamoto 0:669ef71cba68 524
t_yamamoto 0:669ef71cba68 525 #if USE_PROCESS_NUM>2
kishibekairohan 16:3f2c2d89372b 526 static void Process2()
yabahiro 21:1f1e9c585da8 527 {
yabahiro 36:788274604650 528 LedMode(3);
yabahiro 31:45f97698857b 529 // printf("1:%d 2:%d 3:%d 4:%d 5:%d 6:%d 7:%d 8:%d\n\r",g[0],g[1],g[2],g[3],g[4],g[5],g[6],g[7]);
yabahiro 31:45f97698857b 530 count++;
yabahiro 31:45f97698857b 531 if(mode==1) {//スタートゾーンから白線検知
kishibekairohan 33:656aa14904a5 532 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 533 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 534 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 535 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 536 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 537 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 538 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 539 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 540 if(g[2]==0) {
yabahiro 31:45f97698857b 541 count=100000;
yabahiro 31:45f97698857b 542 cross=0;
yabahiro 31:45f97698857b 543 mode=3;
yabahiro 31:45f97698857b 544 }
yabahiro 31:45f97698857b 545 } else if(mode==3) { //横ライントレースから縦ライントレースへ
yabahiro 31:45f97698857b 546 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 547 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 548 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 549 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 550 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 551 motor[TIRE_BR].dir = BACK;
yabahiro 31:45f97698857b 552 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 553 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 554 if(g[0]==0) {
yabahiro 35:94f026ab4d30 555 mode=10;
yabahiro 35:94f026ab4d30 556 count=100000;
yabahiro 31:45f97698857b 557 }
yabahiro 35:94f026ab4d30 558 } else if(mode==10) { //縦ライントレース
yabahiro 35:94f026ab4d30 559
yabahiro 35:94f026ab4d30 560 if(counts==false&&g[2]==0) {
yabahiro 35:94f026ab4d30 561 cros++;
yabahiro 35:94f026ab4d30 562 counts=true;
yabahiro 31:45f97698857b 563 }
yabahiro 35:94f026ab4d30 564 if(counts==true&&g[2]==99) {
yabahiro 35:94f026ab4d30 565 counts=false;
yabahiro 35:94f026ab4d30 566 }
yabahiro 35:94f026ab4d30 567
yabahiro 35:94f026ab4d30 568 if(cros==Twsh) {
yabahiro 35:94f026ab4d30 569 mode=11;
yabahiro 31:45f97698857b 570 count=0;
yabahiro 35:94f026ab4d30 571 cros=0;
yabahiro 35:94f026ab4d30 572 }//ゆっくりモードに入れなかった時の保険
yabahiro 31:45f97698857b 573 switch(g[0]) {
yabahiro 31:45f97698857b 574 case 98:
kishibekairohan 33:656aa14904a5 575 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 576 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 577 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 578 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 579 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 580 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 581 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 582 motor[TIRE_BL].dir = FOR;
yabahiro 35:94f026ab4d30 583 mtc=true;
yabahiro 35:94f026ab4d30 584 if(count>80000) {
yabahiro 31:45f97698857b 585 cross++;
yabahiro 31:45f97698857b 586 count=0;
yabahiro 31:45f97698857b 587 }
yabahiro 31:45f97698857b 588 if(cross==Twsh) {
yabahiro 31:45f97698857b 589 mode=11;
yabahiro 31:45f97698857b 590 count=0;
yabahiro 35:94f026ab4d30 591 cross=0;
yabahiro 31:45f97698857b 592 }
yabahiro 31:45f97698857b 593 break;
yabahiro 31:45f97698857b 594 case 0:
kishibekairohan 33:656aa14904a5 595 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 596 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 597 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 598 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 599 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 600 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 601 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 602 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 603 mtc=true;
yabahiro 31:45f97698857b 604 break;
yabahiro 31:45f97698857b 605 case 255:
kishibekairohan 33:656aa14904a5 606 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 607 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 608 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 609 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 610 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 611 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 612 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 613 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 614 mtc=true;
yabahiro 31:45f97698857b 615 break;
yabahiro 31:45f97698857b 616 case 253:
kishibekairohan 33:656aa14904a5 617 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 618 motor[TIRE_FR].dir = BACK;
yabahiro 31:45f97698857b 619 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 620 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 621 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 622 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 623 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 624 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 625 mtc=true;
yabahiro 31:45f97698857b 626 break;
yabahiro 31:45f97698857b 627 case 254:
kishibekairohan 33:656aa14904a5 628 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 629 motor[TIRE_FR].dir = BACK;
yabahiro 31:45f97698857b 630 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 631 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 632 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 633 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 634 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 635 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 636 mtc=true;
yabahiro 31:45f97698857b 637 break;
yabahiro 31:45f97698857b 638 case 1:
kishibekairohan 33:656aa14904a5 639 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 640 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 641 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 642 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 643 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 644 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 645 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 646 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 647 mtc=true;
yabahiro 31:45f97698857b 648 break;
yabahiro 31:45f97698857b 649 case 3:
yabahiro 31:45f97698857b 650 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 651 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 652 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 653 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 654 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 655 motor[TIRE_BR].dir = BACK;
yabahiro 31:45f97698857b 656 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 657 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 658 mtc=true;
yabahiro 31:45f97698857b 659 break;
yabahiro 31:45f97698857b 660 case 2:
yabahiro 31:45f97698857b 661 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 662 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 663 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 664 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 665 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 666 motor[TIRE_BR].dir = BACK;
yabahiro 31:45f97698857b 667 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 668 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 669 mtc=true;
yabahiro 31:45f97698857b 670 break;
yabahiro 31:45f97698857b 671 }
yabahiro 31:45f97698857b 672 if(g[0]!=98&&mtc==true) {
yabahiro 31:45f97698857b 673 switch(g[1]) {
yabahiro 31:45f97698857b 674 case 0:
yabahiro 31:45f97698857b 675 mtc=false;
yabahiro 31:45f97698857b 676 break;
yabahiro 31:45f97698857b 677 case 255:
yabahiro 31:45f97698857b 678 motor[TIRE_BR].pwm += 5;
yabahiro 31:45f97698857b 679 mtc=false;
yabahiro 31:45f97698857b 680 break;
yabahiro 31:45f97698857b 681 case 253:
yabahiro 31:45f97698857b 682 motor[TIRE_BR].pwm += 10;
yabahiro 31:45f97698857b 683 mtc=false;
yabahiro 31:45f97698857b 684 break;
yabahiro 31:45f97698857b 685 case 254:
yabahiro 31:45f97698857b 686 motor[TIRE_BR].pwm += 20;
yabahiro 31:45f97698857b 687 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 688 mtc=false;
yabahiro 31:45f97698857b 689 break;
yabahiro 31:45f97698857b 690 case 1:
yabahiro 31:45f97698857b 691 motor[TIRE_BL].pwm += 5;
yabahiro 31:45f97698857b 692 mtc=false;
yabahiro 31:45f97698857b 693 break;
yabahiro 31:45f97698857b 694 case 3:
yabahiro 31:45f97698857b 695 motor[TIRE_BL].pwm += 10;
yabahiro 31:45f97698857b 696 mtc=false;
yabahiro 31:45f97698857b 697 break;
yabahiro 31:45f97698857b 698 case 2:
yabahiro 31:45f97698857b 699 motor[TIRE_BL].pwm += 20;
yabahiro 31:45f97698857b 700 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 701 mtc=false;
yabahiro 31:45f97698857b 702 break;
yabahiro 21:1f1e9c585da8 703 }
yabahiro 31:45f97698857b 704 }
yabahiro 31:45f97698857b 705 } else if(mode==11) {
yabahiro 31:45f97698857b 706 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 707 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 708 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 709 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 710 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 711 motor[TIRE_BR].dir = BACK;
yabahiro 31:45f97698857b 712 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 713 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 714 if(g[2]==0) {
yabahiro 31:45f97698857b 715 count=0;
yabahiro 31:45f97698857b 716 cross=0;
yabahiro 31:45f97698857b 717 mode=20;
yabahiro 31:45f97698857b 718 }
yabahiro 31:45f97698857b 719 } else if(mode==20) {
yabahiro 35:94f026ab4d30 720
yabahiro 35:94f026ab4d30 721 if(counts==false&&g[0]==0) {
yabahiro 35:94f026ab4d30 722 cros++;
yabahiro 35:94f026ab4d30 723 counts=true;
yabahiro 35:94f026ab4d30 724 }
yabahiro 35:94f026ab4d30 725 if(counts==true&&g[0]==99) {
yabahiro 35:94f026ab4d30 726 counts=false;
yabahiro 35:94f026ab4d30 727 }
yabahiro 35:94f026ab4d30 728
yabahiro 35:94f026ab4d30 729 if(cros==2) {
yabahiro 37:7cfa39c41245 730
yabahiro 37:7cfa39c41245 731 // mode=21;
yabahiro 37:7cfa39c41245 732 // count=0;
yabahiro 37:7cfa39c41245 733 // cros=0;
yabahiro 35:94f026ab4d30 734 }//ゆっくりモードに入れなかった時の保険
yabahiro 35:94f026ab4d30 735
yabahiro 31:45f97698857b 736 switch(g[2]) {
yabahiro 31:45f97698857b 737 case 98:
kishibekairohan 33:656aa14904a5 738 motor[TIRE_FR].pwm = normal;
kishibekairohan 22:c47f29caded6 739 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 740 motor[TIRE_FL].pwm = normal;
kishibekairohan 22:c47f29caded6 741 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 742 motor[TIRE_BR].pwm = normal;
kishibekairohan 22:c47f29caded6 743 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 744 motor[TIRE_BL].pwm = normal;
kishibekairohan 22:c47f29caded6 745 motor[TIRE_BL].dir = BACK;
yabahiro 35:94f026ab4d30 746 if(count>80000) {
yabahiro 31:45f97698857b 747 cross++;
yabahiro 31:45f97698857b 748 count=0;
yabahiro 31:45f97698857b 749 }
yabahiro 31:45f97698857b 750 mtc2=true;
yabahiro 35:94f026ab4d30 751 if(cross==2) {
yabahiro 31:45f97698857b 752 mode=21;
yabahiro 31:45f97698857b 753 count=0;
yabahiro 31:45f97698857b 754 cross=0;
yabahiro 31:45f97698857b 755 }
yabahiro 31:45f97698857b 756 break;
yabahiro 31:45f97698857b 757 case 0:
kishibekairohan 33:656aa14904a5 758 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 759 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 760 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 761 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 762 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 763 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 764 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 765 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 766 mtc2=true;
yabahiro 31:45f97698857b 767 break;
yabahiro 31:45f97698857b 768 case 255:
kishibekairohan 33:656aa14904a5 769 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 770 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 771 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 772 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 773 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 774 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 775 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 776 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 777 mtc2=true;
yabahiro 31:45f97698857b 778 break;
yabahiro 31:45f97698857b 779 case 253:
yabahiro 31:45f97698857b 780 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 781 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 782 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 783 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 784 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 785 motor[TIRE_BR].dir = BACK;
yabahiro 31:45f97698857b 786 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 787 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 788 mtc2=true;
yabahiro 31:45f97698857b 789 break;
yabahiro 31:45f97698857b 790 case 254:
yabahiro 31:45f97698857b 791 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 792 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 793 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 794 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 795 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 796 motor[TIRE_BR].dir = BACK;
yabahiro 31:45f97698857b 797 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 798 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 799 mtc2=true;
yabahiro 31:45f97698857b 800 break;
yabahiro 31:45f97698857b 801 case 1:
kishibekairohan 33:656aa14904a5 802 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 803 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 804 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 805 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 806 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 807 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 808 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 809 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 810 mtc2=true;
yabahiro 31:45f97698857b 811 break;
yabahiro 31:45f97698857b 812 case 3:
kishibekairohan 33:656aa14904a5 813 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 814 motor[TIRE_FR].dir = FOR;
yabahiro 31:45f97698857b 815 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 816 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 817 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 818 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 819 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 820 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 821 mtc2=true;
yabahiro 31:45f97698857b 822 break;
yabahiro 31:45f97698857b 823 case 2:
kishibekairohan 33:656aa14904a5 824 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 825 motor[TIRE_FR].dir = FOR;
yabahiro 31:45f97698857b 826 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 827 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 828 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 829 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 830 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 831 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 832 mtc2=true;
yabahiro 31:45f97698857b 833 break;
yabahiro 31:45f97698857b 834 }
yabahiro 31:45f97698857b 835 if(g[2]!=98&&mtc2==true) {
yabahiro 31:45f97698857b 836 switch(g[3]) {
yabahiro 29:c78a46f51209 837 case 0:
yabahiro 31:45f97698857b 838 mtc2=false;
yabahiro 29:c78a46f51209 839 break;
yabahiro 29:c78a46f51209 840 case 255:
yabahiro 31:45f97698857b 841 motor[TIRE_BL].pwm += 5;
yabahiro 31:45f97698857b 842 mtc2=false;
yabahiro 29:c78a46f51209 843 break;
yabahiro 29:c78a46f51209 844 case 253:
yabahiro 31:45f97698857b 845 motor[TIRE_BL].pwm += 10;
yabahiro 31:45f97698857b 846 mtc2=false;
yabahiro 29:c78a46f51209 847 break;
yabahiro 29:c78a46f51209 848 case 254:
yabahiro 31:45f97698857b 849 motor[TIRE_BL].pwm += 20;
yabahiro 29:c78a46f51209 850 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 851 mtc2=false;
yabahiro 29:c78a46f51209 852 break;
yabahiro 29:c78a46f51209 853 case 1:
yabahiro 31:45f97698857b 854 motor[TIRE_FL].pwm += 5;
yabahiro 31:45f97698857b 855 mtc2=false;
yabahiro 29:c78a46f51209 856 break;
yabahiro 29:c78a46f51209 857 case 3:
yabahiro 31:45f97698857b 858 motor[TIRE_FL].pwm += 10;
yabahiro 31:45f97698857b 859 mtc2=false;
yabahiro 29:c78a46f51209 860 break;
yabahiro 29:c78a46f51209 861 case 2:
yabahiro 31:45f97698857b 862 motor[TIRE_FL].pwm += 20;
yabahiro 31:45f97698857b 863 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 864 mtc2=false;
yabahiro 29:c78a46f51209 865 break;
yabahiro 29:c78a46f51209 866 }
yabahiro 31:45f97698857b 867 }
yabahiro 31:45f97698857b 868 } else if(mode==21) {
yabahiro 31:45f97698857b 869 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 870 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 871 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 872 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 873 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 874 motor[TIRE_BR].dir = BACK;
yabahiro 31:45f97698857b 875 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 876 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 877 if(g[0]==0) {
yabahiro 31:45f97698857b 878 mode=30;
yabahiro 35:94f026ab4d30 879 cros=0;
yabahiro 35:94f026ab4d30 880 zyouge=true;
yabahiro 35:94f026ab4d30 881 if(Twsh==2) {
yabahiro 35:94f026ab4d30 882 solenoid.solenoid2 = SOLENOID_ON;
yabahiro 35:94f026ab4d30 883 }
yabahiro 31:45f97698857b 884 }
yabahiro 31:45f97698857b 885 } else if(mode==30) {
yabahiro 35:94f026ab4d30 886
yabahiro 35:94f026ab4d30 887 if(counts==false&&g[3]==0) {
yabahiro 35:94f026ab4d30 888 counts=false;
yabahiro 35:94f026ab4d30 889 mode=31;
yabahiro 35:94f026ab4d30 890 count=0;
yabahiro 35:94f026ab4d30 891 cros=0;
yabahiro 35:94f026ab4d30 892 }//ゆっくりモードに入れなかった時の保険
yabahiro 35:94f026ab4d30 893
yabahiro 31:45f97698857b 894 switch(g[0]) {
yabahiro 31:45f97698857b 895 case 98:
yabahiro 35:94f026ab4d30 896 motor[TIRE_FR].pwm = 30;
yabahiro 31:45f97698857b 897 motor[TIRE_FR].dir = BACK;
yabahiro 35:94f026ab4d30 898 motor[TIRE_FL].pwm = 30;
yabahiro 31:45f97698857b 899 motor[TIRE_FL].dir = FOR;
yabahiro 35:94f026ab4d30 900 motor[TIRE_BR].pwm = 30;
yabahiro 31:45f97698857b 901 motor[TIRE_BR].dir = BACK;
yabahiro 35:94f026ab4d30 902 motor[TIRE_BL].pwm = 30;
yabahiro 31:45f97698857b 903 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 904 if(count>100000) {
yabahiro 31:45f97698857b 905 cross++;
yabahiro 31:45f97698857b 906 count=0;
yabahiro 31:45f97698857b 907 }
yabahiro 31:45f97698857b 908 mtc=true;
yabahiro 31:45f97698857b 909 if(cross==1) {
yabahiro 35:94f026ab4d30 910 if(Twsh==2) {
yabahiro 35:94f026ab4d30 911 solenoid.solenoid2 = SOLENOID_OFF;
yabahiro 35:94f026ab4d30 912 }
yabahiro 31:45f97698857b 913 mode=31;
yabahiro 31:45f97698857b 914 count=0;
yabahiro 29:c78a46f51209 915 }
yabahiro 31:45f97698857b 916 break;
yabahiro 31:45f97698857b 917 case 0:
yabahiro 35:94f026ab4d30 918 motor[TIRE_FR].pwm = 60;
yabahiro 31:45f97698857b 919 motor[TIRE_FR].dir = BACK;
yabahiro 35:94f026ab4d30 920 motor[TIRE_FL].pwm = 60;
yabahiro 31:45f97698857b 921 motor[TIRE_FL].dir = FOR;
yabahiro 35:94f026ab4d30 922 motor[TIRE_BR].pwm = 60;
yabahiro 31:45f97698857b 923 motor[TIRE_BR].dir = BACK;
yabahiro 35:94f026ab4d30 924 motor[TIRE_BL].pwm = 60;
yabahiro 31:45f97698857b 925 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 926 mtc=true;
yabahiro 31:45f97698857b 927 break;
yabahiro 31:45f97698857b 928 case 255:
yabahiro 35:94f026ab4d30 929 motor[TIRE_FR].pwm = 60;
yabahiro 31:45f97698857b 930 motor[TIRE_FR].dir = BACK;
yabahiro 35:94f026ab4d30 931 motor[TIRE_FL].pwm = 20;
yabahiro 31:45f97698857b 932 motor[TIRE_FL].dir = FOR;
yabahiro 35:94f026ab4d30 933 motor[TIRE_BR].pwm = 20;
yabahiro 31:45f97698857b 934 motor[TIRE_BR].dir = BACK;
yabahiro 35:94f026ab4d30 935 motor[TIRE_BL].pwm = 60;
yabahiro 31:45f97698857b 936 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 937 mtc=true;
yabahiro 31:45f97698857b 938 break;
yabahiro 31:45f97698857b 939 case 253:
yabahiro 35:94f026ab4d30 940 motor[TIRE_FR].pwm = 20;
yabahiro 31:45f97698857b 941 motor[TIRE_FR].dir = BACK;
yabahiro 31:45f97698857b 942 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 943 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 944 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 945 motor[TIRE_BR].dir = FREE;
yabahiro 35:94f026ab4d30 946 motor[TIRE_BL].pwm = 20;
yabahiro 31:45f97698857b 947 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 948 mtc=true;
yabahiro 31:45f97698857b 949 break;
yabahiro 31:45f97698857b 950 case 254:
yabahiro 35:94f026ab4d30 951 motor[TIRE_FR].pwm = 30;
yabahiro 31:45f97698857b 952 motor[TIRE_FR].dir = BACK;
yabahiro 31:45f97698857b 953 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 954 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 955 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 956 motor[TIRE_BR].dir = FREE;
yabahiro 35:94f026ab4d30 957 motor[TIRE_BL].pwm = 30;
yabahiro 31:45f97698857b 958 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 959 mtc=true;
yabahiro 31:45f97698857b 960 break;
yabahiro 31:45f97698857b 961 case 1:
yabahiro 35:94f026ab4d30 962 motor[TIRE_FR].pwm = 20;
yabahiro 31:45f97698857b 963 motor[TIRE_FR].dir = BACK;
yabahiro 35:94f026ab4d30 964 motor[TIRE_FL].pwm = 60;
yabahiro 31:45f97698857b 965 motor[TIRE_FL].dir = FOR;
yabahiro 35:94f026ab4d30 966 motor[TIRE_BR].pwm = 60;
yabahiro 31:45f97698857b 967 motor[TIRE_BR].dir = BACK;
yabahiro 35:94f026ab4d30 968 motor[TIRE_BL].pwm = 20;
yabahiro 31:45f97698857b 969 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 970 mtc=true;
yabahiro 31:45f97698857b 971 break;
yabahiro 31:45f97698857b 972 case 3:
yabahiro 31:45f97698857b 973 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 974 motor[TIRE_FR].dir = FREE;
yabahiro 35:94f026ab4d30 975 motor[TIRE_FL].pwm = 20;
yabahiro 31:45f97698857b 976 motor[TIRE_FL].dir = FOR;
yabahiro 35:94f026ab4d30 977 motor[TIRE_BR].pwm = 20;
yabahiro 31:45f97698857b 978 motor[TIRE_BR].dir = BACK;
yabahiro 31:45f97698857b 979 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 980 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 981 mtc=true;
yabahiro 31:45f97698857b 982 break;
yabahiro 31:45f97698857b 983 case 2:
yabahiro 31:45f97698857b 984 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 985 motor[TIRE_FR].dir = FREE;
yabahiro 35:94f026ab4d30 986 motor[TIRE_FL].pwm = 30;
yabahiro 31:45f97698857b 987 motor[TIRE_FL].dir = FOR;
yabahiro 35:94f026ab4d30 988 motor[TIRE_BR].pwm = 30;
yabahiro 31:45f97698857b 989 motor[TIRE_BR].dir = BACK;
yabahiro 31:45f97698857b 990 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 991 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 992 mtc=true;
yabahiro 31:45f97698857b 993 break;
yabahiro 31:45f97698857b 994 }
yabahiro 31:45f97698857b 995 if(g[0]!=98&&mtc==true) {
yabahiro 31:45f97698857b 996 switch(g[1]) {
yabahiro 29:c78a46f51209 997 case 0:
yabahiro 31:45f97698857b 998 mtc=false;
yabahiro 29:c78a46f51209 999 break;
yabahiro 29:c78a46f51209 1000 case 255:
yabahiro 31:45f97698857b 1001 motor[TIRE_BR].pwm += 5;
yabahiro 31:45f97698857b 1002 mtc=false;
yabahiro 29:c78a46f51209 1003 break;
yabahiro 29:c78a46f51209 1004 case 253:
yabahiro 31:45f97698857b 1005 motor[TIRE_BR].pwm += 10;
yabahiro 31:45f97698857b 1006 mtc=false;
yabahiro 29:c78a46f51209 1007 break;
yabahiro 29:c78a46f51209 1008 case 254:
yabahiro 31:45f97698857b 1009 motor[TIRE_BR].pwm += 20;
yabahiro 31:45f97698857b 1010 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1011 mtc=false;
yabahiro 29:c78a46f51209 1012 break;
yabahiro 29:c78a46f51209 1013 case 1:
yabahiro 31:45f97698857b 1014 motor[TIRE_BL].pwm += 5;
yabahiro 31:45f97698857b 1015 mtc=false;
yabahiro 29:c78a46f51209 1016 break;
yabahiro 29:c78a46f51209 1017 case 3:
yabahiro 31:45f97698857b 1018 motor[TIRE_BL].pwm += 10;
yabahiro 31:45f97698857b 1019 mtc=false;
yabahiro 29:c78a46f51209 1020 break;
yabahiro 29:c78a46f51209 1021 case 2:
yabahiro 31:45f97698857b 1022 motor[TIRE_BL].pwm += 20;
yabahiro 31:45f97698857b 1023 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1024 mtc=false;
yabahiro 29:c78a46f51209 1025 break;
yabahiro 29:c78a46f51209 1026 }
yabahiro 31:45f97698857b 1027 }
yabahiro 31:45f97698857b 1028 } else if(mode==31) {
yabahiro 35:94f026ab4d30 1029 motor[TIRE_FR].pwm = 30;
yabahiro 31:45f97698857b 1030 motor[TIRE_FR].dir = BACK;
yabahiro 31:45f97698857b 1031 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1032 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 1033 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1034 motor[TIRE_BR].dir = FREE;
yabahiro 35:94f026ab4d30 1035 motor[TIRE_BL].pwm = 30;
yabahiro 31:45f97698857b 1036 motor[TIRE_BL].dir = FOR;
yabahiro 35:94f026ab4d30 1037 if(g[3]==0) {
yabahiro 31:45f97698857b 1038 count=0;
yabahiro 31:45f97698857b 1039 mode=40;
yabahiro 31:45f97698857b 1040 }
yabahiro 31:45f97698857b 1041 } else if(mode==40) {
yabahiro 35:94f026ab4d30 1042
yabahiro 35:94f026ab4d30 1043 if(counts==false&&g[0]==0) {
yabahiro 35:94f026ab4d30 1044 cros++;
yabahiro 35:94f026ab4d30 1045 counts=true;
yabahiro 35:94f026ab4d30 1046 }
yabahiro 35:94f026ab4d30 1047 if(counts==true&&g[0]==99) {
yabahiro 35:94f026ab4d30 1048 counts=false;
yabahiro 35:94f026ab4d30 1049 }
yabahiro 35:94f026ab4d30 1050
yabahiro 35:94f026ab4d30 1051 if(cros==2) {
yabahiro 36:788274604650 1052 // mode=41;
yabahiro 35:94f026ab4d30 1053 //count=0;
yabahiro 35:94f026ab4d30 1054 //cros=0;
yabahiro 35:94f026ab4d30 1055 }//ゆっくりモードに入れなかった時の保険
yabahiro 35:94f026ab4d30 1056
yabahiro 31:45f97698857b 1057 switch(g[3]) {
yabahiro 31:45f97698857b 1058 case 98:
kishibekairohan 33:656aa14904a5 1059 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 1060 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 1061 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 1062 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1063 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 1064 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1065 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 1066 motor[TIRE_BL].dir = FOR;
yabahiro 35:94f026ab4d30 1067 if(count>20000) {
yabahiro 31:45f97698857b 1068 cross++;
yabahiro 31:45f97698857b 1069 count=0;
yabahiro 31:45f97698857b 1070 }
yabahiro 31:45f97698857b 1071 mtc2=true;
yabahiro 35:94f026ab4d30 1072 if(cross==3) {
yabahiro 31:45f97698857b 1073 mode=41;
yabahiro 31:45f97698857b 1074 count=0;
yabahiro 31:45f97698857b 1075 cross=0;
kishibekairohan 22:c47f29caded6 1076 }
yabahiro 31:45f97698857b 1077 break;
yabahiro 31:45f97698857b 1078 case 0:
kishibekairohan 33:656aa14904a5 1079 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 1080 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 1081 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 1082 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1083 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 1084 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1085 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 1086 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 1087 mtc2=true;
yabahiro 31:45f97698857b 1088 break;
yabahiro 31:45f97698857b 1089 case 255:
kishibekairohan 33:656aa14904a5 1090 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 1091 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 1092 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 1093 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1094 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 1095 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1096 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 1097 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 1098 mtc2=true;
yabahiro 31:45f97698857b 1099 break;
yabahiro 31:45f97698857b 1100 case 253:
yabahiro 31:45f97698857b 1101 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1102 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 1103 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 1104 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1105 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 1106 motor[TIRE_BR].dir = FOR;
yabahiro 31:45f97698857b 1107 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1108 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 1109 mtc2=true;
yabahiro 31:45f97698857b 1110 break;
yabahiro 31:45f97698857b 1111 case 254:
yabahiro 31:45f97698857b 1112 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1113 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 1114 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 1115 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1116 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 1117 motor[TIRE_BR].dir = FOR;
yabahiro 31:45f97698857b 1118 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1119 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 1120 mtc2=true;
yabahiro 31:45f97698857b 1121 break;
yabahiro 31:45f97698857b 1122 case 1:
kishibekairohan 33:656aa14904a5 1123 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 1124 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 1125 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 1126 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1127 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 1128 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1129 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 1130 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 1131 mtc2=true;
yabahiro 31:45f97698857b 1132 break;
yabahiro 31:45f97698857b 1133 case 3:
kishibekairohan 33:656aa14904a5 1134 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 1135 motor[TIRE_FR].dir = BACK;
yabahiro 31:45f97698857b 1136 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1137 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 1138 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1139 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 1140 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 1141 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 1142 mtc2=true;
yabahiro 31:45f97698857b 1143 break;
yabahiro 31:45f97698857b 1144 case 2:
kishibekairohan 33:656aa14904a5 1145 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 1146 motor[TIRE_FR].dir = BACK;
yabahiro 31:45f97698857b 1147 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1148 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 1149 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1150 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 1151 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 1152 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 1153 mtc2=true;
yabahiro 31:45f97698857b 1154 break;
yabahiro 31:45f97698857b 1155 }
yabahiro 31:45f97698857b 1156 if(g[2]!=98&&mtc2==true) {
yabahiro 31:45f97698857b 1157 switch(g[2]) {
yabahiro 29:c78a46f51209 1158 case 0:
yabahiro 31:45f97698857b 1159 mtc2=false;
yabahiro 29:c78a46f51209 1160 break;
yabahiro 29:c78a46f51209 1161 case 255:
yabahiro 31:45f97698857b 1162 motor[TIRE_FL].pwm += 5;
yabahiro 31:45f97698857b 1163 mtc2=false;
yabahiro 29:c78a46f51209 1164 break;
yabahiro 29:c78a46f51209 1165 case 253:
yabahiro 31:45f97698857b 1166 motor[TIRE_FL].pwm += 10;
yabahiro 31:45f97698857b 1167 mtc2=false;
yabahiro 29:c78a46f51209 1168 break;
yabahiro 29:c78a46f51209 1169 case 254:
yabahiro 31:45f97698857b 1170 motor[TIRE_FL].pwm += 20;
yabahiro 29:c78a46f51209 1171 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1172 mtc2=false;
yabahiro 29:c78a46f51209 1173 break;
yabahiro 29:c78a46f51209 1174 case 1:
yabahiro 31:45f97698857b 1175 motor[TIRE_BL].pwm += 5;
yabahiro 31:45f97698857b 1176 mtc2=false;
yabahiro 29:c78a46f51209 1177 break;
yabahiro 29:c78a46f51209 1178 case 3:
yabahiro 31:45f97698857b 1179 motor[TIRE_BL].pwm += 10;
yabahiro 31:45f97698857b 1180 mtc2=false;
yabahiro 29:c78a46f51209 1181 break;
yabahiro 29:c78a46f51209 1182 case 2:
yabahiro 31:45f97698857b 1183 motor[TIRE_BL].pwm += 20;
yabahiro 29:c78a46f51209 1184 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1185 mtc2=false;
yabahiro 29:c78a46f51209 1186 break;
yabahiro 29:c78a46f51209 1187 }
yabahiro 31:45f97698857b 1188 }
yabahiro 31:45f97698857b 1189 } else if(mode==41) {
yabahiro 31:45f97698857b 1190 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1191 motor[TIRE_FR].dir = FREE;
yabahiro 35:94f026ab4d30 1192 motor[TIRE_FL].pwm = 30;
yabahiro 31:45f97698857b 1193 motor[TIRE_FL].dir = BACK;
yabahiro 35:94f026ab4d30 1194 motor[TIRE_BR].pwm = 30;
yabahiro 31:45f97698857b 1195 motor[TIRE_BR].dir = FOR;
yabahiro 31:45f97698857b 1196 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1197 motor[TIRE_BL].dir = FREE;
yabahiro 35:94f026ab4d30 1198 if(g[1]==0) {
yabahiro 31:45f97698857b 1199 count=0;
yabahiro 31:45f97698857b 1200 mode=70;
yabahiro 31:45f97698857b 1201 }
yabahiro 35:94f026ab4d30 1202
yabahiro 31:45f97698857b 1203 } else if(mode==70) {
yabahiro 31:45f97698857b 1204 switch(g[1]) {
yabahiro 31:45f97698857b 1205 case 99:
yabahiro 31:45f97698857b 1206 if(count>=100000) {
yabahiro 31:45f97698857b 1207 mode=100;
yabahiro 29:c78a46f51209 1208 }
yabahiro 31:45f97698857b 1209 break;
yabahiro 31:45f97698857b 1210 case 98:
kishibekairohan 33:656aa14904a5 1211 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 1212 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 1213 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 1214 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1215 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 1216 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1217 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 1218 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1219 break;
yabahiro 31:45f97698857b 1220 case 0:
kishibekairohan 33:656aa14904a5 1221 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 1222 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 1223 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 1224 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1225 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 1226 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1227 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 1228 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1229 mtc=true;
yabahiro 31:45f97698857b 1230 break;
yabahiro 31:45f97698857b 1231 case 255:
kishibekairohan 33:656aa14904a5 1232 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 1233 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 1234 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 1235 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1236 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 1237 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1238 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 1239 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1240 mtc=true;
yabahiro 31:45f97698857b 1241 break;
yabahiro 31:45f97698857b 1242 case 253:
kishibekairohan 33:656aa14904a5 1243 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 1244 motor[TIRE_FR].dir = FOR;
yabahiro 31:45f97698857b 1245 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1246 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 1247 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1248 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 1249 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 1250 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1251 mtc=true;
yabahiro 31:45f97698857b 1252 break;
yabahiro 31:45f97698857b 1253 case 254:
kishibekairohan 33:656aa14904a5 1254 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 1255 motor[TIRE_FR].dir = FOR;
yabahiro 31:45f97698857b 1256 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1257 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 1258 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1259 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 1260 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 1261 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1262 mtc=true;
yabahiro 31:45f97698857b 1263 break;
yabahiro 31:45f97698857b 1264 case 1:
kishibekairohan 33:656aa14904a5 1265 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 1266 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 1267 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 1268 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1269 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 1270 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1271 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 1272 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1273 mtc=true;
yabahiro 31:45f97698857b 1274 break;
yabahiro 31:45f97698857b 1275 case 3:
yabahiro 31:45f97698857b 1276 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1277 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 1278 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 1279 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1280 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 1281 motor[TIRE_BR].dir = FOR;
yabahiro 31:45f97698857b 1282 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1283 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 1284 mtc=true;
yabahiro 31:45f97698857b 1285 break;
yabahiro 31:45f97698857b 1286 case 2:
yabahiro 31:45f97698857b 1287 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1288 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 1289 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 1290 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1291 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 1292 motor[TIRE_BR].dir = FOR;
yabahiro 31:45f97698857b 1293 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1294 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 1295 mtc=true;
yabahiro 31:45f97698857b 1296 break;
yabahiro 31:45f97698857b 1297 }
yabahiro 31:45f97698857b 1298 if(g[1]!=98&&mtc==true) {
yabahiro 31:45f97698857b 1299 switch(g[0]) {
yabahiro 29:c78a46f51209 1300 case 0:
yabahiro 31:45f97698857b 1301 mtc=false;
yabahiro 29:c78a46f51209 1302 break;
yabahiro 29:c78a46f51209 1303 case 255:
yabahiro 31:45f97698857b 1304 motor[TIRE_FL].pwm += 5;
yabahiro 31:45f97698857b 1305 mtc=false;
yabahiro 29:c78a46f51209 1306 break;
yabahiro 29:c78a46f51209 1307 case 253:
yabahiro 31:45f97698857b 1308 motor[TIRE_FL].pwm += 10;
yabahiro 31:45f97698857b 1309 mtc=false;
yabahiro 29:c78a46f51209 1310 break;
yabahiro 29:c78a46f51209 1311 case 254:
yabahiro 31:45f97698857b 1312 motor[TIRE_FL].pwm += 20;
yabahiro 31:45f97698857b 1313 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1314 mtc=false;
yabahiro 29:c78a46f51209 1315 break;
yabahiro 29:c78a46f51209 1316 case 1:
yabahiro 31:45f97698857b 1317 motor[TIRE_FR].pwm += 5;
yabahiro 31:45f97698857b 1318 mtc=false;
yabahiro 29:c78a46f51209 1319 break;
yabahiro 29:c78a46f51209 1320 case 3:
yabahiro 31:45f97698857b 1321 motor[TIRE_FR].pwm += 10;
yabahiro 31:45f97698857b 1322 mtc=false;
yabahiro 29:c78a46f51209 1323 break;
yabahiro 29:c78a46f51209 1324 case 2:
yabahiro 31:45f97698857b 1325 motor[TIRE_FR].pwm += 20;
yabahiro 31:45f97698857b 1326 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1327 mtc=false;
yabahiro 29:c78a46f51209 1328 break;
yabahiro 29:c78a46f51209 1329 }
yabahiro 31:45f97698857b 1330 }
yabahiro 31:45f97698857b 1331 } else if(mode==100) {
yabahiro 35:94f026ab4d30 1332 motor[TIRE_FR].pwm = 20;
yabahiro 31:45f97698857b 1333 motor[TIRE_FR].dir = FOR;
yabahiro 35:94f026ab4d30 1334 motor[TIRE_FL].pwm = 20;
yabahiro 31:45f97698857b 1335 motor[TIRE_FL].dir = BACK;
yabahiro 31:45f97698857b 1336 motor[TIRE_BR].pwm = 23;
yabahiro 31:45f97698857b 1337 motor[TIRE_BR].dir = FOR;
yabahiro 35:94f026ab4d30 1338 motor[TIRE_BL].pwm = 20;
yabahiro 31:45f97698857b 1339 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1340 } else {
yabahiro 31:45f97698857b 1341 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1342 motor[TIRE_FR].dir = BRAKE;
yabahiro 31:45f97698857b 1343 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1344 motor[TIRE_FL].dir = BRAKE;
yabahiro 31:45f97698857b 1345 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1346 motor[TIRE_BR].dir = BRAKE;
yabahiro 31:45f97698857b 1347 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1348 motor[TIRE_BL].dir = BRAKE;
yabahiro 31:45f97698857b 1349 }
yabahiro 31:45f97698857b 1350 }
yabahiro 31:45f97698857b 1351 #endif
yabahiro 31:45f97698857b 1352
yabahiro 31:45f97698857b 1353 #if USE_PROCESS_NUM>3
yabahiro 31:45f97698857b 1354 static void Process3()
yabahiro 31:45f97698857b 1355 {
yabahiro 36:788274604650 1356 }
yabahiro 36:788274604650 1357 #endif
yabahiro 36:788274604650 1358
yabahiro 36:788274604650 1359 #if USE_PROCESS_NUM>4
yabahiro 36:788274604650 1360 static void Process4()
yabahiro 36:788274604650 1361 {
yabahiro 36:788274604650 1362 LedMode(4);
yabahiro 36:788274604650 1363 count++;
yabahiro 31:45f97698857b 1364 if(mode==1) {//スタートゾーンから白線検知
kishibekairohan 33:656aa14904a5 1365 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 1366 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 1367 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 1368 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1369 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 1370 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1371 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 1372 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1373 if(g[2]==0) {
yabahiro 31:45f97698857b 1374 count=100000;
yabahiro 31:45f97698857b 1375 cross=0;
yabahiro 36:788274604650 1376 mode=3;
yabahiro 31:45f97698857b 1377 }
yabahiro 36:788274604650 1378 } else if(mode==3) { //横ライントレースから縦ライントレースへ
yabahiro 36:788274604650 1379 motor[TIRE_FR].pwm = normal;
kishibekairohan 32:90f018b10ad6 1380 motor[TIRE_FR].dir = FOR;
yabahiro 36:788274604650 1381 motor[TIRE_FL].pwm = 0;
kishibekairohan 32:90f018b10ad6 1382 motor[TIRE_FL].dir = FREE;
yabahiro 36:788274604650 1383 motor[TIRE_BR].pwm = 0;
kishibekairohan 32:90f018b10ad6 1384 motor[TIRE_BR].dir = FREE;
yabahiro 36:788274604650 1385 motor[TIRE_BL].pwm = normal;
kishibekairohan 32:90f018b10ad6 1386 motor[TIRE_BL].dir = BACK;
yabahiro 35:94f026ab4d30 1387 if(g[0]==0) {
yabahiro 36:788274604650 1388 mode=10;
yabahiro 36:788274604650 1389 count=100000;
yabahiro 36:788274604650 1390 }
yabahiro 36:788274604650 1391 } else if(mode==10) { //縦ライントレース
yabahiro 36:788274604650 1392
yabahiro 36:788274604650 1393 if(counts==false&&g[2]==0) {
yabahiro 36:788274604650 1394 cros++;
yabahiro 36:788274604650 1395 counts=true;
yabahiro 36:788274604650 1396 }
yabahiro 36:788274604650 1397 if(counts==true&&g[2]==99) {
yabahiro 36:788274604650 1398 counts=false;
yabahiro 36:788274604650 1399 }
yabahiro 36:788274604650 1400
yabahiro 36:788274604650 1401 if(cros==Twsh) {
yabahiro 36:788274604650 1402 mode=11;
yabahiro 31:45f97698857b 1403 count=0;
yabahiro 36:788274604650 1404 cros=0;
yabahiro 36:788274604650 1405 }//ゆっくりモードに入れなかった時の保険
kishibekairohan 32:90f018b10ad6 1406 switch(g[1]) {
yabahiro 31:45f97698857b 1407 case 98:
kishibekairohan 33:656aa14904a5 1408 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 1409 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 1410 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 1411 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1412 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 1413 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1414 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 1415 motor[TIRE_BL].dir = BACK;
yabahiro 36:788274604650 1416 mtc=true;
yabahiro 36:788274604650 1417 if(count>80000) {
yabahiro 31:45f97698857b 1418 cross++;
yabahiro 31:45f97698857b 1419 count=0;
yabahiro 31:45f97698857b 1420 }
yabahiro 31:45f97698857b 1421 if(cross==Twsh) {
yabahiro 31:45f97698857b 1422 mode=11;
yabahiro 31:45f97698857b 1423 count=0;
yabahiro 36:788274604650 1424 cross=0;
yabahiro 31:45f97698857b 1425 }
yabahiro 31:45f97698857b 1426 break;
yabahiro 31:45f97698857b 1427 case 0:
kishibekairohan 33:656aa14904a5 1428 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 1429 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 1430 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 1431 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1432 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 1433 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1434 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 1435 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1436 mtc=true;
yabahiro 31:45f97698857b 1437 break;
yabahiro 31:45f97698857b 1438 case 255:
kishibekairohan 33:656aa14904a5 1439 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 1440 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 1441 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 1442 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1443 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 1444 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1445 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 1446 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1447 mtc=true;
yabahiro 31:45f97698857b 1448 break;
yabahiro 31:45f97698857b 1449 case 253:
kishibekairohan 33:656aa14904a5 1450 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 1451 motor[TIRE_FR].dir = FOR;
yabahiro 31:45f97698857b 1452 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1453 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 1454 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1455 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 1456 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 1457 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1458 mtc=true;
yabahiro 31:45f97698857b 1459 break;
yabahiro 31:45f97698857b 1460 case 254:
kishibekairohan 33:656aa14904a5 1461 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 1462 motor[TIRE_FR].dir = FOR;
yabahiro 31:45f97698857b 1463 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1464 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 1465 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1466 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 1467 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 1468 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1469 mtc=true;
yabahiro 31:45f97698857b 1470 break;
yabahiro 31:45f97698857b 1471 case 1:
kishibekairohan 33:656aa14904a5 1472 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 1473 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 1474 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 1475 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1476 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 1477 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1478 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 1479 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1480 mtc=true;
yabahiro 31:45f97698857b 1481 break;
yabahiro 31:45f97698857b 1482 case 3:
yabahiro 31:45f97698857b 1483 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1484 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 1485 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 1486 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1487 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 1488 motor[TIRE_BR].dir = FOR;
yabahiro 31:45f97698857b 1489 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1490 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 1491 mtc=true;
yabahiro 31:45f97698857b 1492 break;
yabahiro 31:45f97698857b 1493 case 2:
yabahiro 31:45f97698857b 1494 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1495 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 1496 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 1497 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1498 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 1499 motor[TIRE_BR].dir = FOR;
yabahiro 31:45f97698857b 1500 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1501 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 1502 mtc=true;
yabahiro 31:45f97698857b 1503 break;
yabahiro 31:45f97698857b 1504 }
yabahiro 36:788274604650 1505 if(g[0]!=98&&mtc==true) {
yabahiro 36:788274604650 1506 switch(g[1]) {
yabahiro 31:45f97698857b 1507 case 0:
yabahiro 31:45f97698857b 1508 mtc=false;
yabahiro 31:45f97698857b 1509 break;
yabahiro 31:45f97698857b 1510 case 255:
kishibekairohan 32:90f018b10ad6 1511 motor[TIRE_FL].pwm += 5;
yabahiro 31:45f97698857b 1512 mtc=false;
yabahiro 31:45f97698857b 1513 break;
yabahiro 31:45f97698857b 1514 case 253:
kishibekairohan 32:90f018b10ad6 1515 motor[TIRE_FL].pwm += 10;
yabahiro 31:45f97698857b 1516 mtc=false;
yabahiro 31:45f97698857b 1517 break;
yabahiro 31:45f97698857b 1518 case 254:
kishibekairohan 32:90f018b10ad6 1519 motor[TIRE_FL].pwm += 20;
kishibekairohan 32:90f018b10ad6 1520 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1521 mtc=false;
yabahiro 31:45f97698857b 1522 break;
yabahiro 31:45f97698857b 1523 case 1:
kishibekairohan 32:90f018b10ad6 1524 motor[TIRE_FR].pwm += 5;
yabahiro 31:45f97698857b 1525 mtc=false;
yabahiro 31:45f97698857b 1526 break;
yabahiro 31:45f97698857b 1527 case 3:
kishibekairohan 32:90f018b10ad6 1528 motor[TIRE_FR].pwm += 10;
yabahiro 31:45f97698857b 1529 mtc=false;
yabahiro 31:45f97698857b 1530 break;
yabahiro 31:45f97698857b 1531 case 2:
kishibekairohan 32:90f018b10ad6 1532 motor[TIRE_FR].pwm += 20;
kishibekairohan 32:90f018b10ad6 1533 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1534 mtc=false;
yabahiro 31:45f97698857b 1535 break;
yabahiro 29:c78a46f51209 1536 }
yabahiro 31:45f97698857b 1537 }
yabahiro 31:45f97698857b 1538 } else if(mode==11) {
yabahiro 36:788274604650 1539 motor[TIRE_FR].pwm = normal;
kishibekairohan 32:90f018b10ad6 1540 motor[TIRE_FR].dir = FOR;
yabahiro 36:788274604650 1541 motor[TIRE_FL].pwm = 0;
kishibekairohan 32:90f018b10ad6 1542 motor[TIRE_FL].dir = FREE;
yabahiro 36:788274604650 1543 motor[TIRE_BR].pwm = 0;
kishibekairohan 32:90f018b10ad6 1544 motor[TIRE_BR].dir = FREE;
yabahiro 36:788274604650 1545 motor[TIRE_BL].pwm = normal;
kishibekairohan 32:90f018b10ad6 1546 motor[TIRE_BL].dir = BACK;
yabahiro 35:94f026ab4d30 1547 if(g[2]==0) {
yabahiro 31:45f97698857b 1548 count=0;
yabahiro 36:788274604650 1549 cross=0;
yabahiro 31:45f97698857b 1550 mode=20;
yabahiro 31:45f97698857b 1551 }
yabahiro 31:45f97698857b 1552 } else if(mode==20) {
yabahiro 36:788274604650 1553
yabahiro 36:788274604650 1554 if(counts==false&&g[1]==0) {
yabahiro 36:788274604650 1555 cros++;
yabahiro 36:788274604650 1556 counts=true;
yabahiro 36:788274604650 1557 }
yabahiro 36:788274604650 1558 if(counts==true&&g[1]==99) {
yabahiro 36:788274604650 1559 counts=false;
yabahiro 36:788274604650 1560 }
yabahiro 36:788274604650 1561
yabahiro 36:788274604650 1562 if(cros==2) {
yabahiro 36:788274604650 1563 mode=21;
yabahiro 36:788274604650 1564 count=0;
yabahiro 36:788274604650 1565 cros=0;
yabahiro 36:788274604650 1566 }//ゆっくりモードに入れなかった時の保険
yabahiro 36:788274604650 1567
yabahiro 31:45f97698857b 1568 switch(g[2]) {
yabahiro 31:45f97698857b 1569 case 98:
kishibekairohan 33:656aa14904a5 1570 motor[TIRE_FR].pwm = normal;
kishibekairohan 22:c47f29caded6 1571 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 1572 motor[TIRE_FL].pwm = normal;
yabahiro 23:694ecfa97839 1573 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 1574 motor[TIRE_BR].pwm = normal;
yabahiro 23:694ecfa97839 1575 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 1576 motor[TIRE_BL].pwm = normal;
yabahiro 29:c78a46f51209 1577 motor[TIRE_BL].dir = BACK;
yabahiro 36:788274604650 1578 if(count>80000) {
yabahiro 31:45f97698857b 1579 cross++;
yabahiro 31:45f97698857b 1580 count=0;
yabahiro 31:45f97698857b 1581 }
yabahiro 31:45f97698857b 1582 mtc2=true;
yabahiro 36:788274604650 1583 if(cross==2) {
yabahiro 31:45f97698857b 1584 mode=21;
yabahiro 31:45f97698857b 1585 count=0;
yabahiro 31:45f97698857b 1586 cross=0;
yabahiro 31:45f97698857b 1587 }
yabahiro 31:45f97698857b 1588 break;
yabahiro 31:45f97698857b 1589 case 0:
kishibekairohan 33:656aa14904a5 1590 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 1591 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 1592 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 1593 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 1594 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 1595 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 1596 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 1597 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1598 mtc2=true;
yabahiro 31:45f97698857b 1599 break;
yabahiro 31:45f97698857b 1600 case 255:
yabahiro 36:788274604650 1601 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 1602 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 1603 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 1604 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 1605 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 1606 motor[TIRE_BR].dir = BACK;
yabahiro 36:788274604650 1607 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 1608 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1609 mtc2=true;
yabahiro 31:45f97698857b 1610 break;
yabahiro 31:45f97698857b 1611 case 253:
yabahiro 31:45f97698857b 1612 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1613 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 1614 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 1615 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 1616 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 1617 motor[TIRE_BR].dir = BACK;
yabahiro 31:45f97698857b 1618 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1619 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 1620 mtc2=true;
yabahiro 31:45f97698857b 1621 break;
yabahiro 31:45f97698857b 1622 case 254:
yabahiro 31:45f97698857b 1623 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1624 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 1625 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 1626 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 1627 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 1628 motor[TIRE_BR].dir = BACK;
yabahiro 31:45f97698857b 1629 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1630 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 1631 mtc2=true;
yabahiro 31:45f97698857b 1632 break;
yabahiro 31:45f97698857b 1633 case 1:
kishibekairohan 33:656aa14904a5 1634 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 1635 motor[TIRE_FR].dir = FOR;
kishibekairohan 33:656aa14904a5 1636 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 1637 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 1638 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 1639 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 1640 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 1641 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1642 mtc2=true;
yabahiro 31:45f97698857b 1643 break;
yabahiro 31:45f97698857b 1644 case 3:
kishibekairohan 33:656aa14904a5 1645 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 1646 motor[TIRE_FR].dir = FOR;
yabahiro 31:45f97698857b 1647 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1648 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 1649 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1650 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 1651 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 1652 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1653 mtc2=true;
yabahiro 31:45f97698857b 1654 break;
yabahiro 31:45f97698857b 1655 case 2:
kishibekairohan 33:656aa14904a5 1656 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 1657 motor[TIRE_FR].dir = FOR;
yabahiro 31:45f97698857b 1658 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1659 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 1660 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1661 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 1662 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 1663 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1664 mtc2=true;
yabahiro 31:45f97698857b 1665 break;
yabahiro 31:45f97698857b 1666 }
yabahiro 31:45f97698857b 1667 if(g[2]!=98&&mtc2==true) {
yabahiro 31:45f97698857b 1668 switch(g[3]) {
yabahiro 23:694ecfa97839 1669 case 0:
yabahiro 31:45f97698857b 1670 mtc2=false;
yabahiro 23:694ecfa97839 1671 break;
yabahiro 23:694ecfa97839 1672 case 255:
yabahiro 31:45f97698857b 1673 motor[TIRE_BL].pwm += 5;
yabahiro 31:45f97698857b 1674 mtc2=false;
yabahiro 23:694ecfa97839 1675 break;
yabahiro 23:694ecfa97839 1676 case 253:
yabahiro 31:45f97698857b 1677 motor[TIRE_BL].pwm += 10;
yabahiro 31:45f97698857b 1678 mtc2=false;
yabahiro 23:694ecfa97839 1679 break;
yabahiro 23:694ecfa97839 1680 case 254:
yabahiro 31:45f97698857b 1681 motor[TIRE_BL].pwm += 20;
yabahiro 29:c78a46f51209 1682 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1683 mtc2=false;
yabahiro 23:694ecfa97839 1684 break;
yabahiro 23:694ecfa97839 1685 case 1:
yabahiro 31:45f97698857b 1686 motor[TIRE_FL].pwm += 5;
yabahiro 31:45f97698857b 1687 mtc2=false;
yabahiro 23:694ecfa97839 1688 break;
yabahiro 23:694ecfa97839 1689 case 3:
yabahiro 31:45f97698857b 1690 motor[TIRE_FL].pwm += 10;
yabahiro 31:45f97698857b 1691 mtc2=false;
yabahiro 23:694ecfa97839 1692 break;
yabahiro 23:694ecfa97839 1693 case 2:
yabahiro 31:45f97698857b 1694 motor[TIRE_FL].pwm += 20;
yabahiro 31:45f97698857b 1695 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1696 mtc2=false;
yabahiro 29:c78a46f51209 1697 break;
yabahiro 29:c78a46f51209 1698 }
yabahiro 31:45f97698857b 1699 }
yabahiro 31:45f97698857b 1700 } else if(mode==21) {
yabahiro 36:788274604650 1701 motor[TIRE_FR].pwm = normal;
kishibekairohan 32:90f018b10ad6 1702 motor[TIRE_FR].dir = FOR;
yabahiro 36:788274604650 1703 motor[TIRE_FL].pwm = 0;
kishibekairohan 32:90f018b10ad6 1704 motor[TIRE_FL].dir = FREE;
yabahiro 36:788274604650 1705 motor[TIRE_BR].pwm = 0;
kishibekairohan 32:90f018b10ad6 1706 motor[TIRE_BR].dir = FREE;
yabahiro 36:788274604650 1707 motor[TIRE_BL].pwm = normal;
kishibekairohan 32:90f018b10ad6 1708 motor[TIRE_BL].dir = BACK;
yabahiro 35:94f026ab4d30 1709 if(g[1]==0) {
yabahiro 31:45f97698857b 1710 mode=30;
yabahiro 36:788274604650 1711 cros=0;
yabahiro 36:788274604650 1712 zyouge=true;
yabahiro 36:788274604650 1713 if(Twsh==2) {
yabahiro 36:788274604650 1714 solenoid.solenoid2 = SOLENOID_ON;
yabahiro 36:788274604650 1715 }
yabahiro 31:45f97698857b 1716 }
yabahiro 31:45f97698857b 1717 } else if(mode==30) {
yabahiro 36:788274604650 1718
yabahiro 36:788274604650 1719 if(counts==false&&g[3]==0) {
yabahiro 36:788274604650 1720 counts=false;
yabahiro 36:788274604650 1721 mode=31;
yabahiro 36:788274604650 1722 count=0;
yabahiro 36:788274604650 1723 cros=0;
yabahiro 36:788274604650 1724 }//ゆっくりモードに入れなかった時の保険
yabahiro 36:788274604650 1725
kishibekairohan 32:90f018b10ad6 1726 switch(g[1]) {
yabahiro 31:45f97698857b 1727 case 98:
yabahiro 36:788274604650 1728 motor[TIRE_FR].pwm = 30;
yabahiro 31:45f97698857b 1729 motor[TIRE_FR].dir = FOR;
yabahiro 36:788274604650 1730 motor[TIRE_FL].pwm = 30;
yabahiro 31:45f97698857b 1731 motor[TIRE_FL].dir = BACK;
yabahiro 36:788274604650 1732 motor[TIRE_BR].pwm = 30;
yabahiro 31:45f97698857b 1733 motor[TIRE_BR].dir = FOR;
yabahiro 36:788274604650 1734 motor[TIRE_BL].pwm = 30;
yabahiro 31:45f97698857b 1735 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1736 if(count>100000) {
yabahiro 31:45f97698857b 1737 cross++;
yabahiro 31:45f97698857b 1738 count=0;
yabahiro 31:45f97698857b 1739 }
yabahiro 31:45f97698857b 1740 mtc=true;
yabahiro 31:45f97698857b 1741 if(cross==1) {
yabahiro 36:788274604650 1742 if(Twsh==2) {
yabahiro 36:788274604650 1743 solenoid.solenoid2 = SOLENOID_OFF;
yabahiro 36:788274604650 1744 }
yabahiro 31:45f97698857b 1745 mode=31;
yabahiro 31:45f97698857b 1746 count=0;
yabahiro 29:c78a46f51209 1747 }
yabahiro 31:45f97698857b 1748 break;
yabahiro 31:45f97698857b 1749 case 0:
yabahiro 36:788274604650 1750 motor[TIRE_FR].pwm = 60;
yabahiro 31:45f97698857b 1751 motor[TIRE_FR].dir = FOR;
yabahiro 36:788274604650 1752 motor[TIRE_FL].pwm = 60;
yabahiro 31:45f97698857b 1753 motor[TIRE_FL].dir = BACK;
yabahiro 36:788274604650 1754 motor[TIRE_BR].pwm = 60;
yabahiro 31:45f97698857b 1755 motor[TIRE_BR].dir = FOR;
yabahiro 36:788274604650 1756 motor[TIRE_BL].pwm = 60;
yabahiro 31:45f97698857b 1757 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1758 mtc=true;
yabahiro 31:45f97698857b 1759 break;
yabahiro 31:45f97698857b 1760 case 255:
yabahiro 36:788274604650 1761 motor[TIRE_FR].pwm = 60;
yabahiro 31:45f97698857b 1762 motor[TIRE_FR].dir = FOR;
yabahiro 36:788274604650 1763 motor[TIRE_FL].pwm = 20;
yabahiro 31:45f97698857b 1764 motor[TIRE_FL].dir = BACK;
yabahiro 36:788274604650 1765 motor[TIRE_BR].pwm = 20;
yabahiro 31:45f97698857b 1766 motor[TIRE_BR].dir = FOR;
yabahiro 36:788274604650 1767 motor[TIRE_BL].pwm = 60;
yabahiro 31:45f97698857b 1768 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1769 mtc=true;
yabahiro 31:45f97698857b 1770 break;
yabahiro 31:45f97698857b 1771 case 253:
yabahiro 36:788274604650 1772 motor[TIRE_FR].pwm = 20;
yabahiro 31:45f97698857b 1773 motor[TIRE_FR].dir = FOR;
yabahiro 31:45f97698857b 1774 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1775 motor[TIRE_FL].dir = BACK;
yabahiro 31:45f97698857b 1776 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1777 motor[TIRE_BR].dir = FOR;
yabahiro 36:788274604650 1778 motor[TIRE_BL].pwm = 20;
yabahiro 31:45f97698857b 1779 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1780 mtc=true;
yabahiro 31:45f97698857b 1781 break;
yabahiro 31:45f97698857b 1782 case 254:
yabahiro 36:788274604650 1783 motor[TIRE_FR].pwm = 30;
yabahiro 31:45f97698857b 1784 motor[TIRE_FR].dir = FOR;
yabahiro 31:45f97698857b 1785 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1786 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 1787 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1788 motor[TIRE_BR].dir = FREE;
yabahiro 36:788274604650 1789 motor[TIRE_BL].pwm = 30;
yabahiro 31:45f97698857b 1790 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1791 mtc=true;
yabahiro 31:45f97698857b 1792 break;
yabahiro 31:45f97698857b 1793 case 1:
yabahiro 36:788274604650 1794 motor[TIRE_FR].pwm = 20;
yabahiro 31:45f97698857b 1795 motor[TIRE_FR].dir = FOR;
yabahiro 36:788274604650 1796 motor[TIRE_FL].pwm = 60;
yabahiro 31:45f97698857b 1797 motor[TIRE_FL].dir = BACK;
yabahiro 36:788274604650 1798 motor[TIRE_BR].pwm = 60;
yabahiro 31:45f97698857b 1799 motor[TIRE_BR].dir = FOR;
yabahiro 36:788274604650 1800 motor[TIRE_BL].pwm = 20;
yabahiro 31:45f97698857b 1801 motor[TIRE_BL].dir = BACK;
yabahiro 31:45f97698857b 1802 mtc=true;
yabahiro 31:45f97698857b 1803 break;
yabahiro 31:45f97698857b 1804 case 3:
yabahiro 31:45f97698857b 1805 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1806 motor[TIRE_FR].dir = FREE;
yabahiro 36:788274604650 1807 motor[TIRE_FL].pwm = 20;
yabahiro 31:45f97698857b 1808 motor[TIRE_FL].dir = BACK;
yabahiro 36:788274604650 1809 motor[TIRE_BR].pwm = 20;
yabahiro 31:45f97698857b 1810 motor[TIRE_BR].dir = FOR;
yabahiro 31:45f97698857b 1811 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1812 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 1813 mtc=true;
yabahiro 31:45f97698857b 1814 break;
yabahiro 31:45f97698857b 1815 case 2:
yabahiro 31:45f97698857b 1816 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1817 motor[TIRE_FR].dir = FREE;
yabahiro 36:788274604650 1818 motor[TIRE_FL].pwm = 30;
yabahiro 31:45f97698857b 1819 motor[TIRE_FL].dir = BACK;
yabahiro 36:788274604650 1820 motor[TIRE_BR].pwm = 30;
yabahiro 31:45f97698857b 1821 motor[TIRE_BR].dir = FOR;
yabahiro 31:45f97698857b 1822 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1823 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 1824 mtc=true;
yabahiro 31:45f97698857b 1825 break;
yabahiro 31:45f97698857b 1826 }
kishibekairohan 32:90f018b10ad6 1827 if(g[1]!=98&&mtc==true) {
kishibekairohan 32:90f018b10ad6 1828 switch(g[0]) {
yabahiro 29:c78a46f51209 1829 case 0:
yabahiro 31:45f97698857b 1830 mtc=false;
yabahiro 29:c78a46f51209 1831 break;
yabahiro 29:c78a46f51209 1832 case 255:
kishibekairohan 34:cef6c124a52d 1833 motor[TIRE_FL].pwm += 5;
yabahiro 31:45f97698857b 1834 mtc=false;
yabahiro 29:c78a46f51209 1835 break;
yabahiro 29:c78a46f51209 1836 case 253:
kishibekairohan 34:cef6c124a52d 1837 motor[TIRE_FL].pwm += 10;
yabahiro 31:45f97698857b 1838 mtc=false;
yabahiro 29:c78a46f51209 1839 break;
yabahiro 29:c78a46f51209 1840 case 254:
kishibekairohan 34:cef6c124a52d 1841 motor[TIRE_FL].pwm += 20;
kishibekairohan 34:cef6c124a52d 1842 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1843 mtc=false;
yabahiro 29:c78a46f51209 1844 break;
yabahiro 29:c78a46f51209 1845 case 1:
kishibekairohan 34:cef6c124a52d 1846 motor[TIRE_FR].pwm += 5;
yabahiro 31:45f97698857b 1847 mtc=false;
yabahiro 29:c78a46f51209 1848 break;
yabahiro 29:c78a46f51209 1849 case 3:
kishibekairohan 34:cef6c124a52d 1850 motor[TIRE_FR].pwm += 10;
yabahiro 31:45f97698857b 1851 mtc=false;
yabahiro 29:c78a46f51209 1852 break;
yabahiro 29:c78a46f51209 1853 case 2:
kishibekairohan 34:cef6c124a52d 1854 motor[TIRE_FR].pwm += 20;
kishibekairohan 34:cef6c124a52d 1855 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1856 mtc=false;
yabahiro 23:694ecfa97839 1857 break;
yabahiro 23:694ecfa97839 1858 }
yabahiro 31:45f97698857b 1859 }
yabahiro 31:45f97698857b 1860 } else if(mode==31) {
yabahiro 36:788274604650 1861 motor[TIRE_FR].pwm = 0;
kishibekairohan 32:90f018b10ad6 1862 motor[TIRE_FR].dir = FREE;
yabahiro 36:788274604650 1863 motor[TIRE_FL].pwm = 30;
kishibekairohan 32:90f018b10ad6 1864 motor[TIRE_FL].dir = BACK;
yabahiro 36:788274604650 1865 motor[TIRE_BR].pwm = 30;
kishibekairohan 32:90f018b10ad6 1866 motor[TIRE_BR].dir = FOR;
yabahiro 36:788274604650 1867 motor[TIRE_BL].pwm = 0;
kishibekairohan 32:90f018b10ad6 1868 motor[TIRE_BL].dir = FREE;
yabahiro 35:94f026ab4d30 1869 if(g[3]==0) {
yabahiro 31:45f97698857b 1870 count=0;
yabahiro 31:45f97698857b 1871 mode=40;
yabahiro 31:45f97698857b 1872 }
yabahiro 31:45f97698857b 1873 } else if(mode==40) {
yabahiro 36:788274604650 1874
yabahiro 36:788274604650 1875 if(counts==false&&g[0]==0) {
yabahiro 36:788274604650 1876 cros++;
yabahiro 36:788274604650 1877 counts=true;
yabahiro 36:788274604650 1878 }
yabahiro 36:788274604650 1879 if(counts==true&&g[0]==99) {
yabahiro 36:788274604650 1880 counts=false;
yabahiro 36:788274604650 1881 }
yabahiro 36:788274604650 1882
yabahiro 36:788274604650 1883 if(cros==2) {
yabahiro 36:788274604650 1884 // mode=41;
yabahiro 36:788274604650 1885 //count=0;
yabahiro 36:788274604650 1886 //cros=0;
yabahiro 36:788274604650 1887 }//ゆっくりモードに入れなかった時の保険
yabahiro 36:788274604650 1888
yabahiro 31:45f97698857b 1889 switch(g[3]) {
yabahiro 31:45f97698857b 1890 case 98:
kishibekairohan 33:656aa14904a5 1891 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 1892 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 1893 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 1894 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1895 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 1896 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1897 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 1898 motor[TIRE_BL].dir = FOR;
yabahiro 36:788274604650 1899 if(count>20000) {
yabahiro 31:45f97698857b 1900 cross++;
yabahiro 31:45f97698857b 1901 count=0;
yabahiro 31:45f97698857b 1902 }
yabahiro 31:45f97698857b 1903 mtc2=true;
yabahiro 36:788274604650 1904 if(cross==3) {
yabahiro 31:45f97698857b 1905 mode=41;
yabahiro 31:45f97698857b 1906 count=0;
yabahiro 31:45f97698857b 1907 cross=0;
yabahiro 24:41c23c9a5058 1908 }
yabahiro 31:45f97698857b 1909 break;
yabahiro 31:45f97698857b 1910 case 0:
kishibekairohan 33:656aa14904a5 1911 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 1912 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 1913 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 1914 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1915 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 1916 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1917 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 1918 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 1919 mtc2=true;
yabahiro 31:45f97698857b 1920 break;
yabahiro 31:45f97698857b 1921 case 255:
kishibekairohan 33:656aa14904a5 1922 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 1923 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 1924 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 1925 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1926 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 1927 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1928 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 1929 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 1930 mtc2=true;
yabahiro 31:45f97698857b 1931 break;
yabahiro 31:45f97698857b 1932 case 253:
yabahiro 31:45f97698857b 1933 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1934 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 1935 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 1936 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1937 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 1938 motor[TIRE_BR].dir = FOR;
yabahiro 31:45f97698857b 1939 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1940 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 1941 mtc2=true;
yabahiro 31:45f97698857b 1942 break;
yabahiro 31:45f97698857b 1943 case 254:
yabahiro 31:45f97698857b 1944 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 1945 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 1946 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 1947 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1948 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 1949 motor[TIRE_BR].dir = FOR;
yabahiro 31:45f97698857b 1950 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 1951 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 1952 mtc2=true;
yabahiro 31:45f97698857b 1953 break;
yabahiro 31:45f97698857b 1954 case 1:
kishibekairohan 33:656aa14904a5 1955 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 1956 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 1957 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 1958 motor[TIRE_FL].dir = BACK;
kishibekairohan 33:656aa14904a5 1959 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 1960 motor[TIRE_BR].dir = FOR;
kishibekairohan 33:656aa14904a5 1961 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 1962 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 1963 mtc2=true;
yabahiro 31:45f97698857b 1964 break;
yabahiro 31:45f97698857b 1965 case 3:
kishibekairohan 33:656aa14904a5 1966 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 1967 motor[TIRE_FR].dir = BACK;
yabahiro 31:45f97698857b 1968 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1969 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 1970 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1971 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 1972 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 1973 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 1974 mtc2=true;
yabahiro 31:45f97698857b 1975 break;
yabahiro 31:45f97698857b 1976 case 2:
kishibekairohan 33:656aa14904a5 1977 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 1978 motor[TIRE_FR].dir = BACK;
yabahiro 31:45f97698857b 1979 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 1980 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 1981 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 1982 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 1983 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 1984 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 1985 mtc2=true;
yabahiro 31:45f97698857b 1986 break;
yabahiro 31:45f97698857b 1987 }
yabahiro 31:45f97698857b 1988 if(g[2]!=98&&mtc2==true) {
yabahiro 31:45f97698857b 1989 switch(g[2]) {
yabahiro 23:694ecfa97839 1990 case 0:
yabahiro 31:45f97698857b 1991 mtc2=false;
yabahiro 23:694ecfa97839 1992 break;
yabahiro 23:694ecfa97839 1993 case 255:
yabahiro 31:45f97698857b 1994 motor[TIRE_FL].pwm += 5;
yabahiro 31:45f97698857b 1995 mtc2=false;
yabahiro 23:694ecfa97839 1996 break;
yabahiro 23:694ecfa97839 1997 case 253:
yabahiro 31:45f97698857b 1998 motor[TIRE_FL].pwm += 10;
yabahiro 31:45f97698857b 1999 mtc2=false;
yabahiro 23:694ecfa97839 2000 break;
yabahiro 23:694ecfa97839 2001 case 254:
yabahiro 31:45f97698857b 2002 motor[TIRE_FL].pwm += 20;
yabahiro 29:c78a46f51209 2003 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 2004 mtc2=false;
yabahiro 23:694ecfa97839 2005 break;
yabahiro 23:694ecfa97839 2006 case 1:
yabahiro 31:45f97698857b 2007 motor[TIRE_BL].pwm += 5;
yabahiro 31:45f97698857b 2008 mtc2=false;
yabahiro 23:694ecfa97839 2009 break;
yabahiro 23:694ecfa97839 2010 case 3:
yabahiro 31:45f97698857b 2011 motor[TIRE_BL].pwm += 10;
yabahiro 31:45f97698857b 2012 mtc2=false;
yabahiro 23:694ecfa97839 2013 break;
yabahiro 23:694ecfa97839 2014 case 2:
yabahiro 31:45f97698857b 2015 motor[TIRE_BL].pwm += 20;
yabahiro 27:545148741493 2016 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 2017 mtc2=false;
yabahiro 29:c78a46f51209 2018 break;
yabahiro 29:c78a46f51209 2019 }
yabahiro 31:45f97698857b 2020 }
yabahiro 31:45f97698857b 2021 } else if(mode==41) {
yabahiro 36:788274604650 2022 motor[TIRE_FR].pwm = normal;
kishibekairohan 32:90f018b10ad6 2023 motor[TIRE_FR].dir = BACK;
yabahiro 36:788274604650 2024 motor[TIRE_FL].pwm = 0;
kishibekairohan 32:90f018b10ad6 2025 motor[TIRE_FL].dir = FREE;
yabahiro 36:788274604650 2026 motor[TIRE_BR].pwm = 0;
kishibekairohan 32:90f018b10ad6 2027 motor[TIRE_BR].dir = FREE;
yabahiro 36:788274604650 2028 motor[TIRE_BL].pwm = normal;
kishibekairohan 32:90f018b10ad6 2029 motor[TIRE_BL].dir = FOR;
yabahiro 36:788274604650 2030 if(g[1]==0) {
yabahiro 31:45f97698857b 2031 count=0;
yabahiro 31:45f97698857b 2032 mode=70;
yabahiro 31:45f97698857b 2033 }
yabahiro 36:788274604650 2034
yabahiro 36:788274604650 2035 } else if(mode==70)
kishibekairohan 32:90f018b10ad6 2036 switch(g[0]) {
yabahiro 31:45f97698857b 2037 case 99:
yabahiro 31:45f97698857b 2038 if(count>=100000) {
yabahiro 31:45f97698857b 2039 mode=100;
yabahiro 28:9cd36721cf83 2040 }
yabahiro 31:45f97698857b 2041 break;
yabahiro 31:45f97698857b 2042 case 98:
kishibekairohan 33:656aa14904a5 2043 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 2044 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 2045 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 2046 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 2047 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 2048 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 2049 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 2050 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 2051 break;
yabahiro 31:45f97698857b 2052 case 0:
kishibekairohan 33:656aa14904a5 2053 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 2054 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 2055 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 2056 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 2057 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 2058 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 2059 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 2060 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 2061 mtc=true;
yabahiro 31:45f97698857b 2062 break;
yabahiro 31:45f97698857b 2063 case 255:
kishibekairohan 33:656aa14904a5 2064 motor[TIRE_FR].pwm = fast;
yabahiro 31:45f97698857b 2065 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 2066 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 2067 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 2068 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 2069 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 2070 motor[TIRE_BL].pwm = fast;
yabahiro 31:45f97698857b 2071 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 2072 mtc=true;
yabahiro 31:45f97698857b 2073 break;
yabahiro 31:45f97698857b 2074 case 253:
kishibekairohan 33:656aa14904a5 2075 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 2076 motor[TIRE_FR].dir = BACK;
yabahiro 31:45f97698857b 2077 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 2078 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 2079 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 2080 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 2081 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 2082 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 2083 mtc=true;
yabahiro 31:45f97698857b 2084 break;
yabahiro 31:45f97698857b 2085 case 254:
kishibekairohan 33:656aa14904a5 2086 motor[TIRE_FR].pwm = normal;
yabahiro 31:45f97698857b 2087 motor[TIRE_FR].dir = BACK;
yabahiro 31:45f97698857b 2088 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 2089 motor[TIRE_FL].dir = FREE;
yabahiro 31:45f97698857b 2090 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 2091 motor[TIRE_BR].dir = FREE;
kishibekairohan 33:656aa14904a5 2092 motor[TIRE_BL].pwm = normal;
yabahiro 31:45f97698857b 2093 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 2094 mtc=true;
yabahiro 31:45f97698857b 2095 break;
yabahiro 31:45f97698857b 2096 case 1:
kishibekairohan 33:656aa14904a5 2097 motor[TIRE_FR].pwm = slow;
yabahiro 31:45f97698857b 2098 motor[TIRE_FR].dir = BACK;
kishibekairohan 33:656aa14904a5 2099 motor[TIRE_FL].pwm = fast;
yabahiro 31:45f97698857b 2100 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 2101 motor[TIRE_BR].pwm = fast;
yabahiro 31:45f97698857b 2102 motor[TIRE_BR].dir = BACK;
kishibekairohan 33:656aa14904a5 2103 motor[TIRE_BL].pwm = slow;
yabahiro 31:45f97698857b 2104 motor[TIRE_BL].dir = FOR;
yabahiro 31:45f97698857b 2105 mtc=true;
yabahiro 31:45f97698857b 2106 break;
yabahiro 31:45f97698857b 2107 case 3:
yabahiro 31:45f97698857b 2108 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 2109 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 2110 motor[TIRE_FL].pwm = slow;
yabahiro 31:45f97698857b 2111 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 2112 motor[TIRE_BR].pwm = slow;
yabahiro 31:45f97698857b 2113 motor[TIRE_BR].dir = BACK;
yabahiro 31:45f97698857b 2114 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 2115 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 2116 mtc=true;
yabahiro 31:45f97698857b 2117 break;
yabahiro 31:45f97698857b 2118 case 2:
yabahiro 31:45f97698857b 2119 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 2120 motor[TIRE_FR].dir = FREE;
kishibekairohan 33:656aa14904a5 2121 motor[TIRE_FL].pwm = normal;
yabahiro 31:45f97698857b 2122 motor[TIRE_FL].dir = FOR;
kishibekairohan 33:656aa14904a5 2123 motor[TIRE_BR].pwm = normal;
yabahiro 31:45f97698857b 2124 motor[TIRE_BR].dir = BACK;
yabahiro 31:45f97698857b 2125 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 2126 motor[TIRE_BL].dir = FREE;
yabahiro 31:45f97698857b 2127 mtc=true;
yabahiro 31:45f97698857b 2128 break;
yabahiro 31:45f97698857b 2129 }
yabahiro 36:788274604650 2130 if(g[1]!=98&&mtc==true) {
yabahiro 36:788274604650 2131 switch(g[0]) {
yabahiro 36:788274604650 2132 case 0:
yabahiro 36:788274604650 2133 mtc=false;
yabahiro 36:788274604650 2134 break;
yabahiro 36:788274604650 2135 case 255:
yabahiro 36:788274604650 2136 motor[TIRE_BR].pwm += 5;
yabahiro 36:788274604650 2137 mtc=false;
yabahiro 36:788274604650 2138 break;
yabahiro 36:788274604650 2139 case 253:
yabahiro 36:788274604650 2140 motor[TIRE_BR].pwm += 10;
yabahiro 36:788274604650 2141 mtc=false;
yabahiro 36:788274604650 2142 break;
yabahiro 36:788274604650 2143 case 254:
yabahiro 36:788274604650 2144 motor[TIRE_BR].pwm += 20;
yabahiro 36:788274604650 2145 motor[TIRE_BL].pwm = 0;
yabahiro 36:788274604650 2146 mtc=false;
yabahiro 36:788274604650 2147 break;
yabahiro 36:788274604650 2148 case 1:
yabahiro 36:788274604650 2149 motor[TIRE_BL].pwm += 5;
yabahiro 36:788274604650 2150 mtc=false;
yabahiro 36:788274604650 2151 break;
yabahiro 36:788274604650 2152 case 3:
yabahiro 36:788274604650 2153 motor[TIRE_BL].pwm += 10;
yabahiro 36:788274604650 2154 mtc=false;
yabahiro 36:788274604650 2155 break;
yabahiro 36:788274604650 2156 case 2:
yabahiro 36:788274604650 2157 motor[TIRE_BL].pwm += 20;
yabahiro 36:788274604650 2158 motor[TIRE_BR].pwm = 0;
yabahiro 36:788274604650 2159 mtc=false;
yabahiro 36:788274604650 2160 break;
yabahiro 24:41c23c9a5058 2161 }
yabahiro 31:45f97698857b 2162 } else if(mode==100) {
yabahiro 36:788274604650 2163 motor[TIRE_FR].pwm = 20;
kishibekairohan 32:90f018b10ad6 2164 motor[TIRE_FR].dir = BACK;
yabahiro 36:788274604650 2165 motor[TIRE_FL].pwm = 20;
kishibekairohan 32:90f018b10ad6 2166 motor[TIRE_FL].dir = FOR;
yabahiro 31:45f97698857b 2167 motor[TIRE_BR].pwm = 23;
kishibekairohan 32:90f018b10ad6 2168 motor[TIRE_BR].dir = BACK;
yabahiro 36:788274604650 2169 motor[TIRE_BL].pwm = 20;
kishibekairohan 32:90f018b10ad6 2170 motor[TIRE_BL].dir = FOR;
yabahiro 36:788274604650 2171 }
yabahiro 36:788274604650 2172 /* else {
yabahiro 31:45f97698857b 2173 motor[TIRE_FR].pwm = 0;
yabahiro 31:45f97698857b 2174 motor[TIRE_FR].dir = BRAKE;
yabahiro 31:45f97698857b 2175 motor[TIRE_FL].pwm = 0;
yabahiro 31:45f97698857b 2176 motor[TIRE_FL].dir = BRAKE;
yabahiro 31:45f97698857b 2177 motor[TIRE_BR].pwm = 0;
yabahiro 31:45f97698857b 2178 motor[TIRE_BR].dir = BRAKE;
yabahiro 31:45f97698857b 2179 motor[TIRE_BL].pwm = 0;
yabahiro 31:45f97698857b 2180 motor[TIRE_BL].dir = BRAKE;
yabahiro 21:1f1e9c585da8 2181 }
yabahiro 36:788274604650 2182 */
kishibekairohan 13:b6e02d6261d7 2183 }
kishibekairohan 13:b6e02d6261d7 2184 #endif
kishibekairohan 13:b6e02d6261d7 2185
kishibekairohan 13:b6e02d6261d7 2186 #if USE_PROCESS_NUM>5
yabahiro 21:1f1e9c585da8 2187 static void Process5()
yabahiro 21:1f1e9c585da8 2188 {
yabahiro 21:1f1e9c585da8 2189
kishibekairohan 13:b6e02d6261d7 2190 }
kishibekairohan 13:b6e02d6261d7 2191 #endif
kishibekairohan 13:b6e02d6261d7 2192
kishibekairohan 13:b6e02d6261d7 2193 #if USE_PROCESS_NUM>6
yabahiro 21:1f1e9c585da8 2194 static void Process6()
kishibekairohan 13:b6e02d6261d7 2195 {
yabahiro 21:1f1e9c585da8 2196
kishibekairohan 13:b6e02d6261d7 2197 }
kishibekairohan 13:b6e02d6261d7 2198 #endif
kishibekairohan 13:b6e02d6261d7 2199
kishibekairohan 13:b6e02d6261d7 2200 #if USE_PROCESS_NUM>7
kishibekairohan 13:b6e02d6261d7 2201 static void Process7()
kishibekairohan 13:b6e02d6261d7 2202 {
yabahiro 21:1f1e9c585da8 2203
kishibekairohan 12:c09b3e08a316 2204 }
kishibekairohan 12:c09b3e08a316 2205 #endif
kishibekairohan 12:c09b3e08a316 2206
yabahiro 21:1f1e9c585da8 2207 #if USE_PROCESS_NUM>8
kishibekairohan 13:b6e02d6261d7 2208 static void Process8()
kishibekairohan 12:c09b3e08a316 2209 {
yabahiro 21:1f1e9c585da8 2210
kishibekairohan 12:c09b3e08a316 2211 }
kishibekairohan 12:c09b3e08a316 2212 #endif
kishibekairohan 12:c09b3e08a316 2213
kishibekairohan 13:b6e02d6261d7 2214 #if USE_PROCESS_NUM>9
kishibekairohan 13:b6e02d6261d7 2215 static void Process9()
kishibekairohan 12:c09b3e08a316 2216 {
yabahiro 21:1f1e9c585da8 2217
t_yamamoto 0:669ef71cba68 2218 }
t_yamamoto 0:669ef71cba68 2219 #endif
t_yamamoto 0:669ef71cba68 2220 #endif
t_yamamoto 0:669ef71cba68 2221 #pragma endregion PROCESS
t_yamamoto 0:669ef71cba68 2222
t_yamamoto 0:669ef71cba68 2223 static void AllActuatorReset()
t_yamamoto 0:669ef71cba68 2224 {
t_yamamoto 0:669ef71cba68 2225
yabahiro 21:1f1e9c585da8 2226 #ifdef USE_SOLENOID
yabahiro 21:1f1e9c585da8 2227 solenoid.all = ALL_SOLENOID_OFF;
yabahiro 21:1f1e9c585da8 2228 #endif
t_yamamoto 0:669ef71cba68 2229
yabahiro 21:1f1e9c585da8 2230 #ifdef USE_MOTOR
yabahiro 21:1f1e9c585da8 2231 for (uint8_t i = 0; i < MOUNTING_MOTOR_NUM; i++) {
yabahiro 21:1f1e9c585da8 2232 motor[i].dir = FREE;
yabahiro 21:1f1e9c585da8 2233 motor[i].pwm = 0;
yabahiro 21:1f1e9c585da8 2234 }
yabahiro 21:1f1e9c585da8 2235 #endif
t_yamamoto 0:669ef71cba68 2236 }
t_yamamoto 0:669ef71cba68 2237
yabahiro 21:1f1e9c585da8 2238 /*
yabahiro 21:1f1e9c585da8 2239 void BuzzerTimer_func()
yabahiro 21:1f1e9c585da8 2240 {
kishibekairohan 16:3f2c2d89372b 2241 buzzer = !buzzer;
kishibekairohan 17:50dc4b449e69 2242 //LED_DEBUG0 = !LED_DEBUG0;
kishibekairohan 11:028a150943b5 2243 }
yabahiro 21:1f1e9c585da8 2244 */
yabahiro 21:1f1e9c585da8 2245 void TapeLedEms_func()
yabahiro 21:1f1e9c585da8 2246 {
kishibekairohan 16:3f2c2d89372b 2247 sendLedData.code = sendLedData.code == (uint32_t)Red ? (uint32_t)Black : (uint32_t)Red;
kishibekairohan 9:f93fc79a49ea 2248 }
kishibekairohan 16:3f2c2d89372b 2249
kishibekairohan 16:3f2c2d89372b 2250 #pragma region USER-DEFINED-FUNCTIONS
kishibekairohan 16:3f2c2d89372b 2251
kishibekairohan 16:3f2c2d89372b 2252
t_yamamoto 0:669ef71cba68 2253 #pragma endregion