大季 矢花 / Mbed 2 deprecated MainBoard2019_Master_9_18_last

Dependencies:   mbed TrapezoidControl QEI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Process.cpp Source File

Process.cpp

00001 
00002 #include "mbed.h"
00003 #include "Process.h"
00004 #include "QEI.h"
00005 
00006 #include "../../CommonLibraries/PID/PID.h"
00007 #include "../../Communication/RS485/ActuatorHub/ActuatorHub.h"
00008 #include "../../Communication/RS485/LineHub/LineHub.h"
00009 #include "../../Communication/Controller/Controller.h"
00010 #include "../../Input/ExternalInt/ExternalInt.h"
00011 #include "../../Input/Switch/Switch.h"
00012 #include "../../Input/Potentiometer/Potentiometer.h"
00013 #include "../../Input/Encoder/Encoder.h"
00014 #include "../../LED/LED.h"
00015 #include "../../Safty/Safty.h"
00016 #include "../Using.h"
00017 
00018 using namespace SWITCH;
00019 using namespace PID_SPACE;
00020 using namespace ENCODER;
00021 using namespace LINEHUB;
00022 
00023 static CONTROLLER::ControllerData *controller;
00024 ACTUATORHUB::MOTOR::MotorStatus motor[MOUNTING_MOTOR_NUM];
00025 ACTUATORHUB::SOLENOID::SolenoidStatus solenoid;
00026 
00027 static bool lock;
00028 static bool processChangeComp;
00029 static int current;
00030 
00031 static void AllActuatorReset();
00032 
00033 #ifdef USE_SUBPROCESS
00034 static void (*Process[USE_PROCESS_NUM])(void);
00035 #endif
00036 
00037 #pragma region USER-DEFINED_VARIABLES_AND_PROTOTYPE
00038 
00039 /*Replace here with the definition code of your variables.*/
00040 
00041 Serial pc(USBTX, USBRX);
00042 
00043 //**************Encoder***************
00044 const int PerRev = 256;
00045 QEI ECD_0(ECD_A_0,ECD_B_0,NC,PerRev,QEI::X4_ENCODING);
00046 QEI ECD_1(ECD_A_1,ECD_B_1,NC,PerRev,QEI::X4_ENCODING);
00047 QEI ECD_2(ECD_A_2,ECD_B_2,NC,PerRev,QEI::X4_ENCODING);
00048 QEI ECD_3(ECD_A_3,ECD_B_3,NC,PerRev,QEI::X4_ENCODING);
00049 //**************Encoder***************
00050 
00051 //**************Buzzer****************
00052 //DigitalOut buzzer(BUZZER_PIN);
00053 void BuzzerTimer_func();
00054 Ticker BuzzerTimer;
00055 bool EMGflag = false;
00056 //PWMOut buzzer(BUZZER_PIN);
00057 //**************Buzzer****************
00058 
00059 //************TapeLed*****************
00060 void TapeLedEms_func();
00061 TapeLedData tapeLED;
00062 TapeLedData sendLedData;
00063 TapeLED_Mode ledMode = Normal;
00064 Ticker tapeLedTimer;
00065 //************TapaLed*****************
00066 
00067 float tireProRPM[4];
00068 float tireTarRPM[4];
00069 float tirepwm[4];
00070 
00071 const int omni[15][15] = {
00072     {    0,     5,    21,     47,     83,    130,    187,    255,    255,    255,    255,    255,    255,    255,    255 },
00073     {   -5,     0,     5,     21,     47,     83,    130,    187,    193,    208,    234,    255,    255,    255,    255 },
00074     {  -21,    -5,     0,      5,     21,     47,     83,    130,    135,    151,    177,    213,    255,    255,    255 },
00075     {  -47,   -21,     5,      0,      5,     21,     47,     83,     88,    104,    130,    167,    213,    255,    255 },
00076     {  -83,   -47,    -21,     5,      0,      5,     21,     47,     52,     68,     94,    130,    177,    234,    255 },
00077     { -130,   -83,    -47,    -21,     5,      0,      5,     21,     26,     42,     68,    104,    151,    208,    255 },
00078     { -187,  -130,    -83,    -47,    -21,    -5,      0,      5,     10,     26,     52,     88,    135,    193,    255 },
00079     { -255,  -187,   -130,    -83,    -47,    -21,    -5,      0,      5,     21,     47,     83,    130,    187,    255 },
00080     { -255,  -193,   -135,    -88,    -52,    -26,    -10,    -5,      0,      5,     21,     47,     83,    130,    187 },
00081     { -255,  -208,   -151,   -104,    -68,    -42,    -26,    -21,    -5,      0,      5,     21,     47,     83,    130 },
00082     { -255,  -234,   -177,   -130,    -94,    -68,    -52,    -47,    -21,    -7,      0,      7,     21,     47,     83 },
00083     { -255,  -255,   -213,   -167,   -130,   -104,    -88,    -83,    -47,    -21,    -5,      0,      5,     21,     47 },
00084     { -255,  -255,   -255,   -213,   -177,   -151,   -135,   -130,    -83,    -47,    -21,    -5,      0,      5,     21 },
00085     { -255,  -255,   -255,   -255,   -234,   -208,   -193,   -187,   -130,    -83,    -47,    -21,    -5,      0,      5 },
00086     { -255,  -255,   -255,   -255,   -255,   -255,   -255,   -255,   -187,   -130,    -83,    -47,   -21,     -5,      0 }
00087 };
00088 
00089 const int curve[15] = { -152, -98, -54, -18, 0, 0, 0, 0, 0, 0, 0, 18, 54, 98, 152 };
00090 //{-200,-146,-102,-66,-36,-16,0,0,0,16,36,66,102,146,200}
00091 
00092 uint8_t SetStatus(int);
00093 uint8_t SetStatus(int pwmVal)
00094 {
00095     if (pwmVal < 0) return BACK;
00096     else if (pwmVal > 0) return FOR;
00097     else if (pwmVal == 0) return BRAKE;
00098     else return BRAKE;
00099 }
00100 uint8_t Setpwm(int);
00101 uint8_t Setpwm(int pwmVal)
00102 {
00103     if (pwmVal == 0 || pwmVal >  255 || pwmVal < -255) return 255;
00104     else return abs(pwmVal);
00105 }
00106 
00107 #pragma endregion USER-DEFINED_VARIABLES_AND_PROTOTYPE
00108 
00109 #ifdef USE_SUBPROCESS
00110 #if USE_PROCESS_NUM>0
00111 static void Process0(void);
00112 #endif
00113 #if USE_PROCESS_NUM>1
00114 static void Process1(void);
00115 #endif
00116 #if USE_PROCESS_NUM>2
00117 static void Process2(void);
00118 #endif
00119 #if USE_PROCESS_NUM>3
00120 static void Process3(void);
00121 #endif
00122 #if USE_PROCESS_NUM>4
00123 static void Process4(void);
00124 #endif
00125 #if USE_PROCESS_NUM>5
00126 static void Process5(void);
00127 #endif
00128 #if USE_PROCESS_NUM>6
00129 static void Process6(void);
00130 #endif
00131 #if USE_PROCESS_NUM>7
00132 static void Process7(void);
00133 #endif
00134 #if USE_PROCESS_NUM>8
00135 static void Process8(void);
00136 #endif
00137 #if USE_PROCESS_NUM>9
00138 static void Process9(void);
00139 #endif
00140 #endif
00141 
00142 void SystemProcessInitialize()
00143 {
00144     #pragma region USER-DEFINED_VARIABLE_INIT
00145     /*Replace here with the initialization code of your variables.*/
00146     #pragma endregion USER-DEFINED_VARIABLE_INIT
00147 
00148     lock = true;
00149     processChangeComp = true;
00150     current = DEFAULT_PROCESS;
00151 
00152 #ifdef USE_SUBPROCESS
00153 #if USE_PROCESS_NUM>0
00154     Process[0] = Process0;
00155 #endif
00156 #if USE_PROCESS_NUM>1
00157     Process[1] = Process1;
00158 #endif
00159 #if USE_PROCESS_NUM>2
00160     Process[2] = Process2;
00161 #endif
00162 #if USE_PROCESS_NUM>3
00163     Process[3] = Process3;
00164 #endif
00165 #if USE_PROCESS_NUM>4
00166     Process[4] = Process4;
00167 #endif
00168 #if USE_PROCESS_NUM>5
00169     Process[5] = Process5;
00170 #endif
00171 #if USE_PROCESS_NUM>6
00172     Process[6] = Process6;
00173 #endif
00174 #if USE_PROCESS_NUM>7
00175     Process[7] = Process7;
00176 #endif
00177 #if USE_PROCESS_NUM>8
00178     Process[8] = Process8;
00179 #endif
00180 #if USE_PROCESS_NUM>9
00181     Process[9] = Process9;
00182 #endif
00183 #endif
00184 }
00185 
00186 static void SystemProcessUpdate()
00187 {
00188 #ifdef USE_SUBPROCESS
00189     if(controller->Button.HOME) lock = false;
00190 
00191     if(controller->Button.START && processChangeComp) {
00192         current++;
00193         if (USE_PROCESS_NUM < current) current = USE_PROCESS_NUM;
00194         processChangeComp = false;
00195     } else if(controller->Button.SELECT && processChangeComp) {
00196         current--;
00197         if (current < 0) current = 0;
00198         processChangeComp = false;
00199     } else if(!controller->Button.SELECT && !controller->Button.START) processChangeComp = true;
00200 #endif
00201 
00202 #ifdef USE_MOTOR
00203     ACTUATORHUB::MOTOR::Motor::Update(motor);
00204 #endif
00205 
00206 #ifdef USE_SOLENOID
00207     ACTUATORHUB::SOLENOID::Solenoid::Update(solenoid);
00208 #endif
00209 
00210 #ifdef USE_RS485
00211     ACTUATORHUB::ActuatorHub::Update();
00212 #endif
00213 
00214 }
00215 
00216 int g[8];
00217 
00218 void SystemProcess()
00219 {
00220     SystemProcessInitialize();
00221 
00222     while(1) {
00223         for(int i = 0; i < 8; i++) {
00224             g[i] = LineHub::GetPara(i);
00225         }
00226 
00227 #ifdef USE_MU
00228         controller = CONTROLLER::Controller::GetData();
00229 #endif
00230 
00231 #ifdef USE_ERRORCHECK
00232         if(SAFTY::ErrorCheck::Check() & SAFTY::Error::ControllerLost) {
00233             CONTROLLER::Controller::DataReset();
00234             AllActuatorReset();
00235             lock = true;
00236         } else
00237 #endif
00238         {
00239 
00240 #ifdef USE_SUBPROCESS
00241             if(!lock) {
00242                 Process[current]();
00243             } else
00244 #endif
00245             {
00246                 //ロック時の処理
00247             }
00248         }
00249         /*
00250         //Emergency!
00251         if(!EMG_0 && !EMG_1 && !EMGflag) {
00252             buzzer = 0;
00253             BuzzerTimer.attach(BuzzerTimer_func, 1);
00254             EMGflag = true;
00255             LED_DEBUG0 = 1;
00256         }
00257         if(EMG_0 && EMG_1 && EMGflag) {
00258             buzzer = 1;
00259             BuzzerTimer.detach();
00260             EMGflag = false;
00261         }
00262         */
00263         SystemProcessUpdate();
00264     }
00265 }
00266 
00267 
00268 int Twsh;
00269 
00270 #pragma region PROCESS
00271 #ifdef USE_SUBPROCESS
00272 #if USE_PROCESS_NUM>0
00273 
00274 static void Process0()
00275 {
00276     if(StertSW) {
00277         current = 2;
00278         Twsh=3;
00279     }
00280 }
00281 #endif
00282 
00283 #if USE_PROCESS_NUM>1
00284 
00285 bool dz1=true;
00286 bool dz1i=false;
00287 bool dz2=true;
00288 bool dz2i=false;
00289 bool dz3=true;
00290 bool dz3i=false;
00291 bool dz4=true;
00292 bool dz4i=false;
00293 
00294 int mode =1;
00295 int cross=0;//十字数える用
00296 int count=100000;//wait代替え
00297 
00298 
00299 static void Process1()
00300 {
00301     count=100000;
00302     mode=0;
00303     cross=0;
00304     motor[TIRE_FR].dir = SetStatus(-omni[controller->AnalogL.Y][14-controller->AnalogL.X]     + curve[controller->AnalogR.X]);
00305     motor[TIRE_FL].dir = SetStatus(omni[controller->AnalogL.Y][controller->AnalogL.X]         + curve[controller->AnalogR.X]);
00306     motor[TIRE_BR].dir = SetStatus(-omni[14-controller->AnalogL.X][14-controller->AnalogL.Y]  + curve[controller->AnalogR.X]);
00307     motor[TIRE_BL].dir = SetStatus(omni[controller->AnalogL.X][14-controller->AnalogL.Y]      + curve[controller->AnalogR.X]);
00308 
00309     motor[TIRE_FR].pwm = Setpwm(omni[controller->AnalogL.Y][14-controller->AnalogL.X]+ curve[controller->AnalogR.X])*0.2;
00310     motor[TIRE_FL].pwm = Setpwm(omni[controller->AnalogL.Y][controller->AnalogL.X]+ curve[controller->AnalogR.X])*0.2;
00311     motor[TIRE_BR].pwm = Setpwm(omni[14-controller->AnalogL.X][14-controller->AnalogL.Y]+ curve[controller->AnalogR.X])*0.2;
00312     motor[TIRE_BL].pwm = Setpwm(omni[controller->AnalogL.X][14-controller->AnalogL.Y]+ curve[controller->AnalogR.X])*0.2;
00313 
00314     if(controller->Button.UP||controller->Button.DOWN) {
00315 
00316         if(controller->Button.UP) {
00317             motor[MOTOR_0].pwm = 110;
00318             motor[MOTOR_0].dir = FOR;
00319         }
00320         if(controller->Button.DOWN) {
00321             motor[MOTOR_0].pwm = 50;
00322             motor[MOTOR_0].dir = BACK;
00323         }
00324     } else {
00325         motor[MOTOR_0].pwm = 0;
00326         motor[MOTOR_0].dir = BRAKE;
00327     }
00328     if(controller->Button.X) {
00329         if(dz1==true) {
00330             if(dz1i==false) {
00331                 solenoid.solenoid1 = SOLENOID_ON;
00332                 dz1i=true;
00333             } else {
00334                 solenoid.solenoid1 = SOLENOID_OFF;
00335                 dz1i=false;
00336             }
00337             dz1=false;
00338         }
00339     } else {
00340         dz1=true;
00341     }
00342 
00343     if(controller->Button.Y) {
00344         if(dz2==true) {
00345             if(dz2i==false) {
00346                 solenoid.solenoid2 = SOLENOID_ON;
00347                 dz2i=true;
00348             } else {
00349                 solenoid.solenoid2 = SOLENOID_OFF;
00350                 dz2i=false;
00351             }
00352             dz2=false;
00353         }
00354     } else {
00355         dz2=true;
00356     }
00357 
00358     if(controller->Button.A) {
00359         if(dz3==true) {
00360             if(dz3i==false) {
00361                 solenoid.solenoid3 = SOLENOID_ON;
00362                 dz3i=true;
00363             } else {
00364                 solenoid.solenoid3 = SOLENOID_OFF;
00365                 dz3i=false;
00366             }
00367             dz3=false;
00368         }
00369     } else {
00370         dz3=true;
00371     }
00372 
00373     if(controller->Button.B) {
00374         if(dz4==true) {
00375             if(dz4i==false) {
00376                 solenoid.solenoid4 = SOLENOID_ON;
00377                 dz4i=true;
00378             } else {
00379                 solenoid.solenoid4 = SOLENOID_OFF;
00380                 dz4i=false;
00381             }
00382             dz4=false;
00383         }
00384     } else {
00385         dz4=true;
00386     }
00387     /*
00388     if(controller->Button.RIGHT){
00389      motor[MOTOR_1].dir = FOR;
00390      motor[MOTOR_1].pwm = 60;
00391      if (ARM_1){
00392       motor[MOTOR_1].dir = BRAKE;
00393      }
00394     }
00395     else if(controller->Button.LEFT){
00396      motor[MOTOR_1].dir = BACK;
00397      motor[MOTOR_1].pwm = 60;
00398      if (ARM_0){
00399       motor[MOTOR_1].dir = BRAKE;
00400      }
00401     }
00402     */
00403 }
00404 #endif
00405 
00406 #if USE_PROCESS_NUM>2
00407 bool mtc=false;
00408 //追加
00409 bool mtc2 = false;
00410 
00411 static void Process2()
00412 {
00413 //    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]);
00414     count++;
00415     if(mode==0&&StertSW) {
00416         if(ThSW) {
00417             Twsh=1;
00418             mode=1;
00419         } else {
00420             Twsh=2;
00421             mode=1;
00422         }
00423     }
00424     if(mode==1) {//スタートゾーンから白線検知
00425         motor[TIRE_FR].pwm = 30;
00426         motor[TIRE_FR].dir = BACK;
00427         motor[TIRE_FL].pwm = 30;
00428         motor[TIRE_FL].dir = FOR;
00429         motor[TIRE_BR].pwm = 30;
00430         motor[TIRE_BR].dir = BACK;
00431         motor[TIRE_BL].pwm = 30;
00432         motor[TIRE_BL].dir = FOR;
00433         if(g[2]==0) {
00434             count=100000;
00435             cross=0;
00436             mode=2;
00437         }
00438     } else if(mode==2) {//横移動
00439         if(g[2]==0) {
00440             count=100000;
00441             cross=0;
00442             mode=3;
00443             mtc2=true;
00444         } else {
00445             motor[TIRE_FR].pwm = 30;
00446             motor[TIRE_FR].dir = FOR;
00447             motor[TIRE_FL].pwm = 30;
00448             motor[TIRE_FL].dir = FOR;
00449             motor[TIRE_BR].pwm = 30;
00450             motor[TIRE_BR].dir = BACK;
00451             motor[TIRE_BL].pwm = 30;
00452             motor[TIRE_BL].dir = BACK;
00453         }
00454     } else if(mode==3) { //横ライントレースから縦ライントレースへ
00455         motor[TIRE_FR].pwm = 0;
00456         motor[TIRE_FR].dir = FREE;
00457         motor[TIRE_FL].pwm = 20;
00458         motor[TIRE_FL].dir = FOR;
00459         motor[TIRE_BR].pwm = 20;
00460         motor[TIRE_BR].dir = BACK;
00461         motor[TIRE_BL].pwm = 0;
00462         motor[TIRE_BL].dir = FREE;
00463         if(count>100000&&g[0]==0) {
00464             count=0;
00465             mode=10;
00466         }
00467     } else if(mode==4) { //横ライントレースから縦ライントレースへ
00468         motor[TIRE_FR].pwm = 15;
00469         motor[TIRE_FR].dir = BACK;
00470         motor[TIRE_FL].pwm = 15;
00471         motor[TIRE_FL].dir = BACK;
00472         motor[TIRE_BR].pwm = 15;
00473         motor[TIRE_BR].dir = FOR;
00474         motor[TIRE_BL].pwm = 15;
00475         motor[TIRE_BL].dir = FOR;
00476         if(count>30000&&g[0]==0) {
00477             count=0;
00478             cross=0;
00479             mode=10;
00480         }
00481     } else if(g[0]!=99&&mode==10) { //縦ライントレース
00482         switch(g[0]) {
00483             case 98:
00484                 motor[TIRE_FR].pwm = 30;
00485                 motor[TIRE_FR].dir = BACK;
00486                 motor[TIRE_FL].pwm = 30;
00487                 motor[TIRE_FL].dir = FOR;
00488                 motor[TIRE_BR].pwm = 30;
00489                 motor[TIRE_BR].dir = BACK;
00490                 motor[TIRE_BL].pwm = 30;
00491                 motor[TIRE_BL].dir = FOR;
00492                 if(count>100000) {
00493                     cross++;
00494                     count=0;
00495                 }
00496                 mtc=true;
00497                 if(cross==Twsh) {
00498                     mode=11;
00499                     count=0;
00500                 }
00501                 break;
00502             case 0:
00503                 motor[TIRE_FR].pwm = 60;
00504                 motor[TIRE_FR].dir = BACK;
00505                 motor[TIRE_FL].pwm = 60;
00506                 motor[TIRE_FL].dir = FOR;
00507                 motor[TIRE_BR].pwm = 60;
00508                 motor[TIRE_BR].dir = BACK;
00509                 motor[TIRE_BL].pwm = 60;
00510                 motor[TIRE_BL].dir = FOR;
00511                 mtc=true;
00512                 break;
00513             case 255:
00514                 motor[TIRE_FR].pwm = 60;
00515                 motor[TIRE_FR].dir = BACK;
00516                 motor[TIRE_FL].pwm = 40;
00517                 motor[TIRE_FL].dir = FOR;
00518                 motor[TIRE_BR].pwm = 40;
00519                 motor[TIRE_BR].dir = BACK;
00520                 motor[TIRE_BL].pwm = 60;
00521                 motor[TIRE_BL].dir = FOR;
00522                 mtc=true;
00523                 break;
00524             case 253:
00525                 motor[TIRE_FR].pwm = 20;
00526                 motor[TIRE_FR].dir = BACK;
00527                 motor[TIRE_FL].pwm = 0;
00528                 motor[TIRE_FL].dir = FREE;
00529                 motor[TIRE_BR].pwm = 0;
00530                 motor[TIRE_BR].dir = FREE;
00531                 motor[TIRE_BL].pwm = 20;
00532                 motor[TIRE_BL].dir = FOR;
00533                 mtc=true;
00534                 break;
00535             case 254:
00536                 motor[TIRE_FR].pwm = 30;
00537                 motor[TIRE_FR].dir = BACK;
00538                 motor[TIRE_FL].pwm = 0;
00539                 motor[TIRE_FL].dir = FREE;
00540                 motor[TIRE_BR].pwm = 0;
00541                 motor[TIRE_BR].dir = FREE;
00542                 motor[TIRE_BL].pwm = 30;
00543                 motor[TIRE_BL].dir = FOR;
00544                 mtc=true;
00545                 break;
00546             case 1:
00547                 motor[TIRE_FR].pwm = 40;
00548                 motor[TIRE_FR].dir = BACK;
00549                 motor[TIRE_FL].pwm = 60;
00550                 motor[TIRE_FL].dir = FOR;
00551                 motor[TIRE_BR].pwm = 60;
00552                 motor[TIRE_BR].dir = BACK;
00553                 motor[TIRE_BL].pwm = 40;
00554                 motor[TIRE_BL].dir = FOR;
00555                 mtc=true;
00556                 break;
00557             case 3:
00558                 motor[TIRE_FR].pwm = 0;
00559                 motor[TIRE_FR].dir = FREE;
00560                 motor[TIRE_FL].pwm = 20;
00561                 motor[TIRE_FL].dir = FOR;
00562                 motor[TIRE_BR].pwm = 20;
00563                 motor[TIRE_BR].dir = BACK;
00564                 motor[TIRE_BL].pwm = 0;
00565                 motor[TIRE_BL].dir = FREE;
00566                 mtc=true;
00567                 break;
00568             case 2:
00569                 motor[TIRE_FR].pwm = 0;
00570                 motor[TIRE_FR].dir = FREE;
00571                 motor[TIRE_FL].pwm = 30;
00572                 motor[TIRE_FL].dir = FOR;
00573                 motor[TIRE_BR].pwm = 30;
00574                 motor[TIRE_BR].dir = BACK;
00575                 motor[TIRE_BL].pwm = 0;
00576                 motor[TIRE_BL].dir = FREE;
00577                 mtc=true;
00578                 break;
00579         }
00580         if(g[0]!=98&&mtc==true) {
00581             switch(g[1]) {
00582                 case 0:
00583                     mtc=false;
00584                     break;
00585                 case 255:
00586                     motor[TIRE_BR].pwm += 5;
00587                     mtc=false;
00588                     break;
00589                 case 253:
00590                     motor[TIRE_BR].pwm += 10;
00591                     mtc=false;
00592                     break;
00593                 case 254:
00594                     motor[TIRE_BR].pwm += 20;
00595                     motor[TIRE_BL].pwm = 0;
00596                     mtc=false;
00597                     break;
00598                 case 1:
00599                     motor[TIRE_BL].pwm += 5;
00600                     mtc=false;
00601                     break;
00602                 case 3:
00603                     motor[TIRE_BL].pwm += 10;
00604                     mtc=false;
00605                     break;
00606                 case 2:
00607                     motor[TIRE_BL].pwm += 20;
00608                     motor[TIRE_BR].pwm = 0;
00609                     mtc=false;
00610                     break;
00611             }
00612         }
00613     } else if(mode==11) {
00614         motor[TIRE_FR].pwm = 0;
00615         motor[TIRE_FR].dir = FREE;
00616         motor[TIRE_FL].pwm = 15;
00617         motor[TIRE_FL].dir = FOR;
00618         motor[TIRE_BR].pwm = 15;
00619         motor[TIRE_BR].dir = BACK;
00620         motor[TIRE_BL].pwm = 0;
00621         motor[TIRE_BL].dir = FREE;
00622         if(count>5000&&g[2]==0) {
00623             count=0;
00624             mode=12;
00625         }
00626     } else if(mode==12) {
00627         motor[TIRE_FR].pwm = 15;
00628         motor[TIRE_FR].dir = FOR;
00629         motor[TIRE_FL].pwm = 15;
00630         motor[TIRE_FL].dir = BACK;
00631         motor[TIRE_BR].pwm = 15;
00632         motor[TIRE_BR].dir = FOR;
00633         motor[TIRE_BL].pwm = 15;
00634         motor[TIRE_BL].dir = BACK;
00635         if(count>10000&&g[2]==0) {
00636             count=0;
00637             cross=0;
00638             mode=20;
00639         }
00640     } else if(mode==20) {
00641         switch(g[2]) {
00642             case 98:
00643                 motor[TIRE_FR].pwm = 30;
00644                 motor[TIRE_FR].dir = FOR;
00645                 motor[TIRE_FL].pwm = 30;
00646                 motor[TIRE_FL].dir = FOR;
00647                 motor[TIRE_BR].pwm = 30;
00648                 motor[TIRE_BR].dir = BACK;
00649                 motor[TIRE_BL].pwm = 30;
00650                 motor[TIRE_BL].dir = BACK;
00651                 if(count>70000) {
00652                     cross++;
00653                     count=0;
00654                 }
00655                 mtc2=true;
00656                 if(cross==3) {
00657                     mode=21;
00658                     count=0;
00659                     cross=0;
00660                 }
00661                 break;
00662             case 0:
00663                 motor[TIRE_FR].pwm = 60;
00664                 motor[TIRE_FR].dir = FOR;
00665                 motor[TIRE_FL].pwm = 60;
00666                 motor[TIRE_FL].dir = FOR;
00667                 motor[TIRE_BR].pwm = 60;
00668                 motor[TIRE_BR].dir = BACK;
00669                 motor[TIRE_BL].pwm = 60;
00670                 motor[TIRE_BL].dir = BACK;
00671                 mtc2=true;
00672                 break;
00673             case 255:
00674                 motor[TIRE_FR].pwm = 40;
00675                 motor[TIRE_FR].dir = FOR;
00676                 motor[TIRE_FL].pwm = 60;
00677                 motor[TIRE_FL].dir = FOR;
00678                 motor[TIRE_BR].pwm = 60;
00679                 motor[TIRE_BR].dir = BACK;
00680                 motor[TIRE_BL].pwm = 40;
00681                 motor[TIRE_BL].dir = BACK;
00682                 mtc2=true;
00683                 break;
00684             case 253:
00685                 motor[TIRE_FR].pwm = 0;
00686                 motor[TIRE_FR].dir = FREE;
00687                 motor[TIRE_FL].pwm = 20;
00688                 motor[TIRE_FL].dir = FOR;
00689                 motor[TIRE_BR].pwm = 20;
00690                 motor[TIRE_BR].dir = BACK;
00691                 motor[TIRE_BL].pwm = 0;
00692                 motor[TIRE_BL].dir = FREE;
00693                 mtc2=true;
00694                 break;
00695             case 254:
00696                 motor[TIRE_FR].pwm = 0;
00697                 motor[TIRE_FR].dir = FREE;
00698                 motor[TIRE_FL].pwm = 30;
00699                 motor[TIRE_FL].dir = FOR;
00700                 motor[TIRE_BR].pwm = 30;
00701                 motor[TIRE_BR].dir = BACK;
00702                 motor[TIRE_BL].pwm = 0;
00703                 motor[TIRE_BL].dir = FREE;
00704                 mtc2=true;
00705                 break;
00706             case 1:
00707                 motor[TIRE_FR].pwm = 60;
00708                 motor[TIRE_FR].dir = FOR;
00709                 motor[TIRE_FL].pwm = 40;
00710                 motor[TIRE_FL].dir = FOR;
00711                 motor[TIRE_BR].pwm = 40;
00712                 motor[TIRE_BR].dir = BACK;
00713                 motor[TIRE_BL].pwm = 60;
00714                 motor[TIRE_BL].dir = BACK;
00715                 mtc2=true;
00716                 break;
00717             case 3:
00718                 motor[TIRE_FR].pwm = 20;
00719                 motor[TIRE_FR].dir = FOR;
00720                 motor[TIRE_FL].pwm = 0;
00721                 motor[TIRE_FL].dir = FREE;
00722                 motor[TIRE_BR].pwm = 0;
00723                 motor[TIRE_BR].dir = FREE;
00724                 motor[TIRE_BL].pwm = 20;
00725                 motor[TIRE_BL].dir = BACK;
00726                 mtc2=true;
00727                 break;
00728             case 2:
00729                 motor[TIRE_FR].pwm = 30;
00730                 motor[TIRE_FR].dir = FOR;
00731                 motor[TIRE_FL].pwm = 0;
00732                 motor[TIRE_FL].dir = FREE;
00733                 motor[TIRE_BR].pwm = 0;
00734                 motor[TIRE_BR].dir = FREE;
00735                 motor[TIRE_BL].pwm = 30;
00736                 motor[TIRE_BL].dir = BACK;
00737                 mtc2=true;
00738                 break;
00739         }
00740         if(g[2]!=98&&mtc2==true) {
00741             switch(g[3]) {
00742                 case 0:
00743                     mtc2=false;
00744                     break;
00745                 case 255:
00746                     motor[TIRE_BL].pwm += 5;
00747                     mtc2=false;
00748                     break;
00749                 case 253:
00750                     motor[TIRE_BL].pwm += 10;
00751                     mtc2=false;
00752                     break;
00753                 case 254:
00754                     motor[TIRE_BL].pwm += 20;
00755                     motor[TIRE_FL].pwm = 0;
00756                     mtc2=false;
00757                     break;
00758                 case 1:
00759                     motor[TIRE_FL].pwm += 5;
00760                     mtc2=false;
00761                     break;
00762                 case 3:
00763                     motor[TIRE_FL].pwm += 10;
00764                     mtc2=false;
00765                     break;
00766                 case 2:
00767                     motor[TIRE_FL].pwm += 20;
00768                     motor[TIRE_BL].pwm = 0;
00769                     mtc2=false;
00770                     break;
00771             }
00772         }
00773     } else if(mode==21) {
00774         motor[TIRE_FR].pwm = 0;
00775         motor[TIRE_FR].dir = FREE;
00776         motor[TIRE_FL].pwm = 15;
00777         motor[TIRE_FL].dir = FOR;
00778         motor[TIRE_BR].pwm = 15;
00779         motor[TIRE_BR].dir = BACK;
00780         motor[TIRE_BL].pwm = 0;
00781         motor[TIRE_BL].dir = FREE;
00782         if(count>2000&&g[0]==0) {
00783             count=0;
00784             mode=22;
00785         }
00786     } else if(mode==22) {
00787         motor[TIRE_FR].pwm = 15;
00788         motor[TIRE_FR].dir = BACK;
00789         motor[TIRE_FL].pwm = 15;
00790         motor[TIRE_FL].dir = BACK;
00791         motor[TIRE_BR].pwm = 15;
00792         motor[TIRE_BR].dir = FOR;
00793         motor[TIRE_BL].pwm = 15;
00794         motor[TIRE_BL].dir = FOR;
00795         if(count>5000&&g[0]==0) {
00796             count=0;
00797             cross=0;
00798             mode=30;
00799         }
00800     } else if(mode==30) {
00801         switch(g[0]) {
00802             case 98:
00803                 motor[TIRE_FR].pwm = 30;
00804                 motor[TIRE_FR].dir = BACK;
00805                 motor[TIRE_FL].pwm = 30;
00806                 motor[TIRE_FL].dir = FOR;
00807                 motor[TIRE_BR].pwm = 30;
00808                 motor[TIRE_BR].dir = BACK;
00809                 motor[TIRE_BL].pwm = 30;
00810                 motor[TIRE_BL].dir = FOR;
00811                 if(count>100000) {
00812                     cross++;
00813                     count=0;
00814                 }
00815                 mtc=true;
00816                 if(cross==1) {
00817                     mode=31;
00818                     count=0;
00819                 }
00820                 break;
00821             case 0:
00822                 motor[TIRE_FR].pwm = 60;
00823                 motor[TIRE_FR].dir = BACK;
00824                 motor[TIRE_FL].pwm = 60;
00825                 motor[TIRE_FL].dir = FOR;
00826                 motor[TIRE_BR].pwm = 60;
00827                 motor[TIRE_BR].dir = BACK;
00828                 motor[TIRE_BL].pwm = 60;
00829                 motor[TIRE_BL].dir = FOR;
00830                 mtc=true;
00831                 break;
00832             case 255:
00833                 motor[TIRE_FR].pwm = 60;
00834                 motor[TIRE_FR].dir = BACK;
00835                 motor[TIRE_FL].pwm = 40;
00836                 motor[TIRE_FL].dir = FOR;
00837                 motor[TIRE_BR].pwm = 40;
00838                 motor[TIRE_BR].dir = BACK;
00839                 motor[TIRE_BL].pwm = 60;
00840                 motor[TIRE_BL].dir = FOR;
00841                 mtc=true;
00842                 break;
00843             case 253:
00844                 motor[TIRE_FR].pwm = 20;
00845                 motor[TIRE_FR].dir = BACK;
00846                 motor[TIRE_FL].pwm = 0;
00847                 motor[TIRE_FL].dir = FREE;
00848                 motor[TIRE_BR].pwm = 0;
00849                 motor[TIRE_BR].dir = FREE;
00850                 motor[TIRE_BL].pwm = 20;
00851                 motor[TIRE_BL].dir = FOR;
00852                 mtc=true;
00853                 break;
00854             case 254:
00855                 motor[TIRE_FR].pwm = 30;
00856                 motor[TIRE_FR].dir = BACK;
00857                 motor[TIRE_FL].pwm = 0;
00858                 motor[TIRE_FL].dir = FREE;
00859                 motor[TIRE_BR].pwm = 0;
00860                 motor[TIRE_BR].dir = FREE;
00861                 motor[TIRE_BL].pwm = 30;
00862                 motor[TIRE_BL].dir = FOR;
00863                 mtc=true;
00864                 break;
00865             case 1:
00866                 motor[TIRE_FR].pwm = 40;
00867                 motor[TIRE_FR].dir = BACK;
00868                 motor[TIRE_FL].pwm = 60;
00869                 motor[TIRE_FL].dir = FOR;
00870                 motor[TIRE_BR].pwm = 60;
00871                 motor[TIRE_BR].dir = BACK;
00872                 motor[TIRE_BL].pwm = 40;
00873                 motor[TIRE_BL].dir = FOR;
00874                 mtc=true;
00875                 break;
00876             case 3:
00877                 motor[TIRE_FR].pwm = 0;
00878                 motor[TIRE_FR].dir = FREE;
00879                 motor[TIRE_FL].pwm = 20;
00880                 motor[TIRE_FL].dir = FOR;
00881                 motor[TIRE_BR].pwm = 20;
00882                 motor[TIRE_BR].dir = BACK;
00883                 motor[TIRE_BL].pwm = 0;
00884                 motor[TIRE_BL].dir = FREE;
00885                 mtc=true;
00886                 break;
00887             case 2:
00888                 motor[TIRE_FR].pwm = 0;
00889                 motor[TIRE_FR].dir = FREE;
00890                 motor[TIRE_FL].pwm = 30;
00891                 motor[TIRE_FL].dir = FOR;
00892                 motor[TIRE_BR].pwm = 30;
00893                 motor[TIRE_BR].dir = BACK;
00894                 motor[TIRE_BL].pwm = 0;
00895                 motor[TIRE_BL].dir = FREE;
00896                 mtc=true;
00897                 break;
00898         }
00899         if(g[0]!=98&&mtc==true) {
00900             switch(g[1]) {
00901                 case 0:
00902                     mtc=false;
00903                     break;
00904                 case 255:
00905                     motor[TIRE_BR].pwm += 5;
00906                     mtc=false;
00907                     break;
00908                 case 253:
00909                     motor[TIRE_BR].pwm += 10;
00910                     mtc=false;
00911                     break;
00912                 case 254:
00913                     motor[TIRE_BR].pwm += 20;
00914                     motor[TIRE_BL].pwm = 0;
00915                     mtc=false;
00916                     break;
00917                 case 1:
00918                     motor[TIRE_BL].pwm += 5;
00919                     mtc=false;
00920                     break;
00921                 case 3:
00922                     motor[TIRE_BL].pwm += 10;
00923                     mtc=false;
00924                     break;
00925                 case 2:
00926                     motor[TIRE_BL].pwm += 20;
00927                     motor[TIRE_BR].pwm = 0;
00928                     mtc=false;
00929                     break;
00930             }
00931         }
00932     } else if(mode==31) {
00933         motor[TIRE_FR].pwm = 15;
00934         motor[TIRE_FR].dir = BACK;
00935         motor[TIRE_FL].pwm = 0;
00936         motor[TIRE_FL].dir = FREE;
00937         motor[TIRE_BR].pwm = 0;
00938         motor[TIRE_BR].dir = FREE;
00939         motor[TIRE_BL].pwm = 15;
00940         motor[TIRE_BL].dir = FOR;
00941         if(count>5000&&g[3]==0) {
00942             count=0;
00943             mode=32;
00944         }
00945     } else if(mode==32) {
00946         motor[TIRE_FR].pwm = 15;
00947         motor[TIRE_FR].dir = FOR;
00948         motor[TIRE_FL].pwm = 15;
00949         motor[TIRE_FL].dir = BACK;
00950         motor[TIRE_BR].pwm = 15;
00951         motor[TIRE_BR].dir = FOR;
00952         motor[TIRE_BL].pwm = 15;
00953         motor[TIRE_BL].dir = BACK;
00954         if(count>5000&&g[3]==0) {
00955             count=0;
00956             cross=0;
00957             mode=40;
00958         }
00959     } else if(mode==40) {
00960         switch(g[3]) {
00961             case 98:
00962                 motor[TIRE_FR].pwm = 30;
00963                 motor[TIRE_FR].dir = BACK;
00964                 motor[TIRE_FL].pwm = 30;
00965                 motor[TIRE_FL].dir = BACK;
00966                 motor[TIRE_BR].pwm = 30;
00967                 motor[TIRE_BR].dir = FOR;
00968                 motor[TIRE_BL].pwm = 30;
00969                 motor[TIRE_BL].dir = FOR;
00970                 if(count>30000) {
00971                     cross++;
00972                     count=0;
00973                 }
00974                 mtc2=true;
00975                 if(cross==1) {
00976                     mode=41;
00977                     count=0;
00978                     cross=0;
00979                 }
00980                 break;
00981             case 0:
00982                 motor[TIRE_FR].pwm = 60;
00983                 motor[TIRE_FR].dir = BACK;
00984                 motor[TIRE_FL].pwm = 60;
00985                 motor[TIRE_FL].dir = BACK;
00986                 motor[TIRE_BR].pwm = 60;
00987                 motor[TIRE_BR].dir = FOR;
00988                 motor[TIRE_BL].pwm = 60;
00989                 motor[TIRE_BL].dir = FOR;
00990                 mtc2=true;
00991                 break;
00992             case 255:
00993                 motor[TIRE_FR].pwm = 40;
00994                 motor[TIRE_FR].dir = BACK;
00995                 motor[TIRE_FL].pwm = 60;
00996                 motor[TIRE_FL].dir = BACK;
00997                 motor[TIRE_BR].pwm = 60;
00998                 motor[TIRE_BR].dir = FOR;
00999                 motor[TIRE_BL].pwm = 40;
01000                 motor[TIRE_BL].dir = FOR;
01001                 mtc2=true;
01002                 break;
01003             case 253:
01004                 motor[TIRE_FR].pwm = 0;
01005                 motor[TIRE_FR].dir = FREE;
01006                 motor[TIRE_FL].pwm = 20;
01007                 motor[TIRE_FL].dir = BACK;
01008                 motor[TIRE_BR].pwm = 20;
01009                 motor[TIRE_BR].dir = FOR;
01010                 motor[TIRE_BL].pwm = 0;
01011                 motor[TIRE_BL].dir = FREE;
01012                 mtc2=true;
01013                 break;
01014             case 254:
01015                 motor[TIRE_FR].pwm = 0;
01016                 motor[TIRE_FR].dir = FREE;
01017                 motor[TIRE_FL].pwm = 30;
01018                 motor[TIRE_FL].dir = BACK;
01019                 motor[TIRE_BR].pwm = 30;
01020                 motor[TIRE_BR].dir = FOR;
01021                 motor[TIRE_BL].pwm = 0;
01022                 motor[TIRE_BL].dir = FREE;
01023                 mtc2=true;
01024                 break;
01025             case 1:
01026                 motor[TIRE_FR].pwm = 60;
01027                 motor[TIRE_FR].dir = BACK;
01028                 motor[TIRE_FL].pwm = 40;
01029                 motor[TIRE_FL].dir = BACK;
01030                 motor[TIRE_BR].pwm = 40;
01031                 motor[TIRE_BR].dir = FOR;
01032                 motor[TIRE_BL].pwm = 60;
01033                 motor[TIRE_BL].dir = FOR;
01034                 mtc2=true;
01035                 break;
01036             case 3:
01037                 motor[TIRE_FR].pwm = 20;
01038                 motor[TIRE_FR].dir = BACK;
01039                 motor[TIRE_FL].pwm = 0;
01040                 motor[TIRE_FL].dir = FREE;
01041                 motor[TIRE_BR].pwm = 0;
01042                 motor[TIRE_BR].dir = FREE;
01043                 motor[TIRE_BL].pwm = 20;
01044                 motor[TIRE_BL].dir = FOR;
01045                 mtc2=true;
01046                 break;
01047             case 2:
01048                 motor[TIRE_FR].pwm = 30;
01049                 motor[TIRE_FR].dir = BACK;
01050                 motor[TIRE_FL].pwm = 0;
01051                 motor[TIRE_FL].dir = FREE;
01052                 motor[TIRE_BR].pwm = 0;
01053                 motor[TIRE_BR].dir = FREE;
01054                 motor[TIRE_BL].pwm = 30;
01055                 motor[TIRE_BL].dir = FOR;
01056                 mtc2=true;
01057                 break;
01058         }
01059         if(g[2]!=98&&mtc2==true) {
01060             switch(g[2]) {
01061                 case 0:
01062                     mtc2=false;
01063                     break;
01064                 case 255:
01065                     motor[TIRE_FL].pwm += 5;
01066                     mtc2=false;
01067                     break;
01068                 case 253:
01069                     motor[TIRE_FL].pwm += 10;
01070                     mtc2=false;
01071                     break;
01072                 case 254:
01073                     motor[TIRE_FL].pwm += 20;
01074                     motor[TIRE_BL].pwm = 0;
01075                     mtc2=false;
01076                     break;
01077                 case 1:
01078                     motor[TIRE_BL].pwm += 5;
01079                     mtc2=false;
01080                     break;
01081                 case 3:
01082                     motor[TIRE_BL].pwm += 10;
01083                     mtc2=false;
01084                     break;
01085                 case 2:
01086                     motor[TIRE_BL].pwm += 20;
01087                     motor[TIRE_FL].pwm = 0;
01088                     mtc2=false;
01089                     break;
01090             }
01091         }
01092     } else if(mode==41) {
01093         motor[TIRE_FR].pwm = 0;
01094         motor[TIRE_FR].dir = FREE;
01095         motor[TIRE_FL].pwm = 15;
01096         motor[TIRE_FL].dir = BACK;
01097         motor[TIRE_BR].pwm = 15;
01098         motor[TIRE_BR].dir = FOR;
01099         motor[TIRE_BL].pwm = 0;
01100         motor[TIRE_BL].dir = FREE;
01101         if(count>5000&&g[1]==0) {
01102             count=0;
01103             mode=42;
01104         }
01105     } else if(mode==42) {
01106         motor[TIRE_FR].pwm = 15;
01107         motor[TIRE_FR].dir = FOR;
01108         motor[TIRE_FL].pwm = 15;
01109         motor[TIRE_FL].dir = FOR;
01110         motor[TIRE_BR].pwm = 15;
01111         motor[TIRE_BR].dir = BACK;
01112         motor[TIRE_BL].pwm = 15;
01113         motor[TIRE_BL].dir = BACK;
01114         if(count>5000&&g[1]==0) {
01115             count=0;
01116             mode=50;
01117         }
01118     } else if(mode==50) {
01119         switch(g[1]) {
01120             case 98:
01121                 motor[TIRE_FR].pwm = 30;
01122                 motor[TIRE_FR].dir = FOR;
01123                 motor[TIRE_FL].pwm = 30;
01124                 motor[TIRE_FL].dir = BACK;
01125                 motor[TIRE_BR].pwm = 30;
01126                 motor[TIRE_BR].dir = FOR;
01127                 motor[TIRE_BL].pwm = 30;
01128                 motor[TIRE_BL].dir = BACK;
01129                 if(count>100000) {
01130                     cross++;
01131                     count=0;
01132                 }
01133                 mtc=true;
01134                 if(cross==1) {
01135                     mode=51;
01136                     count=0;
01137                 }
01138                 break;
01139             case 0:
01140                 motor[TIRE_FR].pwm = 60;
01141                 motor[TIRE_FR].dir = FOR;
01142                 motor[TIRE_FL].pwm = 60;
01143                 motor[TIRE_FL].dir = BACK;
01144                 motor[TIRE_BR].pwm = 60;
01145                 motor[TIRE_BR].dir = FOR;
01146                 motor[TIRE_BL].pwm = 60;
01147                 motor[TIRE_BL].dir = BACK;
01148                 mtc=true;
01149                 break;
01150             case 255:
01151                 motor[TIRE_FR].pwm = 60;
01152                 motor[TIRE_FR].dir = FOR;
01153                 motor[TIRE_FL].pwm = 40;
01154                 motor[TIRE_FL].dir = BACK;
01155                 motor[TIRE_BR].pwm = 40;
01156                 motor[TIRE_BR].dir = FOR;
01157                 motor[TIRE_BL].pwm = 60;
01158                 motor[TIRE_BL].dir = BACK;
01159                 mtc=true;
01160                 break;
01161             case 253:
01162                 motor[TIRE_FR].pwm = 20;
01163                 motor[TIRE_FR].dir = FOR;
01164                 motor[TIRE_FL].pwm = 0;
01165                 motor[TIRE_FL].dir = FREE;
01166                 motor[TIRE_BR].pwm = 0;
01167                 motor[TIRE_BR].dir = FREE;
01168                 motor[TIRE_BL].pwm = 20;
01169                 motor[TIRE_BL].dir = BACK;
01170                 mtc=true;
01171                 break;
01172             case 254:
01173                 motor[TIRE_FR].pwm = 30;
01174                 motor[TIRE_FR].dir = FOR;
01175                 motor[TIRE_FL].pwm = 0;
01176                 motor[TIRE_FL].dir = FREE;
01177                 motor[TIRE_BR].pwm = 0;
01178                 motor[TIRE_BR].dir = FREE;
01179                 motor[TIRE_BL].pwm = 30;
01180                 motor[TIRE_BL].dir = BACK;
01181                 mtc=true;
01182                 break;
01183             case 1:
01184                 motor[TIRE_FR].pwm = 40;
01185                 motor[TIRE_FR].dir = FOR;
01186                 motor[TIRE_FL].pwm = 60;
01187                 motor[TIRE_FL].dir = BACK;
01188                 motor[TIRE_BR].pwm = 60;
01189                 motor[TIRE_BR].dir = FOR;
01190                 motor[TIRE_BL].pwm = 40;
01191                 motor[TIRE_BL].dir = BACK;
01192                 mtc=true;
01193                 break;
01194             case 3:
01195                 motor[TIRE_FR].pwm = 0;
01196                 motor[TIRE_FR].dir = FREE;
01197                 motor[TIRE_FL].pwm = 20;
01198                 motor[TIRE_FL].dir = BACK;
01199                 motor[TIRE_BR].pwm = 20;
01200                 motor[TIRE_BR].dir = FOR;
01201                 motor[TIRE_BL].pwm = 0;
01202                 motor[TIRE_BL].dir = FREE;
01203                 mtc=true;
01204                 break;
01205             case 2:
01206                 motor[TIRE_FR].pwm = 0;
01207                 motor[TIRE_FR].dir = FREE;
01208                 motor[TIRE_FL].pwm = 30;
01209                 motor[TIRE_FL].dir = BACK;
01210                 motor[TIRE_BR].pwm = 30;
01211                 motor[TIRE_BR].dir = FOR;
01212                 motor[TIRE_BL].pwm = 0;
01213                 motor[TIRE_BL].dir = FREE;
01214                 mtc=true;
01215                 break;
01216         }
01217         if(g[1]!=98&&mtc==true) {
01218             switch(g[0]) {
01219                 case 0:
01220                     mtc=false;
01221                     break;
01222                 case 255:
01223                     motor[TIRE_FL].pwm += 5;
01224                     mtc=false;
01225                     break;
01226                 case 253:
01227                     motor[TIRE_FL].pwm += 10;
01228                     mtc=false;
01229                     break;
01230                 case 254:
01231                     motor[TIRE_FL].pwm += 20;
01232                     motor[TIRE_FR].pwm = 0;
01233                     mtc=false;
01234                     break;
01235                 case 1:
01236                     motor[TIRE_FR].pwm += 5;
01237                     mtc=false;
01238                     break;
01239                 case 3:
01240                     motor[TIRE_FR].pwm += 10;
01241                     mtc=false;
01242                     break;
01243                 case 2:
01244                     motor[TIRE_FR].pwm += 20;
01245                     motor[TIRE_FL].pwm = 0;
01246                     mtc=false;
01247                     break;
01248             }
01249         }
01250     } else if(mode==51) {
01251         motor[TIRE_FR].pwm = 0;
01252         motor[TIRE_FR].dir = FREE;
01253         motor[TIRE_FL].pwm = 15;
01254         motor[TIRE_FL].dir = BACK;
01255         motor[TIRE_BR].pwm = 15;
01256         motor[TIRE_BR].dir = FOR;
01257         motor[TIRE_BL].pwm = 0;
01258         motor[TIRE_BL].dir = FREE;
01259         if(count>5000&&g[3]==0) {
01260             count=0;
01261             mode=52;
01262         }
01263     } else if(mode==52) {
01264         motor[TIRE_FR].pwm = 15;
01265         motor[TIRE_FR].dir = BACK;
01266         motor[TIRE_FL].pwm = 15;
01267         motor[TIRE_FL].dir = FOR;
01268         motor[TIRE_BR].pwm = 15;
01269         motor[TIRE_BR].dir = BACK;
01270         motor[TIRE_BL].pwm = 15;
01271         motor[TIRE_BL].dir = FOR;
01272         if(count>5000&&g[3]==0) {
01273             count=0;
01274             cross=0;
01275             mode=60;
01276         }
01277     } else if(mode==60) {
01278         switch(g[3]) {
01279             case 98:
01280                 motor[TIRE_FR].pwm = 30;
01281                 motor[TIRE_FR].dir = BACK;
01282                 motor[TIRE_FL].pwm = 30;
01283                 motor[TIRE_FL].dir = BACK;
01284                 motor[TIRE_BR].pwm = 30;
01285                 motor[TIRE_BR].dir = FOR;
01286                 motor[TIRE_BL].pwm = 30;
01287                 motor[TIRE_BL].dir = FOR;
01288                 if(count>50000) {
01289                     cross++;
01290                     count=0;
01291                 }
01292                 mtc2=true;
01293                 if(cross==2) {
01294                     mode=61;
01295                     count=0;
01296                     cross=0;
01297                 }
01298                 break;
01299             case 0:
01300                 motor[TIRE_FR].pwm = 60;
01301                 motor[TIRE_FR].dir = BACK;
01302                 motor[TIRE_FL].pwm = 60;
01303                 motor[TIRE_FL].dir = BACK;
01304                 motor[TIRE_BR].pwm = 60;
01305                 motor[TIRE_BR].dir = FOR;
01306                 motor[TIRE_BL].pwm = 60;
01307                 motor[TIRE_BL].dir = FOR;
01308                 mtc2=true;
01309                 break;
01310             case 255:
01311                 motor[TIRE_FR].pwm = 40;
01312                 motor[TIRE_FR].dir = BACK;
01313                 motor[TIRE_FL].pwm = 60;
01314                 motor[TIRE_FL].dir = BACK;
01315                 motor[TIRE_BR].pwm = 60;
01316                 motor[TIRE_BR].dir = FOR;
01317                 motor[TIRE_BL].pwm = 40;
01318                 motor[TIRE_BL].dir = FOR;
01319                 mtc2=true;
01320                 break;
01321             case 253:
01322                 motor[TIRE_FR].pwm = 0;
01323                 motor[TIRE_FR].dir = FREE;
01324                 motor[TIRE_FL].pwm = 20;
01325                 motor[TIRE_FL].dir = BACK;
01326                 motor[TIRE_BR].pwm = 20;
01327                 motor[TIRE_BR].dir = FOR;
01328                 motor[TIRE_BL].pwm = 0;
01329                 motor[TIRE_BL].dir = FREE;
01330                 mtc2=true;
01331                 break;
01332             case 254:
01333                 motor[TIRE_FR].pwm = 0;
01334                 motor[TIRE_FR].dir = FREE;
01335                 motor[TIRE_FL].pwm = 30;
01336                 motor[TIRE_FL].dir = BACK;
01337                 motor[TIRE_BR].pwm = 30;
01338                 motor[TIRE_BR].dir = FOR;
01339                 motor[TIRE_BL].pwm = 0;
01340                 motor[TIRE_BL].dir = FREE;
01341                 mtc2=true;
01342                 break;
01343             case 1:
01344                 motor[TIRE_FR].pwm = 60;
01345                 motor[TIRE_FR].dir = BACK;
01346                 motor[TIRE_FL].pwm = 40;
01347                 motor[TIRE_FL].dir = BACK;
01348                 motor[TIRE_BR].pwm = 40;
01349                 motor[TIRE_BR].dir = FOR;
01350                 motor[TIRE_BL].pwm = 60;
01351                 motor[TIRE_BL].dir = FOR;
01352                 mtc2=true;
01353                 break;
01354             case 3:
01355                 motor[TIRE_FR].pwm = 20;
01356                 motor[TIRE_FR].dir = BACK;
01357                 motor[TIRE_FL].pwm = 0;
01358                 motor[TIRE_FL].dir = FREE;
01359                 motor[TIRE_BR].pwm = 0;
01360                 motor[TIRE_BR].dir = FREE;
01361                 motor[TIRE_BL].pwm = 20;
01362                 motor[TIRE_BL].dir = FOR;
01363                 mtc2=true;
01364                 break;
01365             case 2:
01366                 motor[TIRE_FR].pwm = 30;
01367                 motor[TIRE_FR].dir = BACK;
01368                 motor[TIRE_FL].pwm = 0;
01369                 motor[TIRE_FL].dir = FREE;
01370                 motor[TIRE_BR].pwm = 0;
01371                 motor[TIRE_BR].dir = FREE;
01372                 motor[TIRE_BL].pwm = 30;
01373                 motor[TIRE_BL].dir = FOR;
01374                 mtc2=true;
01375                 break;
01376         }
01377         if(g[2]!=98&&mtc2==true) {
01378             switch(g[2]) {
01379                 case 0:
01380                     mtc2=false;
01381                     break;
01382                 case 255:
01383                     motor[TIRE_FL].pwm += 5;
01384                     mtc2=false;
01385                     break;
01386                 case 253:
01387                     motor[TIRE_FL].pwm += 10;
01388                     mtc2=false;
01389                     break;
01390                 case 254:
01391                     motor[TIRE_FL].pwm += 20;
01392                     motor[TIRE_BL].pwm = 0;
01393                     mtc2=false;
01394                     break;
01395                 case 1:
01396                     motor[TIRE_BL].pwm += 5;
01397                     mtc2=false;
01398                     break;
01399                 case 3:
01400                     motor[TIRE_BL].pwm += 10;
01401                     mtc2=false;
01402                     break;
01403                 case 2:
01404                     motor[TIRE_BL].pwm += 20;
01405                     motor[TIRE_FL].pwm = 0;
01406                     mtc2=false;
01407                     break;
01408             }
01409         }
01410     } else if(mode==61) {
01411         motor[TIRE_FR].pwm = 0;
01412         motor[TIRE_FR].dir = FREE;
01413         motor[TIRE_FL].pwm = 15;
01414         motor[TIRE_FL].dir = BACK;
01415         motor[TIRE_BR].pwm = 15;
01416         motor[TIRE_BR].dir = FOR;
01417         motor[TIRE_BL].pwm = 0;
01418         motor[TIRE_BL].dir = FREE;
01419         if(count>5000&&g[1]==0) {
01420             count=0;
01421             mode=62;
01422         }
01423     } else if(mode==62) {
01424         motor[TIRE_FR].pwm = 15;
01425         motor[TIRE_FR].dir = FOR;
01426         motor[TIRE_FL].pwm = 15;
01427         motor[TIRE_FL].dir = FOR;
01428         motor[TIRE_BR].pwm = 15;
01429         motor[TIRE_BR].dir = BACK;
01430         motor[TIRE_BL].pwm = 15;
01431         motor[TIRE_BL].dir = BACK;
01432         if(count>5000&&g[1]==0) {
01433             count=0;
01434             mode=70;
01435         }
01436     } else if(mode==70) {
01437         switch(g[1]) {
01438             case 99:
01439                 if(count>=100000) {
01440                     mode=100;
01441                 }
01442                 break;
01443             case 98:
01444                 motor[TIRE_FR].pwm = 30;
01445                 motor[TIRE_FR].dir = FOR;
01446                 motor[TIRE_FL].pwm = 30;
01447                 motor[TIRE_FL].dir = BACK;
01448                 motor[TIRE_BR].pwm = 30;
01449                 motor[TIRE_BR].dir = FOR;
01450                 motor[TIRE_BL].pwm = 30;
01451                 motor[TIRE_BL].dir = BACK;
01452                 break;
01453             case 0:
01454                 motor[TIRE_FR].pwm = 60;
01455                 motor[TIRE_FR].dir = FOR;
01456                 motor[TIRE_FL].pwm = 60;
01457                 motor[TIRE_FL].dir = BACK;
01458                 motor[TIRE_BR].pwm = 60;
01459                 motor[TIRE_BR].dir = FOR;
01460                 motor[TIRE_BL].pwm = 60;
01461                 motor[TIRE_BL].dir = BACK;
01462                 mtc=true;
01463                 break;
01464             case 255:
01465                 motor[TIRE_FR].pwm = 60;
01466                 motor[TIRE_FR].dir = FOR;
01467                 motor[TIRE_FL].pwm = 40;
01468                 motor[TIRE_FL].dir = BACK;
01469                 motor[TIRE_BR].pwm = 40;
01470                 motor[TIRE_BR].dir = FOR;
01471                 motor[TIRE_BL].pwm = 60;
01472                 motor[TIRE_BL].dir = BACK;
01473                 mtc=true;
01474                 break;
01475             case 253:
01476                 motor[TIRE_FR].pwm = 20;
01477                 motor[TIRE_FR].dir = FOR;
01478                 motor[TIRE_FL].pwm = 0;
01479                 motor[TIRE_FL].dir = FREE;
01480                 motor[TIRE_BR].pwm = 0;
01481                 motor[TIRE_BR].dir = FREE;
01482                 motor[TIRE_BL].pwm = 20;
01483                 motor[TIRE_BL].dir = BACK;
01484                 mtc=true;
01485                 break;
01486             case 254:
01487                 motor[TIRE_FR].pwm = 30;
01488                 motor[TIRE_FR].dir = FOR;
01489                 motor[TIRE_FL].pwm = 0;
01490                 motor[TIRE_FL].dir = FREE;
01491                 motor[TIRE_BR].pwm = 0;
01492                 motor[TIRE_BR].dir = FREE;
01493                 motor[TIRE_BL].pwm = 30;
01494                 motor[TIRE_BL].dir = BACK;
01495                 mtc=true;
01496                 break;
01497             case 1:
01498                 motor[TIRE_FR].pwm = 40;
01499                 motor[TIRE_FR].dir = FOR;
01500                 motor[TIRE_FL].pwm = 60;
01501                 motor[TIRE_FL].dir = BACK;
01502                 motor[TIRE_BR].pwm = 60;
01503                 motor[TIRE_BR].dir = FOR;
01504                 motor[TIRE_BL].pwm = 40;
01505                 motor[TIRE_BL].dir = BACK;
01506                 mtc=true;
01507                 break;
01508             case 3:
01509                 motor[TIRE_FR].pwm = 0;
01510                 motor[TIRE_FR].dir = FREE;
01511                 motor[TIRE_FL].pwm = 20;
01512                 motor[TIRE_FL].dir = BACK;
01513                 motor[TIRE_BR].pwm = 20;
01514                 motor[TIRE_BR].dir = FOR;
01515                 motor[TIRE_BL].pwm = 0;
01516                 motor[TIRE_BL].dir = FREE;
01517                 mtc=true;
01518                 break;
01519             case 2:
01520                 motor[TIRE_FR].pwm = 0;
01521                 motor[TIRE_FR].dir = FREE;
01522                 motor[TIRE_FL].pwm = 30;
01523                 motor[TIRE_FL].dir = BACK;
01524                 motor[TIRE_BR].pwm = 30;
01525                 motor[TIRE_BR].dir = FOR;
01526                 motor[TIRE_BL].pwm = 0;
01527                 motor[TIRE_BL].dir = FREE;
01528                 mtc=true;
01529                 break;
01530         }
01531         if(g[1]!=98&&mtc==true) {
01532             switch(g[0]) {
01533                 case 0:
01534                     mtc=false;
01535                     break;
01536                 case 255:
01537                     motor[TIRE_FL].pwm += 5;
01538                     mtc=false;
01539                     break;
01540                 case 253:
01541                     motor[TIRE_FL].pwm += 10;
01542                     mtc=false;
01543                     break;
01544                 case 254:
01545                     motor[TIRE_FL].pwm += 20;
01546                     motor[TIRE_FR].pwm = 0;
01547                     mtc=false;
01548                     break;
01549                 case 1:
01550                     motor[TIRE_FR].pwm += 5;
01551                     mtc=false;
01552                     break;
01553                 case 3:
01554                     motor[TIRE_FR].pwm += 10;
01555                     mtc=false;
01556                     break;
01557                 case 2:
01558                     motor[TIRE_FR].pwm += 20;
01559                     motor[TIRE_FL].pwm = 0;
01560                     mtc=false;
01561                     break;
01562             }
01563         }
01564     } else if(mode==100) {
01565         motor[TIRE_FR].pwm = 20;
01566         motor[TIRE_FR].dir = FOR;
01567         motor[TIRE_FL].pwm = 20;
01568         motor[TIRE_FL].dir = BACK;
01569         motor[TIRE_BR].pwm = 23;
01570         motor[TIRE_BR].dir = FOR;
01571         motor[TIRE_BL].pwm = 20;
01572         motor[TIRE_BL].dir = BACK;
01573     } else {
01574         motor[TIRE_FR].pwm = 0;
01575         motor[TIRE_FR].dir = BRAKE;
01576         motor[TIRE_FL].pwm = 0;
01577         motor[TIRE_FL].dir = BRAKE;
01578         motor[TIRE_BR].pwm = 0;
01579         motor[TIRE_BR].dir = BRAKE;
01580         motor[TIRE_BL].pwm = 0;
01581         motor[TIRE_BL].dir = BRAKE;
01582     }
01583 
01584 }
01585 
01586 #endif
01587 
01588 #if USE_PROCESS_NUM>3
01589 static void Process3()
01590 {
01591 
01592 }
01593 #endif
01594 
01595 #if USE_PROCESS_NUM>4
01596 static void Process4()
01597 {
01598 
01599 }
01600 #endif
01601 
01602 #if USE_PROCESS_NUM>5
01603 static void Process5()
01604 {
01605 
01606 }
01607 #endif
01608 
01609 #if USE_PROCESS_NUM>6
01610 static void Process6()
01611 {
01612 
01613 }
01614 #endif
01615 
01616 #if USE_PROCESS_NUM>7
01617 static void Process7()
01618 {
01619 
01620 }
01621 #endif
01622 
01623 #if USE_PROCESS_NUM>8
01624 static void Process8()
01625 {
01626 
01627 }
01628 #endif
01629 
01630 #if USE_PROCESS_NUM>9
01631 static void Process9()
01632 {
01633 
01634 }
01635 #endif
01636 #endif
01637 #pragma endregion PROCESS
01638 
01639 static void AllActuatorReset()
01640 {
01641 
01642 #ifdef USE_SOLENOID
01643     solenoid.all = ALL_SOLENOID_OFF;
01644 #endif
01645 
01646 #ifdef USE_MOTOR
01647     for (uint8_t i = 0; i < MOUNTING_MOTOR_NUM; i++) {
01648         motor[i].dir = FREE;
01649         motor[i].pwm = 0;
01650     }
01651 #endif
01652 }
01653 
01654 /*
01655 void BuzzerTimer_func()
01656 {
01657     buzzer = !buzzer;
01658     //LED_DEBUG0 = !LED_DEBUG0;
01659 }
01660 */
01661 void TapeLedEms_func()
01662 {
01663     sendLedData.code = sendLedData.code == (uint32_t)Red ? (uint32_t)Black : (uint32_t)Red;
01664 }
01665 
01666 #pragma region USER-DEFINED-FUNCTIONS
01667 
01668 
01669 #pragma endregion