aa
Dependencies: mbed TrapezoidControl QEI
System/Process/Process.cpp@47:b6e5a6bfe7ab, 2019-10-05 (annotated)
- Committer:
- yabahiro
- Date:
- Sat Oct 05 21:53:35 2019 +0000
- Revision:
- 47:b6e5a6bfe7ab
- Parent:
- 46:4a8bca4cc1fd
- Child:
- 48:d24c325fc0b4
aa;
Who changed what in which revision?
User | Revision | Line number | New 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 | 42:4f9689c0a349 | 107 | int selectnum[16][4]= { |
yabahiro | 42:4f9689c0a349 | 108 | //1,2,4,8 |
yabahiro | 42:4f9689c0a349 | 109 | {0,0,0,0}, |
yabahiro | 42:4f9689c0a349 | 110 | {1,0,0,0}, |
yabahiro | 42:4f9689c0a349 | 111 | {0,1,0,0}, |
yabahiro | 42:4f9689c0a349 | 112 | {1,1,0,0}, |
yabahiro | 42:4f9689c0a349 | 113 | {0,0,1,0}, |
yabahiro | 42:4f9689c0a349 | 114 | {1,0,1,0}, |
yabahiro | 42:4f9689c0a349 | 115 | {0,1,1,0}, |
yabahiro | 42:4f9689c0a349 | 116 | {1,1,1,0}, |
yabahiro | 42:4f9689c0a349 | 117 | {0,0,0,1}, |
yabahiro | 42:4f9689c0a349 | 118 | {1,0,0,1}, |
yabahiro | 42:4f9689c0a349 | 119 | {0,1,0,1}, |
yabahiro | 42:4f9689c0a349 | 120 | {1,1,0,1}, |
yabahiro | 42:4f9689c0a349 | 121 | {0,0,1,1}, |
yabahiro | 42:4f9689c0a349 | 122 | {1,0,1,1}, |
yabahiro | 42:4f9689c0a349 | 123 | {0,1,1,1}, |
yabahiro | 42:4f9689c0a349 | 124 | {1,1,1,1} |
yabahiro | 42:4f9689c0a349 | 125 | }; |
yabahiro | 42:4f9689c0a349 | 126 | |
yabahiro | 43:677f7446612e | 127 | DigitalIn EMC(PB_0); |
yabahiro | 43:677f7446612e | 128 | |
yabahiro | 42:4f9689c0a349 | 129 | void LedMode(int num) |
yabahiro | 35:94f026ab4d30 | 130 | { |
yabahiro | 42:4f9689c0a349 | 131 | POTENTIOMETER::dio[0]= selectnum[num][0]; |
yabahiro | 42:4f9689c0a349 | 132 | POTENTIOMETER::dio[1]= selectnum[num][1];; |
yabahiro | 42:4f9689c0a349 | 133 | POTENTIOMETER::dio[2]= selectnum[num][2];; |
yabahiro | 42:4f9689c0a349 | 134 | POTENTIOMETER::dio[3]= selectnum[num][3];; |
yabahiro | 35:94f026ab4d30 | 135 | |
yabahiro | 35:94f026ab4d30 | 136 | } |
yabahiro | 31:45f97698857b | 137 | int Twsh; |
yabahiro | 31:45f97698857b | 138 | bool UP_flag = false; |
yabahiro | 35:94f026ab4d30 | 139 | bool SW_flag = false; |
yabahiro | 31:45f97698857b | 140 | bool Air_flag = false; |
yabahiro | 35:94f026ab4d30 | 141 | bool zyouge; |
yabahiro | 39:f89166d7411c | 142 | bool zyougedo; |
yabahiro | 31:45f97698857b | 143 | bool dz1=true; |
yabahiro | 31:45f97698857b | 144 | bool dz1i=false; |
yabahiro | 31:45f97698857b | 145 | bool dz2=true; |
yabahiro | 31:45f97698857b | 146 | bool dz2i=false; |
yabahiro | 31:45f97698857b | 147 | bool dz3=true; |
yabahiro | 31:45f97698857b | 148 | bool dz3i=false; |
yabahiro | 31:45f97698857b | 149 | bool dz4=true; |
yabahiro | 31:45f97698857b | 150 | bool dz4i=false; |
yabahiro | 31:45f97698857b | 151 | bool zone; |
yabahiro | 31:45f97698857b | 152 | bool through=false; |
yabahiro | 35:94f026ab4d30 | 153 | bool counts=false; |
yabahiro | 36:788274604650 | 154 | bool mtc=false; |
yabahiro | 36:788274604650 | 155 | bool mtc2 = false; |
yabahiro | 43:677f7446612e | 156 | bool emcs=false; |
yabahiro | 45:878f8f385635 | 157 | bool kiri; |
yabahiro | 31:45f97698857b | 158 | |
yabahiro | 41:e1dd6d97f17d | 159 | bool start_flag = true; |
yabahiro | 41:e1dd6d97f17d | 160 | |
yabahiro | 42:4f9689c0a349 | 161 | int mode =0; |
yabahiro | 31:45f97698857b | 162 | int cross=0;//十字数える用 |
yabahiro | 35:94f026ab4d30 | 163 | int cros=0; |
yabahiro | 31:45f97698857b | 164 | int count=100000;//wait代替え |
kishibekairohan | 33:656aa14904a5 | 165 | |
kishibekairohan | 33:656aa14904a5 | 166 | ///*********PWM調整用*********/// |
yabahiro | 40:7f93984e8ba1 | 167 | int fast =60; |
yabahiro | 40:7f93984e8ba1 | 168 | int normal = 40; |
yabahiro | 40:7f93984e8ba1 | 169 | int slow = 20; |
yabahiro | 31:45f97698857b | 170 | |
t_yamamoto | 0:669ef71cba68 | 171 | #pragma endregion USER-DEFINED_VARIABLES_AND_PROTOTYPE |
t_yamamoto | 0:669ef71cba68 | 172 | |
t_yamamoto | 0:669ef71cba68 | 173 | #ifdef USE_SUBPROCESS |
t_yamamoto | 0:669ef71cba68 | 174 | #if USE_PROCESS_NUM>0 |
t_yamamoto | 0:669ef71cba68 | 175 | static void Process0(void); |
t_yamamoto | 0:669ef71cba68 | 176 | #endif |
t_yamamoto | 0:669ef71cba68 | 177 | #if USE_PROCESS_NUM>1 |
t_yamamoto | 0:669ef71cba68 | 178 | static void Process1(void); |
t_yamamoto | 0:669ef71cba68 | 179 | #endif |
t_yamamoto | 0:669ef71cba68 | 180 | #if USE_PROCESS_NUM>2 |
t_yamamoto | 0:669ef71cba68 | 181 | static void Process2(void); |
t_yamamoto | 0:669ef71cba68 | 182 | #endif |
t_yamamoto | 0:669ef71cba68 | 183 | #if USE_PROCESS_NUM>3 |
t_yamamoto | 0:669ef71cba68 | 184 | static void Process3(void); |
t_yamamoto | 0:669ef71cba68 | 185 | #endif |
t_yamamoto | 0:669ef71cba68 | 186 | #if USE_PROCESS_NUM>4 |
t_yamamoto | 0:669ef71cba68 | 187 | static void Process4(void); |
t_yamamoto | 0:669ef71cba68 | 188 | #endif |
t_yamamoto | 0:669ef71cba68 | 189 | #if USE_PROCESS_NUM>5 |
t_yamamoto | 0:669ef71cba68 | 190 | static void Process5(void); |
t_yamamoto | 0:669ef71cba68 | 191 | #endif |
t_yamamoto | 0:669ef71cba68 | 192 | #if USE_PROCESS_NUM>6 |
t_yamamoto | 0:669ef71cba68 | 193 | static void Process6(void); |
t_yamamoto | 0:669ef71cba68 | 194 | #endif |
t_yamamoto | 0:669ef71cba68 | 195 | #if USE_PROCESS_NUM>7 |
t_yamamoto | 0:669ef71cba68 | 196 | static void Process7(void); |
t_yamamoto | 0:669ef71cba68 | 197 | #endif |
t_yamamoto | 0:669ef71cba68 | 198 | #if USE_PROCESS_NUM>8 |
t_yamamoto | 0:669ef71cba68 | 199 | static void Process8(void); |
t_yamamoto | 0:669ef71cba68 | 200 | #endif |
t_yamamoto | 0:669ef71cba68 | 201 | #if USE_PROCESS_NUM>9 |
t_yamamoto | 0:669ef71cba68 | 202 | static void Process9(void); |
t_yamamoto | 0:669ef71cba68 | 203 | #endif |
t_yamamoto | 0:669ef71cba68 | 204 | #endif |
t_yamamoto | 0:669ef71cba68 | 205 | |
t_yamamoto | 0:669ef71cba68 | 206 | void SystemProcessInitialize() |
t_yamamoto | 0:669ef71cba68 | 207 | { |
yabahiro | 21:1f1e9c585da8 | 208 | #pragma region USER-DEFINED_VARIABLE_INIT |
yabahiro | 21:1f1e9c585da8 | 209 | /*Replace here with the initialization code of your variables.*/ |
yabahiro | 21:1f1e9c585da8 | 210 | #pragma endregion USER-DEFINED_VARIABLE_INIT |
t_yamamoto | 0:669ef71cba68 | 211 | |
yabahiro | 21:1f1e9c585da8 | 212 | lock = true; |
yabahiro | 21:1f1e9c585da8 | 213 | processChangeComp = true; |
yabahiro | 21:1f1e9c585da8 | 214 | current = DEFAULT_PROCESS; |
t_yamamoto | 0:669ef71cba68 | 215 | |
yabahiro | 21:1f1e9c585da8 | 216 | #ifdef USE_SUBPROCESS |
yabahiro | 21:1f1e9c585da8 | 217 | #if USE_PROCESS_NUM>0 |
yabahiro | 21:1f1e9c585da8 | 218 | Process[0] = Process0; |
yabahiro | 21:1f1e9c585da8 | 219 | #endif |
yabahiro | 21:1f1e9c585da8 | 220 | #if USE_PROCESS_NUM>1 |
yabahiro | 21:1f1e9c585da8 | 221 | Process[1] = Process1; |
yabahiro | 21:1f1e9c585da8 | 222 | #endif |
yabahiro | 21:1f1e9c585da8 | 223 | #if USE_PROCESS_NUM>2 |
yabahiro | 21:1f1e9c585da8 | 224 | Process[2] = Process2; |
yabahiro | 21:1f1e9c585da8 | 225 | #endif |
yabahiro | 21:1f1e9c585da8 | 226 | #if USE_PROCESS_NUM>3 |
yabahiro | 21:1f1e9c585da8 | 227 | Process[3] = Process3; |
yabahiro | 21:1f1e9c585da8 | 228 | #endif |
yabahiro | 21:1f1e9c585da8 | 229 | #if USE_PROCESS_NUM>4 |
yabahiro | 21:1f1e9c585da8 | 230 | Process[4] = Process4; |
yabahiro | 21:1f1e9c585da8 | 231 | #endif |
yabahiro | 21:1f1e9c585da8 | 232 | #if USE_PROCESS_NUM>5 |
yabahiro | 21:1f1e9c585da8 | 233 | Process[5] = Process5; |
yabahiro | 21:1f1e9c585da8 | 234 | #endif |
yabahiro | 21:1f1e9c585da8 | 235 | #if USE_PROCESS_NUM>6 |
yabahiro | 21:1f1e9c585da8 | 236 | Process[6] = Process6; |
yabahiro | 21:1f1e9c585da8 | 237 | #endif |
yabahiro | 21:1f1e9c585da8 | 238 | #if USE_PROCESS_NUM>7 |
yabahiro | 21:1f1e9c585da8 | 239 | Process[7] = Process7; |
yabahiro | 21:1f1e9c585da8 | 240 | #endif |
yabahiro | 21:1f1e9c585da8 | 241 | #if USE_PROCESS_NUM>8 |
yabahiro | 21:1f1e9c585da8 | 242 | Process[8] = Process8; |
yabahiro | 21:1f1e9c585da8 | 243 | #endif |
yabahiro | 21:1f1e9c585da8 | 244 | #if USE_PROCESS_NUM>9 |
yabahiro | 21:1f1e9c585da8 | 245 | Process[9] = Process9; |
yabahiro | 21:1f1e9c585da8 | 246 | #endif |
yabahiro | 21:1f1e9c585da8 | 247 | #endif |
t_yamamoto | 0:669ef71cba68 | 248 | } |
t_yamamoto | 0:669ef71cba68 | 249 | |
t_yamamoto | 0:669ef71cba68 | 250 | static void SystemProcessUpdate() |
t_yamamoto | 0:669ef71cba68 | 251 | { |
yabahiro | 21:1f1e9c585da8 | 252 | #ifdef USE_SUBPROCESS |
yabahiro | 21:1f1e9c585da8 | 253 | if(controller->Button.HOME) lock = false; |
yabahiro | 21:1f1e9c585da8 | 254 | |
yabahiro | 21:1f1e9c585da8 | 255 | if(controller->Button.START && processChangeComp) { |
yabahiro | 21:1f1e9c585da8 | 256 | current++; |
yabahiro | 21:1f1e9c585da8 | 257 | if (USE_PROCESS_NUM < current) current = USE_PROCESS_NUM; |
yabahiro | 21:1f1e9c585da8 | 258 | processChangeComp = false; |
yabahiro | 21:1f1e9c585da8 | 259 | } else if(controller->Button.SELECT && processChangeComp) { |
yabahiro | 21:1f1e9c585da8 | 260 | current--; |
yabahiro | 21:1f1e9c585da8 | 261 | if (current < 0) current = 0; |
yabahiro | 21:1f1e9c585da8 | 262 | processChangeComp = false; |
yabahiro | 21:1f1e9c585da8 | 263 | } else if(!controller->Button.SELECT && !controller->Button.START) processChangeComp = true; |
yabahiro | 21:1f1e9c585da8 | 264 | #endif |
yabahiro | 21:1f1e9c585da8 | 265 | |
yabahiro | 21:1f1e9c585da8 | 266 | #ifdef USE_MOTOR |
yabahiro | 21:1f1e9c585da8 | 267 | ACTUATORHUB::MOTOR::Motor::Update(motor); |
yabahiro | 21:1f1e9c585da8 | 268 | #endif |
yabahiro | 21:1f1e9c585da8 | 269 | |
yabahiro | 21:1f1e9c585da8 | 270 | #ifdef USE_SOLENOID |
yabahiro | 21:1f1e9c585da8 | 271 | ACTUATORHUB::SOLENOID::Solenoid::Update(solenoid); |
yabahiro | 21:1f1e9c585da8 | 272 | #endif |
yabahiro | 21:1f1e9c585da8 | 273 | |
yabahiro | 21:1f1e9c585da8 | 274 | #ifdef USE_RS485 |
yabahiro | 21:1f1e9c585da8 | 275 | ACTUATORHUB::ActuatorHub::Update(); |
yabahiro | 21:1f1e9c585da8 | 276 | #endif |
yabahiro | 21:1f1e9c585da8 | 277 | |
yabahiro | 21:1f1e9c585da8 | 278 | } |
yabahiro | 21:1f1e9c585da8 | 279 | |
yabahiro | 21:1f1e9c585da8 | 280 | int g[8]; |
yabahiro | 21:1f1e9c585da8 | 281 | |
yabahiro | 21:1f1e9c585da8 | 282 | void SystemProcess() |
yabahiro | 21:1f1e9c585da8 | 283 | { |
yabahiro | 21:1f1e9c585da8 | 284 | SystemProcessInitialize(); |
yabahiro | 21:1f1e9c585da8 | 285 | |
yabahiro | 21:1f1e9c585da8 | 286 | while(1) { |
yabahiro | 43:677f7446612e | 287 | if(EMC==0) { |
yabahiro | 43:677f7446612e | 288 | fast=40; |
yabahiro | 43:677f7446612e | 289 | normal=30; |
yabahiro | 43:677f7446612e | 290 | slow=20; |
yabahiro | 43:677f7446612e | 291 | cross=0;//十字数える用 |
yabahiro | 43:677f7446612e | 292 | cros=0; |
yabahiro | 46:4a8bca4cc1fd | 293 | count=0;//wait代替え |
yabahiro | 43:677f7446612e | 294 | UP_flag = false; |
yabahiro | 43:677f7446612e | 295 | SW_flag = false; |
yabahiro | 43:677f7446612e | 296 | Air_flag = false; |
yabahiro | 43:677f7446612e | 297 | zyouge=false; |
yabahiro | 43:677f7446612e | 298 | zyougedo=false; |
yabahiro | 43:677f7446612e | 299 | dz1=true; |
yabahiro | 43:677f7446612e | 300 | dz1i=false; |
yabahiro | 43:677f7446612e | 301 | dz2=true; |
yabahiro | 43:677f7446612e | 302 | dz2i=false; |
yabahiro | 43:677f7446612e | 303 | dz3=true; |
yabahiro | 43:677f7446612e | 304 | dz3i=false; |
yabahiro | 43:677f7446612e | 305 | dz4=true; |
yabahiro | 43:677f7446612e | 306 | dz4i=false; |
yabahiro | 43:677f7446612e | 307 | through=false; |
yabahiro | 43:677f7446612e | 308 | counts=false; |
yabahiro | 43:677f7446612e | 309 | mtc=false; |
yabahiro | 43:677f7446612e | 310 | mtc2 = false; |
yabahiro | 43:677f7446612e | 311 | current = 0; |
yabahiro | 43:677f7446612e | 312 | SystemProcessInitialize(); |
yabahiro | 43:677f7446612e | 313 | if(emcs==false) { |
yabahiro | 43:677f7446612e | 314 | AllActuatorReset(); |
yabahiro | 43:677f7446612e | 315 | emcs=true; |
yabahiro | 43:677f7446612e | 316 | } |
yabahiro | 43:677f7446612e | 317 | } else { |
yabahiro | 43:677f7446612e | 318 | emcs=false; |
yabahiro | 43:677f7446612e | 319 | } |
yabahiro | 43:677f7446612e | 320 | |
yabahiro | 42:4f9689c0a349 | 321 | if(mode==0) { |
yabahiro | 42:4f9689c0a349 | 322 | if(ZoneSW) { |
yabahiro | 42:4f9689c0a349 | 323 | LedMode(1); |
yabahiro | 42:4f9689c0a349 | 324 | } else { |
yabahiro | 42:4f9689c0a349 | 325 | LedMode(2); |
yabahiro | 42:4f9689c0a349 | 326 | } |
yabahiro | 42:4f9689c0a349 | 327 | } |
yabahiro | 21:1f1e9c585da8 | 328 | for(int i = 0; i < 8; i++) { |
yabahiro | 21:1f1e9c585da8 | 329 | g[i] = LineHub::GetPara(i); |
yabahiro | 21:1f1e9c585da8 | 330 | } |
yabahiro | 41:e1dd6d97f17d | 331 | if(ThSW) { |
yabahiro | 41:e1dd6d97f17d | 332 | Twsh=1; |
yabahiro | 41:e1dd6d97f17d | 333 | } else { |
yabahiro | 41:e1dd6d97f17d | 334 | Twsh=2; |
yabahiro | 41:e1dd6d97f17d | 335 | } |
yabahiro | 42:4f9689c0a349 | 336 | |
yabahiro | 45:878f8f385635 | 337 | if(StertSW && start_flag == true) { |
yabahiro | 42:4f9689c0a349 | 338 | start_flag = false; |
yabahiro | 42:4f9689c0a349 | 339 | lock = false; |
yabahiro | 42:4f9689c0a349 | 340 | if(ZoneSW) { |
yabahiro | 46:4a8bca4cc1fd | 341 | count=0; |
yabahiro | 42:4f9689c0a349 | 342 | mode=1; |
yabahiro | 44:c208a908583c | 343 | current = 6; |
yabahiro | 47:b6e5a6bfe7ab | 344 | |
yabahiro | 42:4f9689c0a349 | 345 | } else { |
yabahiro | 46:4a8bca4cc1fd | 346 | count=0; |
yabahiro | 42:4f9689c0a349 | 347 | mode=1; |
yabahiro | 43:677f7446612e | 348 | current = 4; |
yabahiro | 41:e1dd6d97f17d | 349 | } |
yabahiro | 42:4f9689c0a349 | 350 | } |
yabahiro | 41:e1dd6d97f17d | 351 | if(DWSW||DOSW) { |
yabahiro | 41:e1dd6d97f17d | 352 | if(DWSW) { |
yabahiro | 41:e1dd6d97f17d | 353 | zyouge=true; |
yabahiro | 41:e1dd6d97f17d | 354 | } |
yabahiro | 41:e1dd6d97f17d | 355 | if(DOSW) { |
yabahiro | 41:e1dd6d97f17d | 356 | if(DOLS) { |
yabahiro | 41:e1dd6d97f17d | 357 | motor[MOTOR_0].pwm = 100; |
yabahiro | 41:e1dd6d97f17d | 358 | motor[MOTOR_0].dir = BRAKE; |
yabahiro | 41:e1dd6d97f17d | 359 | } else { |
yabahiro | 41:e1dd6d97f17d | 360 | motor[MOTOR_0].pwm = 50; |
yabahiro | 41:e1dd6d97f17d | 361 | motor[MOTOR_0].dir = BACK; |
yabahiro | 41:e1dd6d97f17d | 362 | } |
yabahiro | 41:e1dd6d97f17d | 363 | } |
yabahiro | 42:4f9689c0a349 | 364 | } else if(zyouge==false) { |
yabahiro | 41:e1dd6d97f17d | 365 | motor[MOTOR_0].pwm = 100; |
yabahiro | 41:e1dd6d97f17d | 366 | motor[MOTOR_0].dir = BRAKE; |
yabahiro | 41:e1dd6d97f17d | 367 | } |
yabahiro | 41:e1dd6d97f17d | 368 | if(zyouge) { |
yabahiro | 41:e1dd6d97f17d | 369 | if(Twsh==1) { |
yabahiro | 46:4a8bca4cc1fd | 370 | motor[MOTOR_0].pwm = 215; |
yabahiro | 41:e1dd6d97f17d | 371 | motor[MOTOR_0].dir = FOR; |
yabahiro | 41:e1dd6d97f17d | 372 | if(UPLS) { |
yabahiro | 41:e1dd6d97f17d | 373 | motor[MOTOR_0].pwm = 100; |
yabahiro | 41:e1dd6d97f17d | 374 | motor[MOTOR_0].dir = BRAKE; |
yabahiro | 41:e1dd6d97f17d | 375 | zyouge=false; |
yabahiro | 41:e1dd6d97f17d | 376 | } |
yabahiro | 41:e1dd6d97f17d | 377 | } |
yabahiro | 41:e1dd6d97f17d | 378 | if(Twsh==2) { |
yabahiro | 46:4a8bca4cc1fd | 379 | motor[MOTOR_0].pwm = 245; |
yabahiro | 41:e1dd6d97f17d | 380 | motor[MOTOR_0].dir = FOR; |
yabahiro | 41:e1dd6d97f17d | 381 | if(UPLS2) { |
yabahiro | 41:e1dd6d97f17d | 382 | motor[MOTOR_0].pwm = 100; |
yabahiro | 41:e1dd6d97f17d | 383 | motor[MOTOR_0].dir = BRAKE; |
yabahiro | 41:e1dd6d97f17d | 384 | zyouge=false; |
yabahiro | 41:e1dd6d97f17d | 385 | } |
yabahiro | 41:e1dd6d97f17d | 386 | } |
yabahiro | 41:e1dd6d97f17d | 387 | } |
yabahiro | 41:e1dd6d97f17d | 388 | if(AIRSW) { |
yabahiro | 41:e1dd6d97f17d | 389 | if(SW_flag==false) { |
yabahiro | 41:e1dd6d97f17d | 390 | if(Air_flag==false) { |
yabahiro | 41:e1dd6d97f17d | 391 | solenoid.solenoid3 = SOLENOID_ON; |
yabahiro | 41:e1dd6d97f17d | 392 | Air_flag=true; |
yabahiro | 41:e1dd6d97f17d | 393 | SW_flag=true; |
yabahiro | 41:e1dd6d97f17d | 394 | } else { |
yabahiro | 41:e1dd6d97f17d | 395 | solenoid.solenoid3 = SOLENOID_OFF; |
yabahiro | 41:e1dd6d97f17d | 396 | Air_flag=false; |
yabahiro | 41:e1dd6d97f17d | 397 | SW_flag=true; |
yabahiro | 41:e1dd6d97f17d | 398 | } |
yabahiro | 41:e1dd6d97f17d | 399 | } |
yabahiro | 41:e1dd6d97f17d | 400 | } else { |
yabahiro | 42:4f9689c0a349 | 401 | if( SW_flag==true) { |
yabahiro | 42:4f9689c0a349 | 402 | count++; |
yabahiro | 43:677f7446612e | 403 | if(count>=2000) { |
yabahiro | 42:4f9689c0a349 | 404 | SW_flag=false; |
yabahiro | 42:4f9689c0a349 | 405 | count=0; |
yabahiro | 42:4f9689c0a349 | 406 | } |
yabahiro | 42:4f9689c0a349 | 407 | } |
yabahiro | 41:e1dd6d97f17d | 408 | } |
yabahiro | 35:94f026ab4d30 | 409 | |
yabahiro | 36:788274604650 | 410 | //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 | 411 | |
yabahiro | 21:1f1e9c585da8 | 412 | #ifdef USE_MU |
yabahiro | 21:1f1e9c585da8 | 413 | controller = CONTROLLER::Controller::GetData(); |
yabahiro | 21:1f1e9c585da8 | 414 | #endif |
yabahiro | 21:1f1e9c585da8 | 415 | |
yabahiro | 21:1f1e9c585da8 | 416 | #ifdef USE_ERRORCHECK |
yabahiro | 41:e1dd6d97f17d | 417 | if(SAFTY::ErrorCheck::Check() & SAFTY::Error::ControllerLost & start_flag) { //& start_flag |
yabahiro | 21:1f1e9c585da8 | 418 | CONTROLLER::Controller::DataReset(); |
yabahiro | 21:1f1e9c585da8 | 419 | AllActuatorReset(); |
yabahiro | 21:1f1e9c585da8 | 420 | lock = true; |
yabahiro | 21:1f1e9c585da8 | 421 | } else |
yabahiro | 21:1f1e9c585da8 | 422 | #endif |
yabahiro | 21:1f1e9c585da8 | 423 | { |
yabahiro | 21:1f1e9c585da8 | 424 | |
yabahiro | 21:1f1e9c585da8 | 425 | #ifdef USE_SUBPROCESS |
yabahiro | 21:1f1e9c585da8 | 426 | if(!lock) { |
yabahiro | 21:1f1e9c585da8 | 427 | Process[current](); |
yabahiro | 21:1f1e9c585da8 | 428 | } else |
yabahiro | 21:1f1e9c585da8 | 429 | #endif |
yabahiro | 21:1f1e9c585da8 | 430 | { |
yabahiro | 21:1f1e9c585da8 | 431 | //ロック時の処理 |
yabahiro | 21:1f1e9c585da8 | 432 | } |
yabahiro | 21:1f1e9c585da8 | 433 | } |
yabahiro | 43:677f7446612e | 434 | |
yabahiro | 21:1f1e9c585da8 | 435 | SystemProcessUpdate(); |
yabahiro | 21:1f1e9c585da8 | 436 | } |
t_yamamoto | 0:669ef71cba68 | 437 | } |
t_yamamoto | 0:669ef71cba68 | 438 | |
t_yamamoto | 0:669ef71cba68 | 439 | #pragma region PROCESS |
t_yamamoto | 0:669ef71cba68 | 440 | #ifdef USE_SUBPROCESS |
t_yamamoto | 0:669ef71cba68 | 441 | #if USE_PROCESS_NUM>0 |
yabahiro | 21:1f1e9c585da8 | 442 | static void Process0() |
yabahiro | 21:1f1e9c585da8 | 443 | { |
yabahiro | 42:4f9689c0a349 | 444 | /* |
yabahiro | 36:788274604650 | 445 | mode=1; |
yabahiro | 36:788274604650 | 446 | LedMode(1); |
yabahiro | 35:94f026ab4d30 | 447 | if(ThSW) { |
yabahiro | 35:94f026ab4d30 | 448 | Twsh=1; |
yabahiro | 35:94f026ab4d30 | 449 | } else { |
yabahiro | 35:94f026ab4d30 | 450 | Twsh=2; |
yabahiro | 31:45f97698857b | 451 | } |
yabahiro | 36:788274604650 | 452 | |
yabahiro | 25:38d4964e8aad | 453 | if(StertSW) { |
yabahiro | 41:e1dd6d97f17d | 454 | //start_flag == false; |
yabahiro | 41:e1dd6d97f17d | 455 | //lock = false; |
yabahiro | 36:788274604650 | 456 | if(ZoneSW) { |
yabahiro | 31:45f97698857b | 457 | mode=1; |
yabahiro | 31:45f97698857b | 458 | current = 2; |
yabahiro | 31:45f97698857b | 459 | } else { |
yabahiro | 31:45f97698857b | 460 | mode=1; |
yabahiro | 40:7f93984e8ba1 | 461 | current = 5; |
yabahiro | 31:45f97698857b | 462 | } |
yabahiro | 25:38d4964e8aad | 463 | } |
yabahiro | 35:94f026ab4d30 | 464 | if(DWSW) { |
yabahiro | 35:94f026ab4d30 | 465 | zyouge=true; |
yabahiro | 35:94f026ab4d30 | 466 | } |
yabahiro | 39:f89166d7411c | 467 | if(DOSW) { |
yabahiro | 39:f89166d7411c | 468 | zyougedo=true; |
yabahiro | 39:f89166d7411c | 469 | } |
yabahiro | 35:94f026ab4d30 | 470 | if(AIRSW) { |
yabahiro | 35:94f026ab4d30 | 471 | if(SW_flag==false) { |
yabahiro | 35:94f026ab4d30 | 472 | if(Air_flag==false) { |
yabahiro | 35:94f026ab4d30 | 473 | solenoid.solenoid3 = SOLENOID_ON; |
yabahiro | 35:94f026ab4d30 | 474 | Air_flag=true; |
yabahiro | 35:94f026ab4d30 | 475 | SW_flag=true; |
yabahiro | 35:94f026ab4d30 | 476 | } else { |
yabahiro | 35:94f026ab4d30 | 477 | solenoid.solenoid3 = SOLENOID_OFF; |
yabahiro | 35:94f026ab4d30 | 478 | Air_flag=false; |
yabahiro | 35:94f026ab4d30 | 479 | SW_flag=true; |
yabahiro | 35:94f026ab4d30 | 480 | } |
yabahiro | 35:94f026ab4d30 | 481 | } |
yabahiro | 35:94f026ab4d30 | 482 | } else { |
yabahiro | 35:94f026ab4d30 | 483 | SW_flag=false; |
yabahiro | 31:45f97698857b | 484 | } |
yabahiro | 31:45f97698857b | 485 | |
yabahiro | 35:94f026ab4d30 | 486 | if(zyouge) { |
yabahiro | 35:94f026ab4d30 | 487 | if(Twsh==1) { |
yabahiro | 35:94f026ab4d30 | 488 | motor[MOTOR_0].pwm = 220; |
yabahiro | 35:94f026ab4d30 | 489 | motor[MOTOR_0].dir = FOR; |
yabahiro | 35:94f026ab4d30 | 490 | if(UPLS) { |
yabahiro | 35:94f026ab4d30 | 491 | motor[MOTOR_0].pwm = 100; |
yabahiro | 35:94f026ab4d30 | 492 | motor[MOTOR_0].dir = BRAKE; |
yabahiro | 35:94f026ab4d30 | 493 | zyouge=false; |
yabahiro | 35:94f026ab4d30 | 494 | } |
yabahiro | 35:94f026ab4d30 | 495 | } |
yabahiro | 35:94f026ab4d30 | 496 | if(Twsh==2) { |
yabahiro | 37:7cfa39c41245 | 497 | motor[MOTOR_0].pwm = 230; |
yabahiro | 35:94f026ab4d30 | 498 | motor[MOTOR_0].dir = FOR; |
yabahiro | 35:94f026ab4d30 | 499 | if(UPLS2) { |
yabahiro | 35:94f026ab4d30 | 500 | motor[MOTOR_0].pwm = 100; |
yabahiro | 35:94f026ab4d30 | 501 | motor[MOTOR_0].dir = BRAKE; |
yabahiro | 35:94f026ab4d30 | 502 | zyouge=false; |
yabahiro | 35:94f026ab4d30 | 503 | } |
yabahiro | 31:45f97698857b | 504 | } |
yabahiro | 39:f89166d7411c | 505 | } |
yabahiro | 39:f89166d7411c | 506 | if(zyougedo) { |
yabahiro | 39:f89166d7411c | 507 | motor[MOTOR_0].pwm = 50; |
yabahiro | 39:f89166d7411c | 508 | motor[MOTOR_0].dir = BACK; |
yabahiro | 39:f89166d7411c | 509 | if(DOLS) { |
yabahiro | 39:f89166d7411c | 510 | motor[MOTOR_0].pwm = 100; |
yabahiro | 39:f89166d7411c | 511 | motor[MOTOR_0].dir = BRAKE; |
yabahiro | 39:f89166d7411c | 512 | zyougedo=false; |
yabahiro | 39:f89166d7411c | 513 | } |
yabahiro | 31:45f97698857b | 514 | } |
yabahiro | 42:4f9689c0a349 | 515 | */ |
yabahiro | 35:94f026ab4d30 | 516 | } |
t_yamamoto | 0:669ef71cba68 | 517 | #endif |
t_yamamoto | 0:669ef71cba68 | 518 | |
t_yamamoto | 0:669ef71cba68 | 519 | #if USE_PROCESS_NUM>1 |
kishibekairohan | 16:3f2c2d89372b | 520 | static void Process1() |
t_yamamoto | 0:669ef71cba68 | 521 | { |
yabahiro | 42:4f9689c0a349 | 522 | LedMode(6); |
yabahiro | 41:e1dd6d97f17d | 523 | start_flag = true; |
yabahiro | 36:788274604650 | 524 | mtc=false; |
yabahiro | 36:788274604650 | 525 | mtc2 = false; |
yabahiro | 31:45f97698857b | 526 | mode=1; |
yabahiro | 27:545148741493 | 527 | cross=0; |
yabahiro | 35:94f026ab4d30 | 528 | Twsh=1; |
yabahiro | 21:1f1e9c585da8 | 529 | motor[TIRE_FR].dir = SetStatus(-omni[controller->AnalogL.Y][14-controller->AnalogL.X] + curve[controller->AnalogR.X]); |
yabahiro | 21:1f1e9c585da8 | 530 | motor[TIRE_FL].dir = SetStatus(omni[controller->AnalogL.Y][controller->AnalogL.X] + curve[controller->AnalogR.X]); |
yabahiro | 21:1f1e9c585da8 | 531 | motor[TIRE_BR].dir = SetStatus(-omni[14-controller->AnalogL.X][14-controller->AnalogL.Y] + curve[controller->AnalogR.X]); |
yabahiro | 21:1f1e9c585da8 | 532 | motor[TIRE_BL].dir = SetStatus(omni[controller->AnalogL.X][14-controller->AnalogL.Y] + curve[controller->AnalogR.X]); |
yabahiro | 21:1f1e9c585da8 | 533 | |
yabahiro | 21:1f1e9c585da8 | 534 | motor[TIRE_FR].pwm = Setpwm(omni[controller->AnalogL.Y][14-controller->AnalogL.X]+ curve[controller->AnalogR.X])*0.2; |
yabahiro | 21:1f1e9c585da8 | 535 | motor[TIRE_FL].pwm = Setpwm(omni[controller->AnalogL.Y][controller->AnalogL.X]+ curve[controller->AnalogR.X])*0.2; |
yabahiro | 21:1f1e9c585da8 | 536 | motor[TIRE_BR].pwm = Setpwm(omni[14-controller->AnalogL.X][14-controller->AnalogL.Y]+ curve[controller->AnalogR.X])*0.2; |
yabahiro | 21:1f1e9c585da8 | 537 | motor[TIRE_BL].pwm = Setpwm(omni[controller->AnalogL.X][14-controller->AnalogL.Y]+ curve[controller->AnalogR.X])*0.2; |
yabahiro | 21:1f1e9c585da8 | 538 | |
yabahiro | 21:1f1e9c585da8 | 539 | if(controller->Button.UP||controller->Button.DOWN) { |
yabahiro | 21:1f1e9c585da8 | 540 | |
yabahiro | 21:1f1e9c585da8 | 541 | if(controller->Button.UP) { |
yabahiro | 35:94f026ab4d30 | 542 | motor[MOTOR_0].pwm =200; |
yabahiro | 21:1f1e9c585da8 | 543 | motor[MOTOR_0].dir = FOR; |
yabahiro | 35:94f026ab4d30 | 544 | if(UPLS) { |
yabahiro | 35:94f026ab4d30 | 545 | motor[MOTOR_0].pwm = 0; |
yabahiro | 35:94f026ab4d30 | 546 | motor[MOTOR_0].dir = BRAKE; |
yabahiro | 35:94f026ab4d30 | 547 | } |
yabahiro | 21:1f1e9c585da8 | 548 | } |
yabahiro | 21:1f1e9c585da8 | 549 | if(controller->Button.DOWN) { |
yabahiro | 21:1f1e9c585da8 | 550 | motor[MOTOR_0].pwm = 50; |
yabahiro | 21:1f1e9c585da8 | 551 | motor[MOTOR_0].dir = BACK; |
yabahiro | 21:1f1e9c585da8 | 552 | } |
yabahiro | 21:1f1e9c585da8 | 553 | } else { |
yabahiro | 21:1f1e9c585da8 | 554 | motor[MOTOR_0].pwm = 0; |
yabahiro | 21:1f1e9c585da8 | 555 | motor[MOTOR_0].dir = BRAKE; |
yabahiro | 21:1f1e9c585da8 | 556 | } |
yabahiro | 21:1f1e9c585da8 | 557 | |
yabahiro | 21:1f1e9c585da8 | 558 | if(controller->Button.Y) { |
yabahiro | 21:1f1e9c585da8 | 559 | if(dz2==true) { |
yabahiro | 21:1f1e9c585da8 | 560 | if(dz2i==false) { |
yabahiro | 21:1f1e9c585da8 | 561 | solenoid.solenoid2 = SOLENOID_ON; |
yabahiro | 21:1f1e9c585da8 | 562 | dz2i=true; |
yabahiro | 21:1f1e9c585da8 | 563 | } else { |
yabahiro | 21:1f1e9c585da8 | 564 | solenoid.solenoid2 = SOLENOID_OFF; |
yabahiro | 21:1f1e9c585da8 | 565 | dz2i=false; |
yabahiro | 21:1f1e9c585da8 | 566 | } |
yabahiro | 21:1f1e9c585da8 | 567 | dz2=false; |
yabahiro | 21:1f1e9c585da8 | 568 | } |
yabahiro | 21:1f1e9c585da8 | 569 | } else { |
yabahiro | 21:1f1e9c585da8 | 570 | dz2=true; |
yabahiro | 21:1f1e9c585da8 | 571 | } |
yabahiro | 21:1f1e9c585da8 | 572 | |
yabahiro | 21:1f1e9c585da8 | 573 | if(controller->Button.A) { |
yabahiro | 21:1f1e9c585da8 | 574 | if(dz3==true) { |
yabahiro | 21:1f1e9c585da8 | 575 | if(dz3i==false) { |
yabahiro | 30:9450dc1d53cc | 576 | |
yabahiro | 21:1f1e9c585da8 | 577 | dz3i=true; |
yabahiro | 21:1f1e9c585da8 | 578 | } else { |
yabahiro | 21:1f1e9c585da8 | 579 | solenoid.solenoid3 = SOLENOID_OFF; |
yabahiro | 21:1f1e9c585da8 | 580 | dz3i=false; |
yabahiro | 21:1f1e9c585da8 | 581 | } |
yabahiro | 21:1f1e9c585da8 | 582 | dz3=false; |
yabahiro | 21:1f1e9c585da8 | 583 | } |
yabahiro | 21:1f1e9c585da8 | 584 | } else { |
yabahiro | 21:1f1e9c585da8 | 585 | dz3=true; |
yabahiro | 21:1f1e9c585da8 | 586 | } |
yabahiro | 21:1f1e9c585da8 | 587 | |
yabahiro | 21:1f1e9c585da8 | 588 | if(controller->Button.B) { |
yabahiro | 21:1f1e9c585da8 | 589 | if(dz4==true) { |
yabahiro | 21:1f1e9c585da8 | 590 | if(dz4i==false) { |
yabahiro | 21:1f1e9c585da8 | 591 | solenoid.solenoid4 = SOLENOID_ON; |
yabahiro | 21:1f1e9c585da8 | 592 | dz4i=true; |
yabahiro | 21:1f1e9c585da8 | 593 | } else { |
yabahiro | 21:1f1e9c585da8 | 594 | solenoid.solenoid4 = SOLENOID_OFF; |
yabahiro | 21:1f1e9c585da8 | 595 | dz4i=false; |
yabahiro | 21:1f1e9c585da8 | 596 | } |
yabahiro | 21:1f1e9c585da8 | 597 | dz4=false; |
yabahiro | 21:1f1e9c585da8 | 598 | } |
yabahiro | 21:1f1e9c585da8 | 599 | } else { |
yabahiro | 21:1f1e9c585da8 | 600 | dz4=true; |
yabahiro | 21:1f1e9c585da8 | 601 | } |
yabahiro | 21:1f1e9c585da8 | 602 | /* |
yabahiro | 21:1f1e9c585da8 | 603 | if(controller->Button.RIGHT){ |
yabahiro | 21:1f1e9c585da8 | 604 | motor[MOTOR_1].dir = FOR; |
yabahiro | 21:1f1e9c585da8 | 605 | motor[MOTOR_1].pwm = 60; |
yabahiro | 21:1f1e9c585da8 | 606 | if (ARM_1){ |
yabahiro | 21:1f1e9c585da8 | 607 | motor[MOTOR_1].dir = BRAKE; |
yabahiro | 21:1f1e9c585da8 | 608 | } |
yabahiro | 21:1f1e9c585da8 | 609 | } |
yabahiro | 21:1f1e9c585da8 | 610 | else if(controller->Button.LEFT){ |
yabahiro | 21:1f1e9c585da8 | 611 | motor[MOTOR_1].dir = BACK; |
yabahiro | 21:1f1e9c585da8 | 612 | motor[MOTOR_1].pwm = 60; |
yabahiro | 21:1f1e9c585da8 | 613 | if (ARM_0){ |
yabahiro | 21:1f1e9c585da8 | 614 | motor[MOTOR_1].dir = BRAKE; |
yabahiro | 21:1f1e9c585da8 | 615 | } |
yabahiro | 21:1f1e9c585da8 | 616 | } |
yabahiro | 21:1f1e9c585da8 | 617 | */ |
t_yamamoto | 0:669ef71cba68 | 618 | } |
t_yamamoto | 0:669ef71cba68 | 619 | #endif |
t_yamamoto | 0:669ef71cba68 | 620 | |
t_yamamoto | 0:669ef71cba68 | 621 | #if USE_PROCESS_NUM>2 |
kishibekairohan | 16:3f2c2d89372b | 622 | static void Process2() |
yabahiro | 21:1f1e9c585da8 | 623 | { |
yabahiro | 42:4f9689c0a349 | 624 | // 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 | 36:788274604650 | 625 | LedMode(3); |
yabahiro | 31:45f97698857b | 626 | count++; |
yabahiro | 44:c208a908583c | 627 | if(mode==0||mode==1) { |
yabahiro | 35:94f026ab4d30 | 628 | |
yabahiro | 38:391a0c8e4c16 | 629 | if(Twsh==2) { |
yabahiro | 38:391a0c8e4c16 | 630 | solenoid.solenoid2 = SOLENOID_ON; |
yabahiro | 38:391a0c8e4c16 | 631 | } |
yabahiro | 35:94f026ab4d30 | 632 | if(counts==false&&g[0]==0) { |
yabahiro | 35:94f026ab4d30 | 633 | cros++; |
yabahiro | 35:94f026ab4d30 | 634 | counts=true; |
yabahiro | 35:94f026ab4d30 | 635 | } |
yabahiro | 35:94f026ab4d30 | 636 | if(counts==true&&g[0]==99) { |
yabahiro | 35:94f026ab4d30 | 637 | counts=false; |
yabahiro | 35:94f026ab4d30 | 638 | } |
yabahiro | 35:94f026ab4d30 | 639 | |
yabahiro | 35:94f026ab4d30 | 640 | if(cros==2) { |
yabahiro | 37:7cfa39c41245 | 641 | |
yabahiro | 37:7cfa39c41245 | 642 | // mode=21; |
yabahiro | 37:7cfa39c41245 | 643 | // count=0; |
yabahiro | 37:7cfa39c41245 | 644 | // cros=0; |
yabahiro | 35:94f026ab4d30 | 645 | }//ゆっくりモードに入れなかった時の保険 |
yabahiro | 44:c208a908583c | 646 | if(g[0]==0) { |
yabahiro | 44:c208a908583c | 647 | fast=35; |
yabahiro | 44:c208a908583c | 648 | normal=20; |
yabahiro | 44:c208a908583c | 649 | slow=15; |
yabahiro | 44:c208a908583c | 650 | } |
yabahiro | 45:878f8f385635 | 651 | |
yabahiro | 31:45f97698857b | 652 | switch(g[2]) { |
yabahiro | 31:45f97698857b | 653 | case 98: |
kishibekairohan | 33:656aa14904a5 | 654 | motor[TIRE_FR].pwm = normal; |
kishibekairohan | 22:c47f29caded6 | 655 | motor[TIRE_FR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 656 | motor[TIRE_FL].pwm = normal; |
kishibekairohan | 22:c47f29caded6 | 657 | motor[TIRE_FL].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 658 | motor[TIRE_BR].pwm = normal; |
kishibekairohan | 22:c47f29caded6 | 659 | motor[TIRE_BR].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 660 | motor[TIRE_BL].pwm = normal; |
kishibekairohan | 22:c47f29caded6 | 661 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 662 | if(count>30000) { |
yabahiro | 31:45f97698857b | 663 | cross++; |
yabahiro | 31:45f97698857b | 664 | count=0; |
yabahiro | 31:45f97698857b | 665 | } |
yabahiro | 31:45f97698857b | 666 | mtc2=true; |
yabahiro | 43:677f7446612e | 667 | if(cross==2) { |
yabahiro | 43:677f7446612e | 668 | mode=22; |
yabahiro | 31:45f97698857b | 669 | count=0; |
yabahiro | 31:45f97698857b | 670 | cross=0; |
yabahiro | 44:c208a908583c | 671 | fast=40; |
yabahiro | 44:c208a908583c | 672 | normal=30; |
yabahiro | 44:c208a908583c | 673 | slow=20; |
yabahiro | 31:45f97698857b | 674 | } |
yabahiro | 31:45f97698857b | 675 | break; |
yabahiro | 31:45f97698857b | 676 | case 0: |
kishibekairohan | 33:656aa14904a5 | 677 | motor[TIRE_FR].pwm = fast; |
yabahiro | 31:45f97698857b | 678 | motor[TIRE_FR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 679 | motor[TIRE_FL].pwm = fast; |
yabahiro | 31:45f97698857b | 680 | motor[TIRE_FL].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 681 | motor[TIRE_BR].pwm = fast; |
yabahiro | 31:45f97698857b | 682 | motor[TIRE_BR].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 683 | motor[TIRE_BL].pwm = fast; |
yabahiro | 31:45f97698857b | 684 | motor[TIRE_BL].dir = BACK; |
yabahiro | 31:45f97698857b | 685 | mtc2=true; |
yabahiro | 31:45f97698857b | 686 | break; |
yabahiro | 31:45f97698857b | 687 | case 255: |
kishibekairohan | 33:656aa14904a5 | 688 | motor[TIRE_FR].pwm = normal; |
yabahiro | 31:45f97698857b | 689 | motor[TIRE_FR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 690 | motor[TIRE_FL].pwm = fast; |
yabahiro | 31:45f97698857b | 691 | motor[TIRE_FL].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 692 | motor[TIRE_BR].pwm = fast; |
yabahiro | 31:45f97698857b | 693 | motor[TIRE_BR].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 694 | motor[TIRE_BL].pwm = normal; |
yabahiro | 31:45f97698857b | 695 | motor[TIRE_BL].dir = BACK; |
yabahiro | 31:45f97698857b | 696 | mtc2=true; |
yabahiro | 31:45f97698857b | 697 | break; |
yabahiro | 31:45f97698857b | 698 | case 253: |
yabahiro | 31:45f97698857b | 699 | motor[TIRE_FR].pwm = 0; |
yabahiro | 31:45f97698857b | 700 | motor[TIRE_FR].dir = FREE; |
kishibekairohan | 33:656aa14904a5 | 701 | motor[TIRE_FL].pwm = slow; |
yabahiro | 31:45f97698857b | 702 | motor[TIRE_FL].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 703 | motor[TIRE_BR].pwm = slow; |
yabahiro | 31:45f97698857b | 704 | motor[TIRE_BR].dir = BACK; |
yabahiro | 31:45f97698857b | 705 | motor[TIRE_BL].pwm = 0; |
yabahiro | 31:45f97698857b | 706 | motor[TIRE_BL].dir = FREE; |
yabahiro | 31:45f97698857b | 707 | mtc2=true; |
yabahiro | 31:45f97698857b | 708 | break; |
yabahiro | 31:45f97698857b | 709 | case 254: |
yabahiro | 31:45f97698857b | 710 | motor[TIRE_FR].pwm = 0; |
yabahiro | 31:45f97698857b | 711 | motor[TIRE_FR].dir = FREE; |
kishibekairohan | 33:656aa14904a5 | 712 | motor[TIRE_FL].pwm = normal; |
yabahiro | 31:45f97698857b | 713 | motor[TIRE_FL].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 714 | motor[TIRE_BR].pwm = normal; |
yabahiro | 31:45f97698857b | 715 | motor[TIRE_BR].dir = BACK; |
yabahiro | 31:45f97698857b | 716 | motor[TIRE_BL].pwm = 0; |
yabahiro | 31:45f97698857b | 717 | motor[TIRE_BL].dir = FREE; |
yabahiro | 31:45f97698857b | 718 | mtc2=true; |
yabahiro | 31:45f97698857b | 719 | break; |
yabahiro | 31:45f97698857b | 720 | case 1: |
kishibekairohan | 33:656aa14904a5 | 721 | motor[TIRE_FR].pwm = fast; |
yabahiro | 31:45f97698857b | 722 | motor[TIRE_FR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 723 | motor[TIRE_FL].pwm = slow; |
yabahiro | 31:45f97698857b | 724 | motor[TIRE_FL].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 725 | motor[TIRE_BR].pwm = slow; |
yabahiro | 31:45f97698857b | 726 | motor[TIRE_BR].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 727 | motor[TIRE_BL].pwm = fast; |
yabahiro | 31:45f97698857b | 728 | motor[TIRE_BL].dir = BACK; |
yabahiro | 31:45f97698857b | 729 | mtc2=true; |
yabahiro | 31:45f97698857b | 730 | break; |
yabahiro | 31:45f97698857b | 731 | case 3: |
kishibekairohan | 33:656aa14904a5 | 732 | motor[TIRE_FR].pwm = slow; |
yabahiro | 31:45f97698857b | 733 | motor[TIRE_FR].dir = FOR; |
yabahiro | 31:45f97698857b | 734 | motor[TIRE_FL].pwm = 0; |
yabahiro | 31:45f97698857b | 735 | motor[TIRE_FL].dir = FREE; |
yabahiro | 31:45f97698857b | 736 | motor[TIRE_BR].pwm = 0; |
yabahiro | 31:45f97698857b | 737 | motor[TIRE_BR].dir = FREE; |
kishibekairohan | 33:656aa14904a5 | 738 | motor[TIRE_BL].pwm = slow; |
yabahiro | 31:45f97698857b | 739 | motor[TIRE_BL].dir = BACK; |
yabahiro | 31:45f97698857b | 740 | mtc2=true; |
yabahiro | 31:45f97698857b | 741 | break; |
yabahiro | 31:45f97698857b | 742 | case 2: |
kishibekairohan | 33:656aa14904a5 | 743 | motor[TIRE_FR].pwm = normal; |
yabahiro | 31:45f97698857b | 744 | motor[TIRE_FR].dir = FOR; |
yabahiro | 31:45f97698857b | 745 | motor[TIRE_FL].pwm = 0; |
yabahiro | 31:45f97698857b | 746 | motor[TIRE_FL].dir = FREE; |
yabahiro | 31:45f97698857b | 747 | motor[TIRE_BR].pwm = 0; |
yabahiro | 31:45f97698857b | 748 | motor[TIRE_BR].dir = FREE; |
kishibekairohan | 33:656aa14904a5 | 749 | motor[TIRE_BL].pwm = normal; |
yabahiro | 31:45f97698857b | 750 | motor[TIRE_BL].dir = BACK; |
yabahiro | 31:45f97698857b | 751 | mtc2=true; |
yabahiro | 31:45f97698857b | 752 | break; |
yabahiro | 31:45f97698857b | 753 | } |
yabahiro | 31:45f97698857b | 754 | if(g[2]!=98&&mtc2==true) { |
yabahiro | 31:45f97698857b | 755 | switch(g[3]) { |
yabahiro | 29:c78a46f51209 | 756 | case 0: |
yabahiro | 31:45f97698857b | 757 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 758 | break; |
yabahiro | 29:c78a46f51209 | 759 | case 255: |
yabahiro | 31:45f97698857b | 760 | motor[TIRE_BL].pwm += 5; |
yabahiro | 31:45f97698857b | 761 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 762 | break; |
yabahiro | 29:c78a46f51209 | 763 | case 253: |
yabahiro | 31:45f97698857b | 764 | motor[TIRE_BL].pwm += 10; |
yabahiro | 31:45f97698857b | 765 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 766 | break; |
yabahiro | 29:c78a46f51209 | 767 | case 254: |
yabahiro | 31:45f97698857b | 768 | motor[TIRE_BL].pwm += 20; |
yabahiro | 29:c78a46f51209 | 769 | motor[TIRE_FL].pwm = 0; |
yabahiro | 31:45f97698857b | 770 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 771 | break; |
yabahiro | 29:c78a46f51209 | 772 | case 1: |
yabahiro | 31:45f97698857b | 773 | motor[TIRE_FL].pwm += 5; |
yabahiro | 31:45f97698857b | 774 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 775 | break; |
yabahiro | 29:c78a46f51209 | 776 | case 3: |
yabahiro | 31:45f97698857b | 777 | motor[TIRE_FL].pwm += 10; |
yabahiro | 31:45f97698857b | 778 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 779 | break; |
yabahiro | 29:c78a46f51209 | 780 | case 2: |
yabahiro | 31:45f97698857b | 781 | motor[TIRE_FL].pwm += 20; |
yabahiro | 31:45f97698857b | 782 | motor[TIRE_BL].pwm = 0; |
yabahiro | 31:45f97698857b | 783 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 784 | break; |
yabahiro | 29:c78a46f51209 | 785 | } |
yabahiro | 31:45f97698857b | 786 | } |
yabahiro | 31:45f97698857b | 787 | } else if(mode==21) { |
yabahiro | 43:677f7446612e | 788 | motor[TIRE_FR].pwm = 30; |
yabahiro | 42:4f9689c0a349 | 789 | motor[TIRE_FR].dir = FOR; |
yabahiro | 42:4f9689c0a349 | 790 | motor[TIRE_FL].pwm = 30; |
yabahiro | 42:4f9689c0a349 | 791 | motor[TIRE_FL].dir = FOR; |
yabahiro | 43:677f7446612e | 792 | motor[TIRE_BR].pwm = 30; |
yabahiro | 42:4f9689c0a349 | 793 | motor[TIRE_BR].dir = BACK; |
yabahiro | 42:4f9689c0a349 | 794 | motor[TIRE_BL].pwm = 30; |
yabahiro | 42:4f9689c0a349 | 795 | motor[TIRE_BL].dir = BACK; |
yabahiro | 42:4f9689c0a349 | 796 | if(g[2]==98&&count>=10000) { |
yabahiro | 42:4f9689c0a349 | 797 | mode=22; |
yabahiro | 42:4f9689c0a349 | 798 | count=0; |
yabahiro | 42:4f9689c0a349 | 799 | } |
yabahiro | 43:677f7446612e | 800 | } |
yabahiro | 44:c208a908583c | 801 | if(YELLOW==true) { |
yabahiro | 43:677f7446612e | 802 | if(mode==22) { |
yabahiro | 44:c208a908583c | 803 | motor[TIRE_FR].pwm = 100; |
yabahiro | 43:677f7446612e | 804 | motor[TIRE_FR].dir = BRAKE; |
yabahiro | 44:c208a908583c | 805 | motor[TIRE_FL].pwm = 100; |
yabahiro | 43:677f7446612e | 806 | motor[TIRE_FL].dir = BRAKE; |
yabahiro | 44:c208a908583c | 807 | motor[TIRE_BR].pwm = 100; |
yabahiro | 43:677f7446612e | 808 | motor[TIRE_BR].dir = BRAKE; |
yabahiro | 44:c208a908583c | 809 | motor[TIRE_BL].pwm = 100; |
yabahiro | 43:677f7446612e | 810 | motor[TIRE_BL].dir = BRAKE; |
yabahiro | 44:c208a908583c | 811 | if(count>=10000) { |
yabahiro | 43:677f7446612e | 812 | mode=23; |
yabahiro | 43:677f7446612e | 813 | } |
yabahiro | 43:677f7446612e | 814 | } else if(mode==23) { |
yabahiro | 43:677f7446612e | 815 | motor[TIRE_FR].pwm = 20; |
yabahiro | 43:677f7446612e | 816 | motor[TIRE_FR].dir = BACK; |
yabahiro | 43:677f7446612e | 817 | motor[TIRE_FL].pwm = 20; |
yabahiro | 43:677f7446612e | 818 | motor[TIRE_FL].dir = BACK; |
yabahiro | 43:677f7446612e | 819 | motor[TIRE_BR].pwm = 20; |
yabahiro | 43:677f7446612e | 820 | motor[TIRE_BR].dir = FOR; |
yabahiro | 43:677f7446612e | 821 | motor[TIRE_BL].pwm = 20; |
yabahiro | 43:677f7446612e | 822 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 823 | if(g[2]==98) { |
yabahiro | 44:c208a908583c | 824 | mode=24; |
yabahiro | 44:c208a908583c | 825 | count=0; |
yabahiro | 44:c208a908583c | 826 | } |
yabahiro | 44:c208a908583c | 827 | } else if(mode==24) { |
yabahiro | 44:c208a908583c | 828 | motor[TIRE_FR].pwm = 20; |
yabahiro | 44:c208a908583c | 829 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 830 | motor[TIRE_FL].pwm = 20; |
yabahiro | 44:c208a908583c | 831 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 832 | motor[TIRE_BR].pwm = 20; |
yabahiro | 44:c208a908583c | 833 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 834 | motor[TIRE_BL].pwm = 20; |
yabahiro | 44:c208a908583c | 835 | motor[TIRE_BL].dir = FOR; |
yabahiro | 43:677f7446612e | 836 | if(g[2]!=98) { |
yabahiro | 43:677f7446612e | 837 | count=0; |
yabahiro | 44:c208a908583c | 838 | mode=25; |
yabahiro | 43:677f7446612e | 839 | } |
yabahiro | 44:c208a908583c | 840 | } else if(mode==25) { |
yabahiro | 43:677f7446612e | 841 | motor[TIRE_FR].pwm = 10; |
yabahiro | 43:677f7446612e | 842 | motor[TIRE_FR].dir = BRAKE; |
yabahiro | 43:677f7446612e | 843 | motor[TIRE_FL].pwm = 10; |
yabahiro | 43:677f7446612e | 844 | motor[TIRE_FL].dir = BRAKE; |
yabahiro | 43:677f7446612e | 845 | motor[TIRE_BR].pwm = 10; |
yabahiro | 43:677f7446612e | 846 | motor[TIRE_BR].dir = BRAKE; |
yabahiro | 43:677f7446612e | 847 | motor[TIRE_BL].pwm = 10; |
yabahiro | 43:677f7446612e | 848 | motor[TIRE_BL].dir = BRAKE; |
yabahiro | 44:c208a908583c | 849 | if(count>=10000) { |
yabahiro | 44:c208a908583c | 850 | mode=26; |
yabahiro | 44:c208a908583c | 851 | count=0; |
yabahiro | 43:677f7446612e | 852 | } |
yabahiro | 44:c208a908583c | 853 | } else if(mode==26) { |
yabahiro | 44:c208a908583c | 854 | motor[TIRE_FR].pwm = 20; |
yabahiro | 43:677f7446612e | 855 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 856 | motor[TIRE_FL].pwm = 20; |
yabahiro | 43:677f7446612e | 857 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 858 | motor[TIRE_BR].pwm = 20; |
yabahiro | 44:c208a908583c | 859 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 860 | motor[TIRE_BL].pwm = 20; |
yabahiro | 44:c208a908583c | 861 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 862 | if(count>=5000) { |
yabahiro | 44:c208a908583c | 863 | mode=27; |
yabahiro | 44:c208a908583c | 864 | count=0; |
yabahiro | 44:c208a908583c | 865 | } |
yabahiro | 44:c208a908583c | 866 | } else if(mode==27) { |
yabahiro | 44:c208a908583c | 867 | motor[TIRE_FR].pwm = 20; |
yabahiro | 44:c208a908583c | 868 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 869 | motor[TIRE_FL].pwm = 20; |
yabahiro | 44:c208a908583c | 870 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 871 | motor[TIRE_BR].pwm = 20; |
yabahiro | 43:677f7446612e | 872 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 873 | motor[TIRE_BL].pwm = 20; |
yabahiro | 43:677f7446612e | 874 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 875 | //どれくらい回転するかって値 |
yabahiro | 44:c208a908583c | 876 | if(count>=2500) { |
yabahiro | 44:c208a908583c | 877 | count=0; |
yabahiro | 43:677f7446612e | 878 | mode=30; |
yabahiro | 43:677f7446612e | 879 | } |
yabahiro | 43:677f7446612e | 880 | } else if(mode==24) { |
yabahiro | 43:677f7446612e | 881 | motor[TIRE_FR].pwm = 10; |
yabahiro | 43:677f7446612e | 882 | motor[TIRE_FR].dir = BRAKE; |
yabahiro | 43:677f7446612e | 883 | motor[TIRE_FL].pwm = 10; |
yabahiro | 43:677f7446612e | 884 | motor[TIRE_FL].dir = BRAKE; |
yabahiro | 43:677f7446612e | 885 | motor[TIRE_BR].pwm = 10; |
yabahiro | 43:677f7446612e | 886 | motor[TIRE_BR].dir = BRAKE; |
yabahiro | 43:677f7446612e | 887 | motor[TIRE_BL].pwm = 10; |
yabahiro | 43:677f7446612e | 888 | motor[TIRE_BL].dir = BRAKE; |
yabahiro | 44:c208a908583c | 889 | if(count>=10000) { |
yabahiro | 43:677f7446612e | 890 | mode=30; |
yabahiro | 44:c208a908583c | 891 | count=0; |
yabahiro | 43:677f7446612e | 892 | } |
yabahiro | 42:4f9689c0a349 | 893 | } |
yabahiro | 43:677f7446612e | 894 | } else { |
yabahiro | 43:677f7446612e | 895 | if(mode==22) { |
yabahiro | 43:677f7446612e | 896 | motor[TIRE_FR].pwm = 0; |
yabahiro | 43:677f7446612e | 897 | motor[TIRE_FR].dir = FREE; |
yabahiro | 43:677f7446612e | 898 | motor[TIRE_FL].pwm = 25; |
yabahiro | 43:677f7446612e | 899 | motor[TIRE_FL].dir = FOR; |
yabahiro | 43:677f7446612e | 900 | motor[TIRE_BR].pwm = 25; |
yabahiro | 43:677f7446612e | 901 | motor[TIRE_BR].dir = BACK; |
yabahiro | 43:677f7446612e | 902 | motor[TIRE_BL].pwm = 0; |
yabahiro | 43:677f7446612e | 903 | motor[TIRE_BL].dir = FREE; |
yabahiro | 43:677f7446612e | 904 | if(g[0]==0) { |
yabahiro | 43:677f7446612e | 905 | mode=30; |
yabahiro | 43:677f7446612e | 906 | cros=0; |
yabahiro | 43:677f7446612e | 907 | } |
yabahiro | 42:4f9689c0a349 | 908 | } |
yabahiro | 43:677f7446612e | 909 | } |
yabahiro | 43:677f7446612e | 910 | if(mode==30) { |
yabahiro | 44:c208a908583c | 911 | motor[TIRE_FR].pwm = 59; |
yabahiro | 38:391a0c8e4c16 | 912 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 913 | motor[TIRE_FL].pwm = 62; |
yabahiro | 38:391a0c8e4c16 | 914 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 915 | motor[TIRE_BR].pwm = 59; |
yabahiro | 38:391a0c8e4c16 | 916 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 917 | motor[TIRE_BL].pwm = 62; |
yabahiro | 38:391a0c8e4c16 | 918 | motor[TIRE_BL].dir = FOR; |
yabahiro | 38:391a0c8e4c16 | 919 | if(g[0]==98) { |
yabahiro | 35:94f026ab4d30 | 920 | mode=31; |
yabahiro | 38:391a0c8e4c16 | 921 | count=0; |
yabahiro | 38:391a0c8e4c16 | 922 | } |
yabahiro | 38:391a0c8e4c16 | 923 | } else if(mode==31) { |
yabahiro | 42:4f9689c0a349 | 924 | motor[TIRE_FR].pwm = 0; |
yabahiro | 42:4f9689c0a349 | 925 | motor[TIRE_FR].dir = FREE; |
yabahiro | 42:4f9689c0a349 | 926 | motor[TIRE_FL].pwm = 0; |
yabahiro | 42:4f9689c0a349 | 927 | motor[TIRE_FL].dir = FREE; |
yabahiro | 42:4f9689c0a349 | 928 | motor[TIRE_BR].pwm = 0; |
yabahiro | 42:4f9689c0a349 | 929 | motor[TIRE_BR].dir = FREE; |
yabahiro | 42:4f9689c0a349 | 930 | motor[TIRE_BL].pwm = 0; |
yabahiro | 42:4f9689c0a349 | 931 | motor[TIRE_BL].dir = FREE; |
yabahiro | 42:4f9689c0a349 | 932 | if(count>=5000) { |
yabahiro | 38:391a0c8e4c16 | 933 | count=0; |
yabahiro | 38:391a0c8e4c16 | 934 | mode=32; |
yabahiro | 38:391a0c8e4c16 | 935 | } |
yabahiro | 38:391a0c8e4c16 | 936 | } else if(mode==32) { |
yabahiro | 42:4f9689c0a349 | 937 | motor[TIRE_FR].pwm = 10; |
yabahiro | 42:4f9689c0a349 | 938 | motor[TIRE_FR].dir = BRAKE; |
yabahiro | 42:4f9689c0a349 | 939 | motor[TIRE_FL].pwm = 10; |
yabahiro | 42:4f9689c0a349 | 940 | motor[TIRE_FL].dir = BRAKE; |
yabahiro | 42:4f9689c0a349 | 941 | motor[TIRE_BR].pwm = 10; |
yabahiro | 42:4f9689c0a349 | 942 | motor[TIRE_BR].dir = BRAKE; |
yabahiro | 42:4f9689c0a349 | 943 | motor[TIRE_BL].pwm = 10; |
yabahiro | 42:4f9689c0a349 | 944 | motor[TIRE_BL].dir = BRAKE; |
yabahiro | 42:4f9689c0a349 | 945 | if(count>=40000) { |
yabahiro | 42:4f9689c0a349 | 946 | mode=33; |
yabahiro | 42:4f9689c0a349 | 947 | count=0; |
yabahiro | 42:4f9689c0a349 | 948 | } |
yabahiro | 42:4f9689c0a349 | 949 | } else if(mode==33) { |
yabahiro | 44:c208a908583c | 950 | motor[TIRE_FR].pwm = 0; |
yabahiro | 42:4f9689c0a349 | 951 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 952 | motor[TIRE_FL].pwm = 30; |
yabahiro | 44:c208a908583c | 953 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 954 | motor[TIRE_BR].pwm = 30; |
yabahiro | 44:c208a908583c | 955 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 956 | motor[TIRE_BL].pwm = 0; |
yabahiro | 42:4f9689c0a349 | 957 | motor[TIRE_BL].dir = FOR; |
yabahiro | 38:391a0c8e4c16 | 958 | if(g[3]==0) { |
yabahiro | 38:391a0c8e4c16 | 959 | count=0; |
yabahiro | 39:f89166d7411c | 960 | if(Twsh==2) { |
yabahiro | 39:f89166d7411c | 961 | solenoid.solenoid2 = SOLENOID_OFF; |
yabahiro | 39:f89166d7411c | 962 | } |
yabahiro | 38:391a0c8e4c16 | 963 | mode=40; |
yabahiro | 38:391a0c8e4c16 | 964 | } |
yabahiro | 31:45f97698857b | 965 | } else if(mode==40) { |
yabahiro | 38:391a0c8e4c16 | 966 | if(LIB) { |
yabahiro | 38:391a0c8e4c16 | 967 | mode=42; |
yabahiro | 38:391a0c8e4c16 | 968 | } |
yabahiro | 35:94f026ab4d30 | 969 | if(counts==false&&g[0]==0) { |
yabahiro | 35:94f026ab4d30 | 970 | cros++; |
yabahiro | 35:94f026ab4d30 | 971 | counts=true; |
yabahiro | 35:94f026ab4d30 | 972 | } |
yabahiro | 35:94f026ab4d30 | 973 | if(counts==true&&g[0]==99) { |
yabahiro | 35:94f026ab4d30 | 974 | counts=false; |
yabahiro | 35:94f026ab4d30 | 975 | } |
yabahiro | 35:94f026ab4d30 | 976 | |
yabahiro | 38:391a0c8e4c16 | 977 | if(cros==1) { |
yabahiro | 36:788274604650 | 978 | // mode=41; |
yabahiro | 35:94f026ab4d30 | 979 | //count=0; |
yabahiro | 35:94f026ab4d30 | 980 | //cros=0; |
yabahiro | 35:94f026ab4d30 | 981 | }//ゆっくりモードに入れなかった時の保険 |
yabahiro | 35:94f026ab4d30 | 982 | |
yabahiro | 31:45f97698857b | 983 | switch(g[3]) { |
yabahiro | 31:45f97698857b | 984 | case 98: |
kishibekairohan | 33:656aa14904a5 | 985 | motor[TIRE_FR].pwm = normal; |
yabahiro | 31:45f97698857b | 986 | motor[TIRE_FR].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 987 | motor[TIRE_FL].pwm = normal; |
yabahiro | 31:45f97698857b | 988 | motor[TIRE_FL].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 989 | motor[TIRE_BR].pwm = normal; |
yabahiro | 31:45f97698857b | 990 | motor[TIRE_BR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 991 | motor[TIRE_BL].pwm = normal; |
yabahiro | 31:45f97698857b | 992 | motor[TIRE_BL].dir = FOR; |
yabahiro | 35:94f026ab4d30 | 993 | if(count>20000) { |
yabahiro | 31:45f97698857b | 994 | cross++; |
yabahiro | 31:45f97698857b | 995 | count=0; |
yabahiro | 31:45f97698857b | 996 | } |
yabahiro | 31:45f97698857b | 997 | mtc2=true; |
yabahiro | 44:c208a908583c | 998 | if(cross==2) { |
yabahiro | 31:45f97698857b | 999 | mode=41; |
yabahiro | 31:45f97698857b | 1000 | count=0; |
yabahiro | 31:45f97698857b | 1001 | cross=0; |
kishibekairohan | 22:c47f29caded6 | 1002 | } |
yabahiro | 31:45f97698857b | 1003 | break; |
yabahiro | 31:45f97698857b | 1004 | case 0: |
kishibekairohan | 33:656aa14904a5 | 1005 | motor[TIRE_FR].pwm = fast; |
yabahiro | 31:45f97698857b | 1006 | motor[TIRE_FR].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 1007 | motor[TIRE_FL].pwm = fast; |
yabahiro | 31:45f97698857b | 1008 | motor[TIRE_FL].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 1009 | motor[TIRE_BR].pwm = fast; |
yabahiro | 31:45f97698857b | 1010 | motor[TIRE_BR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 1011 | motor[TIRE_BL].pwm = fast; |
yabahiro | 31:45f97698857b | 1012 | motor[TIRE_BL].dir = FOR; |
yabahiro | 31:45f97698857b | 1013 | mtc2=true; |
yabahiro | 31:45f97698857b | 1014 | break; |
yabahiro | 31:45f97698857b | 1015 | case 255: |
kishibekairohan | 33:656aa14904a5 | 1016 | motor[TIRE_FR].pwm = slow; |
yabahiro | 31:45f97698857b | 1017 | motor[TIRE_FR].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 1018 | motor[TIRE_FL].pwm = fast; |
yabahiro | 31:45f97698857b | 1019 | motor[TIRE_FL].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 1020 | motor[TIRE_BR].pwm = fast; |
yabahiro | 31:45f97698857b | 1021 | motor[TIRE_BR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 1022 | motor[TIRE_BL].pwm = slow; |
yabahiro | 31:45f97698857b | 1023 | motor[TIRE_BL].dir = FOR; |
yabahiro | 31:45f97698857b | 1024 | mtc2=true; |
yabahiro | 31:45f97698857b | 1025 | break; |
yabahiro | 31:45f97698857b | 1026 | case 253: |
yabahiro | 31:45f97698857b | 1027 | motor[TIRE_FR].pwm = 0; |
yabahiro | 31:45f97698857b | 1028 | motor[TIRE_FR].dir = FREE; |
kishibekairohan | 33:656aa14904a5 | 1029 | motor[TIRE_FL].pwm = slow; |
yabahiro | 31:45f97698857b | 1030 | motor[TIRE_FL].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 1031 | motor[TIRE_BR].pwm = slow; |
yabahiro | 31:45f97698857b | 1032 | motor[TIRE_BR].dir = FOR; |
yabahiro | 31:45f97698857b | 1033 | motor[TIRE_BL].pwm = 0; |
yabahiro | 31:45f97698857b | 1034 | motor[TIRE_BL].dir = FREE; |
yabahiro | 31:45f97698857b | 1035 | mtc2=true; |
yabahiro | 31:45f97698857b | 1036 | break; |
yabahiro | 31:45f97698857b | 1037 | case 254: |
yabahiro | 31:45f97698857b | 1038 | motor[TIRE_FR].pwm = 0; |
yabahiro | 31:45f97698857b | 1039 | motor[TIRE_FR].dir = FREE; |
kishibekairohan | 33:656aa14904a5 | 1040 | motor[TIRE_FL].pwm = normal; |
yabahiro | 31:45f97698857b | 1041 | motor[TIRE_FL].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 1042 | motor[TIRE_BR].pwm = normal; |
yabahiro | 31:45f97698857b | 1043 | motor[TIRE_BR].dir = FOR; |
yabahiro | 31:45f97698857b | 1044 | motor[TIRE_BL].pwm = 0; |
yabahiro | 31:45f97698857b | 1045 | motor[TIRE_BL].dir = FREE; |
yabahiro | 31:45f97698857b | 1046 | mtc2=true; |
yabahiro | 31:45f97698857b | 1047 | break; |
yabahiro | 31:45f97698857b | 1048 | case 1: |
kishibekairohan | 33:656aa14904a5 | 1049 | motor[TIRE_FR].pwm = fast; |
yabahiro | 31:45f97698857b | 1050 | motor[TIRE_FR].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 1051 | motor[TIRE_FL].pwm = slow; |
yabahiro | 31:45f97698857b | 1052 | motor[TIRE_FL].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 1053 | motor[TIRE_BR].pwm = slow; |
yabahiro | 31:45f97698857b | 1054 | motor[TIRE_BR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 1055 | motor[TIRE_BL].pwm = fast; |
yabahiro | 31:45f97698857b | 1056 | motor[TIRE_BL].dir = FOR; |
yabahiro | 31:45f97698857b | 1057 | mtc2=true; |
yabahiro | 31:45f97698857b | 1058 | break; |
yabahiro | 31:45f97698857b | 1059 | case 3: |
kishibekairohan | 33:656aa14904a5 | 1060 | motor[TIRE_FR].pwm = slow; |
yabahiro | 31:45f97698857b | 1061 | motor[TIRE_FR].dir = BACK; |
yabahiro | 31:45f97698857b | 1062 | motor[TIRE_FL].pwm = 0; |
yabahiro | 31:45f97698857b | 1063 | motor[TIRE_FL].dir = FREE; |
yabahiro | 31:45f97698857b | 1064 | motor[TIRE_BR].pwm = 0; |
yabahiro | 31:45f97698857b | 1065 | motor[TIRE_BR].dir = FREE; |
kishibekairohan | 33:656aa14904a5 | 1066 | motor[TIRE_BL].pwm = slow; |
yabahiro | 31:45f97698857b | 1067 | motor[TIRE_BL].dir = FOR; |
yabahiro | 31:45f97698857b | 1068 | mtc2=true; |
yabahiro | 31:45f97698857b | 1069 | break; |
yabahiro | 31:45f97698857b | 1070 | case 2: |
kishibekairohan | 33:656aa14904a5 | 1071 | motor[TIRE_FR].pwm = normal; |
yabahiro | 31:45f97698857b | 1072 | motor[TIRE_FR].dir = BACK; |
yabahiro | 31:45f97698857b | 1073 | motor[TIRE_FL].pwm = 0; |
yabahiro | 31:45f97698857b | 1074 | motor[TIRE_FL].dir = FREE; |
yabahiro | 31:45f97698857b | 1075 | motor[TIRE_BR].pwm = 0; |
yabahiro | 31:45f97698857b | 1076 | motor[TIRE_BR].dir = FREE; |
kishibekairohan | 33:656aa14904a5 | 1077 | motor[TIRE_BL].pwm = normal; |
yabahiro | 31:45f97698857b | 1078 | motor[TIRE_BL].dir = FOR; |
yabahiro | 31:45f97698857b | 1079 | mtc2=true; |
yabahiro | 31:45f97698857b | 1080 | break; |
yabahiro | 31:45f97698857b | 1081 | } |
yabahiro | 31:45f97698857b | 1082 | if(g[2]!=98&&mtc2==true) { |
yabahiro | 31:45f97698857b | 1083 | switch(g[2]) { |
yabahiro | 29:c78a46f51209 | 1084 | case 0: |
yabahiro | 31:45f97698857b | 1085 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 1086 | break; |
yabahiro | 29:c78a46f51209 | 1087 | case 255: |
yabahiro | 31:45f97698857b | 1088 | motor[TIRE_FL].pwm += 5; |
yabahiro | 31:45f97698857b | 1089 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 1090 | break; |
yabahiro | 29:c78a46f51209 | 1091 | case 253: |
yabahiro | 31:45f97698857b | 1092 | motor[TIRE_FL].pwm += 10; |
yabahiro | 31:45f97698857b | 1093 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 1094 | break; |
yabahiro | 29:c78a46f51209 | 1095 | case 254: |
yabahiro | 31:45f97698857b | 1096 | motor[TIRE_FL].pwm += 20; |
yabahiro | 29:c78a46f51209 | 1097 | motor[TIRE_BL].pwm = 0; |
yabahiro | 31:45f97698857b | 1098 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 1099 | break; |
yabahiro | 29:c78a46f51209 | 1100 | case 1: |
yabahiro | 31:45f97698857b | 1101 | motor[TIRE_BL].pwm += 5; |
yabahiro | 31:45f97698857b | 1102 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 1103 | break; |
yabahiro | 29:c78a46f51209 | 1104 | case 3: |
yabahiro | 31:45f97698857b | 1105 | motor[TIRE_BL].pwm += 10; |
yabahiro | 31:45f97698857b | 1106 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 1107 | break; |
yabahiro | 29:c78a46f51209 | 1108 | case 2: |
yabahiro | 31:45f97698857b | 1109 | motor[TIRE_BL].pwm += 20; |
yabahiro | 29:c78a46f51209 | 1110 | motor[TIRE_FL].pwm = 0; |
yabahiro | 31:45f97698857b | 1111 | mtc2=false; |
yabahiro | 29:c78a46f51209 | 1112 | break; |
yabahiro | 29:c78a46f51209 | 1113 | } |
yabahiro | 31:45f97698857b | 1114 | } |
yabahiro | 31:45f97698857b | 1115 | } else if(mode==41) { |
yabahiro | 42:4f9689c0a349 | 1116 | if(LIF||LIB) { |
yabahiro | 42:4f9689c0a349 | 1117 | mode=42; |
yabahiro | 42:4f9689c0a349 | 1118 | } |
yabahiro | 31:45f97698857b | 1119 | motor[TIRE_FR].pwm = 0; |
yabahiro | 31:45f97698857b | 1120 | motor[TIRE_FR].dir = FREE; |
yabahiro | 35:94f026ab4d30 | 1121 | motor[TIRE_FL].pwm = 30; |
yabahiro | 31:45f97698857b | 1122 | motor[TIRE_FL].dir = BACK; |
yabahiro | 35:94f026ab4d30 | 1123 | motor[TIRE_BR].pwm = 30; |
yabahiro | 31:45f97698857b | 1124 | motor[TIRE_BR].dir = FOR; |
yabahiro | 31:45f97698857b | 1125 | motor[TIRE_BL].pwm = 0; |
yabahiro | 31:45f97698857b | 1126 | motor[TIRE_BL].dir = FREE; |
yabahiro | 35:94f026ab4d30 | 1127 | if(g[1]==0) { |
yabahiro | 31:45f97698857b | 1128 | count=0; |
yabahiro | 31:45f97698857b | 1129 | mode=70; |
yabahiro | 31:45f97698857b | 1130 | } |
yabahiro | 38:391a0c8e4c16 | 1131 | } else if(mode==42) { |
yabahiro | 38:391a0c8e4c16 | 1132 | motor[TIRE_FR].pwm = 20; |
yabahiro | 38:391a0c8e4c16 | 1133 | motor[TIRE_FR].dir = FOR; |
yabahiro | 38:391a0c8e4c16 | 1134 | motor[TIRE_FL].pwm = 0; |
yabahiro | 38:391a0c8e4c16 | 1135 | motor[TIRE_FL].dir = FREE; |
yabahiro | 38:391a0c8e4c16 | 1136 | motor[TIRE_BR].pwm = 0; |
yabahiro | 38:391a0c8e4c16 | 1137 | motor[TIRE_BR].dir = FREE; |
yabahiro | 38:391a0c8e4c16 | 1138 | motor[TIRE_BL].pwm = 20; |
yabahiro | 38:391a0c8e4c16 | 1139 | motor[TIRE_BL].dir = BACK; |
yabahiro | 38:391a0c8e4c16 | 1140 | if(g[1]==0) { |
yabahiro | 38:391a0c8e4c16 | 1141 | count=0; |
yabahiro | 38:391a0c8e4c16 | 1142 | mode=70; |
yabahiro | 38:391a0c8e4c16 | 1143 | } |
yabahiro | 31:45f97698857b | 1144 | } else if(mode==70) { |
yabahiro | 31:45f97698857b | 1145 | switch(g[1]) { |
yabahiro | 31:45f97698857b | 1146 | case 99: |
yabahiro | 31:45f97698857b | 1147 | if(count>=100000) { |
yabahiro | 31:45f97698857b | 1148 | mode=100; |
yabahiro | 29:c78a46f51209 | 1149 | } |
yabahiro | 31:45f97698857b | 1150 | break; |
yabahiro | 31:45f97698857b | 1151 | case 98: |
kishibekairohan | 33:656aa14904a5 | 1152 | motor[TIRE_FR].pwm = normal; |
yabahiro | 31:45f97698857b | 1153 | motor[TIRE_FR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 1154 | motor[TIRE_FL].pwm = normal; |
yabahiro | 31:45f97698857b | 1155 | motor[TIRE_FL].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 1156 | motor[TIRE_BR].pwm = normal; |
yabahiro | 31:45f97698857b | 1157 | motor[TIRE_BR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 1158 | motor[TIRE_BL].pwm = normal; |
yabahiro | 31:45f97698857b | 1159 | motor[TIRE_BL].dir = BACK; |
yabahiro | 31:45f97698857b | 1160 | break; |
yabahiro | 31:45f97698857b | 1161 | case 0: |
yabahiro | 38:391a0c8e4c16 | 1162 | motor[TIRE_FR].pwm = 80; |
yabahiro | 31:45f97698857b | 1163 | motor[TIRE_FR].dir = FOR; |
yabahiro | 38:391a0c8e4c16 | 1164 | motor[TIRE_FL].pwm = 80; |
yabahiro | 31:45f97698857b | 1165 | motor[TIRE_FL].dir = BACK; |
yabahiro | 38:391a0c8e4c16 | 1166 | motor[TIRE_BR].pwm = 80; |
yabahiro | 31:45f97698857b | 1167 | motor[TIRE_BR].dir = FOR; |
yabahiro | 38:391a0c8e4c16 | 1168 | motor[TIRE_BL].pwm = 80; |
yabahiro | 31:45f97698857b | 1169 | motor[TIRE_BL].dir = BACK; |
yabahiro | 31:45f97698857b | 1170 | mtc=true; |
yabahiro | 31:45f97698857b | 1171 | break; |
yabahiro | 31:45f97698857b | 1172 | case 255: |
kishibekairohan | 33:656aa14904a5 | 1173 | motor[TIRE_FR].pwm = fast; |
yabahiro | 31:45f97698857b | 1174 | motor[TIRE_FR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 1175 | motor[TIRE_FL].pwm = slow; |
yabahiro | 31:45f97698857b | 1176 | motor[TIRE_FL].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 1177 | motor[TIRE_BR].pwm = slow; |
yabahiro | 31:45f97698857b | 1178 | motor[TIRE_BR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 1179 | motor[TIRE_BL].pwm = fast; |
yabahiro | 31:45f97698857b | 1180 | motor[TIRE_BL].dir = BACK; |
yabahiro | 31:45f97698857b | 1181 | mtc=true; |
yabahiro | 31:45f97698857b | 1182 | break; |
yabahiro | 31:45f97698857b | 1183 | case 253: |
kishibekairohan | 33:656aa14904a5 | 1184 | motor[TIRE_FR].pwm = slow; |
yabahiro | 31:45f97698857b | 1185 | motor[TIRE_FR].dir = FOR; |
yabahiro | 31:45f97698857b | 1186 | motor[TIRE_FL].pwm = 0; |
yabahiro | 31:45f97698857b | 1187 | motor[TIRE_FL].dir = FREE; |
yabahiro | 31:45f97698857b | 1188 | motor[TIRE_BR].pwm = 0; |
yabahiro | 31:45f97698857b | 1189 | motor[TIRE_BR].dir = FREE; |
kishibekairohan | 33:656aa14904a5 | 1190 | motor[TIRE_BL].pwm = slow; |
yabahiro | 31:45f97698857b | 1191 | motor[TIRE_BL].dir = BACK; |
yabahiro | 31:45f97698857b | 1192 | mtc=true; |
yabahiro | 31:45f97698857b | 1193 | break; |
yabahiro | 31:45f97698857b | 1194 | case 254: |
kishibekairohan | 33:656aa14904a5 | 1195 | motor[TIRE_FR].pwm = normal; |
yabahiro | 31:45f97698857b | 1196 | motor[TIRE_FR].dir = FOR; |
yabahiro | 31:45f97698857b | 1197 | motor[TIRE_FL].pwm = 0; |
yabahiro | 31:45f97698857b | 1198 | motor[TIRE_FL].dir = FREE; |
yabahiro | 31:45f97698857b | 1199 | motor[TIRE_BR].pwm = 0; |
yabahiro | 31:45f97698857b | 1200 | motor[TIRE_BR].dir = FREE; |
kishibekairohan | 33:656aa14904a5 | 1201 | motor[TIRE_BL].pwm = normal; |
yabahiro | 31:45f97698857b | 1202 | motor[TIRE_BL].dir = BACK; |
yabahiro | 31:45f97698857b | 1203 | mtc=true; |
yabahiro | 31:45f97698857b | 1204 | break; |
yabahiro | 31:45f97698857b | 1205 | case 1: |
kishibekairohan | 33:656aa14904a5 | 1206 | motor[TIRE_FR].pwm = slow; |
yabahiro | 31:45f97698857b | 1207 | motor[TIRE_FR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 1208 | motor[TIRE_FL].pwm = fast; |
yabahiro | 31:45f97698857b | 1209 | motor[TIRE_FL].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 1210 | motor[TIRE_BR].pwm = fast; |
yabahiro | 31:45f97698857b | 1211 | motor[TIRE_BR].dir = FOR; |
kishibekairohan | 33:656aa14904a5 | 1212 | motor[TIRE_BL].pwm = slow; |
yabahiro | 31:45f97698857b | 1213 | motor[TIRE_BL].dir = BACK; |
yabahiro | 31:45f97698857b | 1214 | mtc=true; |
yabahiro | 31:45f97698857b | 1215 | break; |
yabahiro | 31:45f97698857b | 1216 | case 3: |
yabahiro | 31:45f97698857b | 1217 | motor[TIRE_FR].pwm = 0; |
yabahiro | 31:45f97698857b | 1218 | motor[TIRE_FR].dir = FREE; |
kishibekairohan | 33:656aa14904a5 | 1219 | motor[TIRE_FL].pwm = slow; |
yabahiro | 31:45f97698857b | 1220 | motor[TIRE_FL].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 1221 | motor[TIRE_BR].pwm = slow; |
yabahiro | 31:45f97698857b | 1222 | motor[TIRE_BR].dir = FOR; |
yabahiro | 31:45f97698857b | 1223 | motor[TIRE_BL].pwm = 0; |
yabahiro | 31:45f97698857b | 1224 | motor[TIRE_BL].dir = FREE; |
yabahiro | 31:45f97698857b | 1225 | mtc=true; |
yabahiro | 31:45f97698857b | 1226 | break; |
yabahiro | 31:45f97698857b | 1227 | case 2: |
yabahiro | 31:45f97698857b | 1228 | motor[TIRE_FR].pwm = 0; |
yabahiro | 31:45f97698857b | 1229 | motor[TIRE_FR].dir = FREE; |
kishibekairohan | 33:656aa14904a5 | 1230 | motor[TIRE_FL].pwm = normal; |
yabahiro | 31:45f97698857b | 1231 | motor[TIRE_FL].dir = BACK; |
kishibekairohan | 33:656aa14904a5 | 1232 | motor[TIRE_BR].pwm = normal; |
yabahiro | 31:45f97698857b | 1233 | motor[TIRE_BR].dir = FOR; |
yabahiro | 31:45f97698857b | 1234 | motor[TIRE_BL].pwm = 0; |
yabahiro | 31:45f97698857b | 1235 | motor[TIRE_BL].dir = FREE; |
yabahiro | 31:45f97698857b | 1236 | mtc=true; |
yabahiro | 31:45f97698857b | 1237 | break; |
yabahiro | 31:45f97698857b | 1238 | } |
yabahiro | 31:45f97698857b | 1239 | if(g[1]!=98&&mtc==true) { |
yabahiro | 31:45f97698857b | 1240 | switch(g[0]) { |
yabahiro | 29:c78a46f51209 | 1241 | case 0: |
yabahiro | 31:45f97698857b | 1242 | mtc=false; |
yabahiro | 29:c78a46f51209 | 1243 | break; |
yabahiro | 29:c78a46f51209 | 1244 | case 255: |
yabahiro | 31:45f97698857b | 1245 | motor[TIRE_FL].pwm += 5; |
yabahiro | 31:45f97698857b | 1246 | mtc=false; |
yabahiro | 29:c78a46f51209 | 1247 | break; |
yabahiro | 29:c78a46f51209 | 1248 | case 253: |
yabahiro | 31:45f97698857b | 1249 | motor[TIRE_FL].pwm += 10; |
yabahiro | 31:45f97698857b | 1250 | mtc=false; |
yabahiro | 29:c78a46f51209 | 1251 | break; |
yabahiro | 29:c78a46f51209 | 1252 | case 254: |
yabahiro | 31:45f97698857b | 1253 | motor[TIRE_FL].pwm += 20; |
yabahiro | 31:45f97698857b | 1254 | motor[TIRE_FR].pwm = 0; |
yabahiro | 31:45f97698857b | 1255 | mtc=false; |
yabahiro | 29:c78a46f51209 | 1256 | break; |
yabahiro | 29:c78a46f51209 | 1257 | case 1: |
yabahiro | 31:45f97698857b | 1258 | motor[TIRE_FR].pwm += 5; |
yabahiro | 31:45f97698857b | 1259 | mtc=false; |
yabahiro | 29:c78a46f51209 | 1260 | break; |
yabahiro | 29:c78a46f51209 | 1261 | case 3: |
yabahiro | 31:45f97698857b | 1262 | motor[TIRE_FR].pwm += 10; |
yabahiro | 31:45f97698857b | 1263 | mtc=false; |
yabahiro | 29:c78a46f51209 | 1264 | break; |
yabahiro | 29:c78a46f51209 | 1265 | case 2: |
yabahiro | 31:45f97698857b | 1266 | motor[TIRE_FR].pwm += 20; |
yabahiro | 31:45f97698857b | 1267 | motor[TIRE_FL].pwm = 0; |
yabahiro | 31:45f97698857b | 1268 | mtc=false; |
yabahiro | 29:c78a46f51209 | 1269 | break; |
yabahiro | 29:c78a46f51209 | 1270 | } |
yabahiro | 31:45f97698857b | 1271 | } |
yabahiro | 31:45f97698857b | 1272 | } else if(mode==100) { |
yabahiro | 35:94f026ab4d30 | 1273 | motor[TIRE_FR].pwm = 20; |
yabahiro | 31:45f97698857b | 1274 | motor[TIRE_FR].dir = FOR; |
yabahiro | 35:94f026ab4d30 | 1275 | motor[TIRE_FL].pwm = 20; |
yabahiro | 31:45f97698857b | 1276 | motor[TIRE_FL].dir = BACK; |
yabahiro | 31:45f97698857b | 1277 | motor[TIRE_BR].pwm = 23; |
yabahiro | 31:45f97698857b | 1278 | motor[TIRE_BR].dir = FOR; |
yabahiro | 35:94f026ab4d30 | 1279 | motor[TIRE_BL].pwm = 20; |
yabahiro | 31:45f97698857b | 1280 | motor[TIRE_BL].dir = BACK; |
yabahiro | 31:45f97698857b | 1281 | } else { |
yabahiro | 31:45f97698857b | 1282 | } |
yabahiro | 31:45f97698857b | 1283 | } |
yabahiro | 31:45f97698857b | 1284 | #endif |
yabahiro | 31:45f97698857b | 1285 | |
yabahiro | 31:45f97698857b | 1286 | #if USE_PROCESS_NUM>3 |
yabahiro | 31:45f97698857b | 1287 | static void Process3() |
yabahiro | 31:45f97698857b | 1288 | { |
yabahiro | 36:788274604650 | 1289 | } |
yabahiro | 36:788274604650 | 1290 | #endif |
yabahiro | 36:788274604650 | 1291 | |
yabahiro | 36:788274604650 | 1292 | #if USE_PROCESS_NUM>4 |
yabahiro | 36:788274604650 | 1293 | static void Process4() |
yabahiro | 36:788274604650 | 1294 | { |
yabahiro | 36:788274604650 | 1295 | LedMode(4); |
yabahiro | 36:788274604650 | 1296 | count++; |
yabahiro | 31:45f97698857b | 1297 | if(mode==1) {//スタートゾーンから白線検知 |
yabahiro | 45:878f8f385635 | 1298 | fast=40; |
yabahiro | 40:7f93984e8ba1 | 1299 | normal=30; |
yabahiro | 40:7f93984e8ba1 | 1300 | slow=20; |
yabahiro | 45:878f8f385635 | 1301 | motor[TIRE_FR].pwm = 27; |
yabahiro | 40:7f93984e8ba1 | 1302 | motor[TIRE_FR].dir = FOR; |
yabahiro | 45:878f8f385635 | 1303 | motor[TIRE_FL].pwm = 33; |
yabahiro | 40:7f93984e8ba1 | 1304 | motor[TIRE_FL].dir = BACK; |
yabahiro | 45:878f8f385635 | 1305 | motor[TIRE_BR].pwm = 33; |
yabahiro | 40:7f93984e8ba1 | 1306 | motor[TIRE_BR].dir = FOR; |
yabahiro | 45:878f8f385635 | 1307 | motor[TIRE_BL].pwm = 27; |
yabahiro | 40:7f93984e8ba1 | 1308 | motor[TIRE_BL].dir = BACK; |
yabahiro | 47:b6e5a6bfe7ab | 1309 | //スタート後どれくらい無検知でうごくか↓ |
yabahiro | 46:4a8bca4cc1fd | 1310 | if(g[2]==0&&count>=100000) { |
yabahiro | 40:7f93984e8ba1 | 1311 | count=100000; |
yabahiro | 40:7f93984e8ba1 | 1312 | cross=0; |
yabahiro | 40:7f93984e8ba1 | 1313 | mode=3; |
yabahiro | 40:7f93984e8ba1 | 1314 | } |
yabahiro | 40:7f93984e8ba1 | 1315 | } else if(mode==3) { //横ライントレースから縦ライントレースへ |
yabahiro | 43:677f7446612e | 1316 | motor[TIRE_FR].pwm = 30; |
yabahiro | 40:7f93984e8ba1 | 1317 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1318 | motor[TIRE_FL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1319 | motor[TIRE_FL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1320 | motor[TIRE_BR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1321 | motor[TIRE_BR].dir = FREE; |
yabahiro | 43:677f7446612e | 1322 | motor[TIRE_BL].pwm = 30; |
yabahiro | 40:7f93984e8ba1 | 1323 | motor[TIRE_BL].dir = BACK; |
yabahiro | 45:878f8f385635 | 1324 | if(g[1]==0) { |
yabahiro | 40:7f93984e8ba1 | 1325 | mode=10; |
yabahiro | 40:7f93984e8ba1 | 1326 | count=100000; |
yabahiro | 40:7f93984e8ba1 | 1327 | } |
yabahiro | 40:7f93984e8ba1 | 1328 | } else if(mode==10) { //縦ライントレース |
yabahiro | 40:7f93984e8ba1 | 1329 | |
yabahiro | 40:7f93984e8ba1 | 1330 | if(counts==false&&g[2]==0) { |
yabahiro | 40:7f93984e8ba1 | 1331 | cros++; |
yabahiro | 40:7f93984e8ba1 | 1332 | counts=true; |
yabahiro | 40:7f93984e8ba1 | 1333 | } |
yabahiro | 40:7f93984e8ba1 | 1334 | if(counts==true&&g[2]==99) { |
yabahiro | 40:7f93984e8ba1 | 1335 | counts=false; |
yabahiro | 40:7f93984e8ba1 | 1336 | } |
yabahiro | 40:7f93984e8ba1 | 1337 | |
yabahiro | 40:7f93984e8ba1 | 1338 | if(cros==Twsh) { |
yabahiro | 40:7f93984e8ba1 | 1339 | mode=11; |
yabahiro | 40:7f93984e8ba1 | 1340 | count=0; |
yabahiro | 40:7f93984e8ba1 | 1341 | cros=0; |
yabahiro | 40:7f93984e8ba1 | 1342 | }//ゆっくりモードに入れなかった時の保険 |
yabahiro | 40:7f93984e8ba1 | 1343 | switch(g[1]) { |
yabahiro | 40:7f93984e8ba1 | 1344 | case 98: |
yabahiro | 40:7f93984e8ba1 | 1345 | motor[TIRE_FR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1346 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1347 | motor[TIRE_FL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1348 | motor[TIRE_FL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1349 | motor[TIRE_BR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1350 | motor[TIRE_BR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1351 | motor[TIRE_BL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1352 | motor[TIRE_BL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1353 | mtc=true; |
yabahiro | 47:b6e5a6bfe7ab | 1354 | if(count>100000) { |
yabahiro | 40:7f93984e8ba1 | 1355 | cross++; |
yabahiro | 40:7f93984e8ba1 | 1356 | count=0; |
yabahiro | 40:7f93984e8ba1 | 1357 | } |
yabahiro | 40:7f93984e8ba1 | 1358 | if(cross==Twsh) { |
yabahiro | 40:7f93984e8ba1 | 1359 | mode=11; |
yabahiro | 40:7f93984e8ba1 | 1360 | count=0; |
yabahiro | 40:7f93984e8ba1 | 1361 | cross=0; |
yabahiro | 40:7f93984e8ba1 | 1362 | } |
yabahiro | 40:7f93984e8ba1 | 1363 | break; |
yabahiro | 40:7f93984e8ba1 | 1364 | case 0: |
yabahiro | 40:7f93984e8ba1 | 1365 | motor[TIRE_FR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1366 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1367 | motor[TIRE_FL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1368 | motor[TIRE_FL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1369 | motor[TIRE_BR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1370 | motor[TIRE_BR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1371 | motor[TIRE_BL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1372 | motor[TIRE_BL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1373 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 1374 | break; |
yabahiro | 40:7f93984e8ba1 | 1375 | case 255: |
yabahiro | 40:7f93984e8ba1 | 1376 | motor[TIRE_FR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1377 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1378 | motor[TIRE_FL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1379 | motor[TIRE_FL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1380 | motor[TIRE_BR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1381 | motor[TIRE_BR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1382 | motor[TIRE_BL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1383 | motor[TIRE_BL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1384 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 1385 | break; |
yabahiro | 40:7f93984e8ba1 | 1386 | case 253: |
yabahiro | 40:7f93984e8ba1 | 1387 | motor[TIRE_FR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1388 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1389 | motor[TIRE_FL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1390 | motor[TIRE_FL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1391 | motor[TIRE_BR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1392 | motor[TIRE_BR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1393 | motor[TIRE_BL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1394 | motor[TIRE_BL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1395 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 1396 | break; |
yabahiro | 40:7f93984e8ba1 | 1397 | case 254: |
yabahiro | 40:7f93984e8ba1 | 1398 | motor[TIRE_FR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1399 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1400 | motor[TIRE_FL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1401 | motor[TIRE_FL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1402 | motor[TIRE_BR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1403 | motor[TIRE_BR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1404 | motor[TIRE_BL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1405 | motor[TIRE_BL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1406 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 1407 | break; |
yabahiro | 40:7f93984e8ba1 | 1408 | case 1: |
yabahiro | 40:7f93984e8ba1 | 1409 | motor[TIRE_FR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1410 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1411 | motor[TIRE_FL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1412 | motor[TIRE_FL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1413 | motor[TIRE_BR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1414 | motor[TIRE_BR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1415 | motor[TIRE_BL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1416 | motor[TIRE_BL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1417 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 1418 | break; |
yabahiro | 40:7f93984e8ba1 | 1419 | case 3: |
yabahiro | 40:7f93984e8ba1 | 1420 | motor[TIRE_FR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1421 | motor[TIRE_FR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1422 | motor[TIRE_FL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1423 | motor[TIRE_FL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1424 | motor[TIRE_BR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1425 | motor[TIRE_BR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1426 | motor[TIRE_BL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1427 | motor[TIRE_BL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1428 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 1429 | break; |
yabahiro | 40:7f93984e8ba1 | 1430 | case 2: |
yabahiro | 40:7f93984e8ba1 | 1431 | motor[TIRE_FR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1432 | motor[TIRE_FR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1433 | motor[TIRE_FL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1434 | motor[TIRE_FL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1435 | motor[TIRE_BR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1436 | motor[TIRE_BR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1437 | motor[TIRE_BL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1438 | motor[TIRE_BL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1439 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 1440 | break; |
yabahiro | 40:7f93984e8ba1 | 1441 | } |
yabahiro | 40:7f93984e8ba1 | 1442 | if(g[0]!=98&&mtc==true) { |
yabahiro | 40:7f93984e8ba1 | 1443 | switch(g[0]) { |
yabahiro | 40:7f93984e8ba1 | 1444 | case 0: |
yabahiro | 40:7f93984e8ba1 | 1445 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 1446 | break; |
yabahiro | 40:7f93984e8ba1 | 1447 | case 255: |
yabahiro | 40:7f93984e8ba1 | 1448 | motor[TIRE_FL].pwm += 5; |
yabahiro | 40:7f93984e8ba1 | 1449 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 1450 | break; |
yabahiro | 40:7f93984e8ba1 | 1451 | case 253: |
yabahiro | 40:7f93984e8ba1 | 1452 | motor[TIRE_FL].pwm += 10; |
yabahiro | 40:7f93984e8ba1 | 1453 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 1454 | break; |
yabahiro | 40:7f93984e8ba1 | 1455 | case 254: |
yabahiro | 40:7f93984e8ba1 | 1456 | motor[TIRE_FL].pwm += 20; |
yabahiro | 40:7f93984e8ba1 | 1457 | motor[TIRE_FR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1458 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 1459 | break; |
yabahiro | 40:7f93984e8ba1 | 1460 | case 1: |
yabahiro | 40:7f93984e8ba1 | 1461 | motor[TIRE_FR].pwm += 5; |
yabahiro | 40:7f93984e8ba1 | 1462 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 1463 | break; |
yabahiro | 40:7f93984e8ba1 | 1464 | case 3: |
yabahiro | 40:7f93984e8ba1 | 1465 | motor[TIRE_FR].pwm += 10; |
yabahiro | 40:7f93984e8ba1 | 1466 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 1467 | break; |
yabahiro | 40:7f93984e8ba1 | 1468 | case 2: |
yabahiro | 40:7f93984e8ba1 | 1469 | motor[TIRE_FR].pwm += 20; |
yabahiro | 40:7f93984e8ba1 | 1470 | motor[TIRE_FL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1471 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 1472 | break; |
yabahiro | 40:7f93984e8ba1 | 1473 | } |
yabahiro | 40:7f93984e8ba1 | 1474 | } |
yabahiro | 40:7f93984e8ba1 | 1475 | } else if(mode==11) { |
yabahiro | 40:7f93984e8ba1 | 1476 | motor[TIRE_FR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1477 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1478 | motor[TIRE_FL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1479 | motor[TIRE_FL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1480 | motor[TIRE_BR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1481 | motor[TIRE_BR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1482 | motor[TIRE_BL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1483 | motor[TIRE_BL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1484 | if(g[2]==0) { |
yabahiro | 40:7f93984e8ba1 | 1485 | count=0; |
yabahiro | 40:7f93984e8ba1 | 1486 | cross=0; |
yabahiro | 40:7f93984e8ba1 | 1487 | mode=20; |
yabahiro | 40:7f93984e8ba1 | 1488 | } |
yabahiro | 40:7f93984e8ba1 | 1489 | } else if(mode==20) { |
yabahiro | 40:7f93984e8ba1 | 1490 | |
yabahiro | 40:7f93984e8ba1 | 1491 | if(Twsh==2) { |
yabahiro | 40:7f93984e8ba1 | 1492 | solenoid.solenoid2 = SOLENOID_ON; |
yabahiro | 40:7f93984e8ba1 | 1493 | } |
yabahiro | 40:7f93984e8ba1 | 1494 | |
yabahiro | 40:7f93984e8ba1 | 1495 | if(counts==false&&g[1]==0) { |
yabahiro | 40:7f93984e8ba1 | 1496 | cros++; |
yabahiro | 40:7f93984e8ba1 | 1497 | counts=true; |
yabahiro | 40:7f93984e8ba1 | 1498 | } |
yabahiro | 40:7f93984e8ba1 | 1499 | if(counts==true&&g[1]==99) { |
yabahiro | 40:7f93984e8ba1 | 1500 | counts=false; |
yabahiro | 40:7f93984e8ba1 | 1501 | } |
yabahiro | 40:7f93984e8ba1 | 1502 | |
yabahiro | 40:7f93984e8ba1 | 1503 | if(cros==2) { |
yabahiro | 40:7f93984e8ba1 | 1504 | //mode=21; |
yabahiro | 40:7f93984e8ba1 | 1505 | //count=0; |
yabahiro | 40:7f93984e8ba1 | 1506 | //cros=0; |
yabahiro | 40:7f93984e8ba1 | 1507 | }//ゆっくりモードに入れなかった時の保険 |
yabahiro | 45:878f8f385635 | 1508 | if(g[1]==0) { |
yabahiro | 45:878f8f385635 | 1509 | fast=35; |
yabahiro | 45:878f8f385635 | 1510 | normal=20; |
yabahiro | 45:878f8f385635 | 1511 | slow=15; |
yabahiro | 45:878f8f385635 | 1512 | } |
yabahiro | 40:7f93984e8ba1 | 1513 | switch(g[2]) { |
yabahiro | 40:7f93984e8ba1 | 1514 | case 98: |
yabahiro | 40:7f93984e8ba1 | 1515 | motor[TIRE_FR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1516 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1517 | motor[TIRE_FL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1518 | motor[TIRE_FL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1519 | motor[TIRE_BR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1520 | motor[TIRE_BR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1521 | motor[TIRE_BL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1522 | motor[TIRE_BL].dir = BACK; |
yabahiro | 41:e1dd6d97f17d | 1523 | if(count>50000) { |
yabahiro | 40:7f93984e8ba1 | 1524 | cross++; |
yabahiro | 40:7f93984e8ba1 | 1525 | count=0; |
yabahiro | 40:7f93984e8ba1 | 1526 | } |
yabahiro | 40:7f93984e8ba1 | 1527 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1528 | if(cross==2) { |
yabahiro | 45:878f8f385635 | 1529 | mode=22; |
yabahiro | 40:7f93984e8ba1 | 1530 | cross=0; |
yabahiro | 41:e1dd6d97f17d | 1531 | count=0; |
yabahiro | 45:878f8f385635 | 1532 | fast=40; |
yabahiro | 45:878f8f385635 | 1533 | normal=30; |
yabahiro | 45:878f8f385635 | 1534 | slow=20; |
yabahiro | 40:7f93984e8ba1 | 1535 | } |
yabahiro | 40:7f93984e8ba1 | 1536 | break; |
yabahiro | 40:7f93984e8ba1 | 1537 | case 0: |
yabahiro | 40:7f93984e8ba1 | 1538 | motor[TIRE_FR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1539 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1540 | motor[TIRE_FL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1541 | motor[TIRE_FL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1542 | motor[TIRE_BR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1543 | motor[TIRE_BR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1544 | motor[TIRE_BL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1545 | motor[TIRE_BL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1546 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1547 | break; |
yabahiro | 40:7f93984e8ba1 | 1548 | case 255: |
yabahiro | 40:7f93984e8ba1 | 1549 | motor[TIRE_FR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1550 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1551 | motor[TIRE_FL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1552 | motor[TIRE_FL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1553 | motor[TIRE_BR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1554 | motor[TIRE_BR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1555 | motor[TIRE_BL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1556 | motor[TIRE_BL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1557 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1558 | break; |
yabahiro | 40:7f93984e8ba1 | 1559 | case 253: |
yabahiro | 40:7f93984e8ba1 | 1560 | motor[TIRE_FR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1561 | motor[TIRE_FR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1562 | motor[TIRE_FL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1563 | motor[TIRE_FL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1564 | motor[TIRE_BR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1565 | motor[TIRE_BR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1566 | motor[TIRE_BL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1567 | motor[TIRE_BL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1568 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1569 | break; |
yabahiro | 40:7f93984e8ba1 | 1570 | case 254: |
yabahiro | 40:7f93984e8ba1 | 1571 | motor[TIRE_FR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1572 | motor[TIRE_FR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1573 | motor[TIRE_FL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1574 | motor[TIRE_FL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1575 | motor[TIRE_BR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1576 | motor[TIRE_BR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1577 | motor[TIRE_BL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1578 | motor[TIRE_BL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1579 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1580 | break; |
yabahiro | 40:7f93984e8ba1 | 1581 | case 1: |
yabahiro | 40:7f93984e8ba1 | 1582 | motor[TIRE_FR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1583 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1584 | motor[TIRE_FL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1585 | motor[TIRE_FL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1586 | motor[TIRE_BR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1587 | motor[TIRE_BR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1588 | motor[TIRE_BL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1589 | motor[TIRE_BL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1590 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1591 | break; |
yabahiro | 40:7f93984e8ba1 | 1592 | case 3: |
yabahiro | 40:7f93984e8ba1 | 1593 | motor[TIRE_FR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1594 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1595 | motor[TIRE_FL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1596 | motor[TIRE_FL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1597 | motor[TIRE_BR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1598 | motor[TIRE_BR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1599 | motor[TIRE_BL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1600 | motor[TIRE_BL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1601 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1602 | break; |
yabahiro | 40:7f93984e8ba1 | 1603 | case 2: |
yabahiro | 40:7f93984e8ba1 | 1604 | motor[TIRE_FR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1605 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1606 | motor[TIRE_FL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1607 | motor[TIRE_FL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1608 | motor[TIRE_BR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1609 | motor[TIRE_BR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1610 | motor[TIRE_BL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1611 | motor[TIRE_BL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1612 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1613 | break; |
yabahiro | 40:7f93984e8ba1 | 1614 | } |
yabahiro | 40:7f93984e8ba1 | 1615 | if(g[2]!=98&&mtc2==true) { |
yabahiro | 40:7f93984e8ba1 | 1616 | switch(g[3]) { |
yabahiro | 40:7f93984e8ba1 | 1617 | case 0: |
yabahiro | 40:7f93984e8ba1 | 1618 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1619 | break; |
yabahiro | 40:7f93984e8ba1 | 1620 | case 255: |
yabahiro | 40:7f93984e8ba1 | 1621 | motor[TIRE_BL].pwm += 5; |
yabahiro | 40:7f93984e8ba1 | 1622 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1623 | break; |
yabahiro | 40:7f93984e8ba1 | 1624 | case 253: |
yabahiro | 40:7f93984e8ba1 | 1625 | motor[TIRE_BL].pwm += 10; |
yabahiro | 40:7f93984e8ba1 | 1626 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1627 | break; |
yabahiro | 40:7f93984e8ba1 | 1628 | case 254: |
yabahiro | 40:7f93984e8ba1 | 1629 | motor[TIRE_BL].pwm += 20; |
yabahiro | 40:7f93984e8ba1 | 1630 | motor[TIRE_FL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1631 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1632 | break; |
yabahiro | 40:7f93984e8ba1 | 1633 | case 1: |
yabahiro | 40:7f93984e8ba1 | 1634 | motor[TIRE_FL].pwm += 5; |
yabahiro | 40:7f93984e8ba1 | 1635 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1636 | break; |
yabahiro | 40:7f93984e8ba1 | 1637 | case 3: |
yabahiro | 40:7f93984e8ba1 | 1638 | motor[TIRE_FL].pwm += 10; |
yabahiro | 40:7f93984e8ba1 | 1639 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1640 | break; |
yabahiro | 40:7f93984e8ba1 | 1641 | case 2: |
yabahiro | 40:7f93984e8ba1 | 1642 | motor[TIRE_FL].pwm += 20; |
yabahiro | 40:7f93984e8ba1 | 1643 | motor[TIRE_BL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1644 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1645 | break; |
yabahiro | 40:7f93984e8ba1 | 1646 | } |
yabahiro | 40:7f93984e8ba1 | 1647 | } |
yabahiro | 42:4f9689c0a349 | 1648 | |
yabahiro | 40:7f93984e8ba1 | 1649 | } else if(mode==21) { |
yabahiro | 45:878f8f385635 | 1650 | motor[TIRE_FR].pwm = 30; |
yabahiro | 41:e1dd6d97f17d | 1651 | motor[TIRE_FR].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1652 | motor[TIRE_FL].pwm = 30; |
yabahiro | 41:e1dd6d97f17d | 1653 | motor[TIRE_FL].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1654 | motor[TIRE_BR].pwm = 30; |
yabahiro | 41:e1dd6d97f17d | 1655 | motor[TIRE_BR].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1656 | motor[TIRE_BL].pwm = 30; |
yabahiro | 41:e1dd6d97f17d | 1657 | motor[TIRE_BL].dir = BRAKE; |
yabahiro | 41:e1dd6d97f17d | 1658 | if(count<=100000) { |
yabahiro | 41:e1dd6d97f17d | 1659 | mode=22; |
yabahiro | 41:e1dd6d97f17d | 1660 | } |
yabahiro | 42:4f9689c0a349 | 1661 | } |
yabahiro | 45:878f8f385635 | 1662 | kiri=true; |
yabahiro | 45:878f8f385635 | 1663 | if(kiri) { |
yabahiro | 42:4f9689c0a349 | 1664 | if(mode==22) { |
yabahiro | 45:878f8f385635 | 1665 | motor[TIRE_FR].pwm = 100; |
yabahiro | 45:878f8f385635 | 1666 | motor[TIRE_FR].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1667 | motor[TIRE_FL].pwm = 100; |
yabahiro | 45:878f8f385635 | 1668 | motor[TIRE_FL].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1669 | motor[TIRE_BR].pwm = 100; |
yabahiro | 45:878f8f385635 | 1670 | motor[TIRE_BR].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1671 | motor[TIRE_BL].pwm = 100; |
yabahiro | 45:878f8f385635 | 1672 | motor[TIRE_BL].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1673 | if(count>=10000) { |
yabahiro | 45:878f8f385635 | 1674 | mode=23; |
yabahiro | 45:878f8f385635 | 1675 | } |
yabahiro | 45:878f8f385635 | 1676 | } else if(mode==23) { |
yabahiro | 45:878f8f385635 | 1677 | motor[TIRE_FR].pwm = 20; |
yabahiro | 45:878f8f385635 | 1678 | motor[TIRE_FR].dir = BACK; |
yabahiro | 45:878f8f385635 | 1679 | motor[TIRE_FL].pwm = 20; |
yabahiro | 45:878f8f385635 | 1680 | motor[TIRE_FL].dir = BACK; |
yabahiro | 45:878f8f385635 | 1681 | motor[TIRE_BR].pwm = 20; |
yabahiro | 45:878f8f385635 | 1682 | motor[TIRE_BR].dir = FOR; |
yabahiro | 45:878f8f385635 | 1683 | motor[TIRE_BL].pwm = 20; |
yabahiro | 45:878f8f385635 | 1684 | motor[TIRE_BL].dir = FOR; |
yabahiro | 45:878f8f385635 | 1685 | if(g[2]==98) { |
yabahiro | 45:878f8f385635 | 1686 | mode=24; |
yabahiro | 45:878f8f385635 | 1687 | count=0; |
yabahiro | 45:878f8f385635 | 1688 | } |
yabahiro | 45:878f8f385635 | 1689 | } else if(mode==24) { |
yabahiro | 42:4f9689c0a349 | 1690 | motor[TIRE_FR].pwm = 20; |
yabahiro | 42:4f9689c0a349 | 1691 | motor[TIRE_FR].dir = BACK; |
yabahiro | 42:4f9689c0a349 | 1692 | motor[TIRE_FL].pwm = 20; |
yabahiro | 42:4f9689c0a349 | 1693 | motor[TIRE_FL].dir = BACK; |
yabahiro | 42:4f9689c0a349 | 1694 | motor[TIRE_BR].pwm = 20; |
yabahiro | 42:4f9689c0a349 | 1695 | motor[TIRE_BR].dir = FOR; |
yabahiro | 42:4f9689c0a349 | 1696 | motor[TIRE_BL].pwm = 20; |
yabahiro | 42:4f9689c0a349 | 1697 | motor[TIRE_BL].dir = FOR; |
yabahiro | 42:4f9689c0a349 | 1698 | if(g[2]!=98) { |
yabahiro | 45:878f8f385635 | 1699 | count=0; |
yabahiro | 45:878f8f385635 | 1700 | mode=25; |
yabahiro | 45:878f8f385635 | 1701 | } |
yabahiro | 45:878f8f385635 | 1702 | } else if(mode==25) { |
yabahiro | 45:878f8f385635 | 1703 | motor[TIRE_FR].pwm = 10; |
yabahiro | 45:878f8f385635 | 1704 | motor[TIRE_FR].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1705 | motor[TIRE_FL].pwm = 10; |
yabahiro | 45:878f8f385635 | 1706 | motor[TIRE_FL].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1707 | motor[TIRE_BR].pwm = 10; |
yabahiro | 45:878f8f385635 | 1708 | motor[TIRE_BR].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1709 | motor[TIRE_BL].pwm = 10; |
yabahiro | 45:878f8f385635 | 1710 | motor[TIRE_BL].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1711 | if(count>=10000) { |
yabahiro | 45:878f8f385635 | 1712 | mode=26; |
yabahiro | 45:878f8f385635 | 1713 | count=0; |
yabahiro | 42:4f9689c0a349 | 1714 | } |
yabahiro | 45:878f8f385635 | 1715 | } else if(mode==26) { |
yabahiro | 45:878f8f385635 | 1716 | motor[TIRE_FR].pwm = 20; |
yabahiro | 45:878f8f385635 | 1717 | motor[TIRE_FR].dir = FOR; |
yabahiro | 45:878f8f385635 | 1718 | motor[TIRE_FL].pwm = 20; |
yabahiro | 45:878f8f385635 | 1719 | motor[TIRE_FL].dir = FOR; |
yabahiro | 45:878f8f385635 | 1720 | motor[TIRE_BR].pwm = 20; |
yabahiro | 45:878f8f385635 | 1721 | motor[TIRE_BR].dir = BACK; |
yabahiro | 45:878f8f385635 | 1722 | motor[TIRE_BL].pwm = 20; |
yabahiro | 45:878f8f385635 | 1723 | motor[TIRE_BL].dir = BACK; |
yabahiro | 45:878f8f385635 | 1724 | if(count>=5000) { |
yabahiro | 45:878f8f385635 | 1725 | mode=27; |
yabahiro | 45:878f8f385635 | 1726 | count=0; |
yabahiro | 45:878f8f385635 | 1727 | } |
yabahiro | 45:878f8f385635 | 1728 | } else if(mode==27) { |
yabahiro | 45:878f8f385635 | 1729 | motor[TIRE_FR].pwm = 20; |
yabahiro | 45:878f8f385635 | 1730 | motor[TIRE_FR].dir = FOR; |
yabahiro | 45:878f8f385635 | 1731 | motor[TIRE_FL].pwm = 20; |
yabahiro | 45:878f8f385635 | 1732 | motor[TIRE_FL].dir = FOR; |
yabahiro | 45:878f8f385635 | 1733 | motor[TIRE_BR].pwm = 20; |
yabahiro | 45:878f8f385635 | 1734 | motor[TIRE_BR].dir = FOR; |
yabahiro | 45:878f8f385635 | 1735 | motor[TIRE_BL].pwm = 20; |
yabahiro | 45:878f8f385635 | 1736 | motor[TIRE_BL].dir = FOR; |
yabahiro | 45:878f8f385635 | 1737 | //どれくらい回転するかって値 |
yabahiro | 45:878f8f385635 | 1738 | if(count>=4000) { |
yabahiro | 45:878f8f385635 | 1739 | count=0; |
yabahiro | 45:878f8f385635 | 1740 | mode=28; |
yabahiro | 45:878f8f385635 | 1741 | } |
yabahiro | 45:878f8f385635 | 1742 | } else if(mode==28) { |
yabahiro | 45:878f8f385635 | 1743 | motor[TIRE_FR].pwm = 10; |
yabahiro | 45:878f8f385635 | 1744 | motor[TIRE_FR].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1745 | motor[TIRE_FL].pwm = 10; |
yabahiro | 45:878f8f385635 | 1746 | motor[TIRE_FL].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1747 | motor[TIRE_BR].pwm = 10; |
yabahiro | 45:878f8f385635 | 1748 | motor[TIRE_BR].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1749 | motor[TIRE_BL].pwm = 10; |
yabahiro | 45:878f8f385635 | 1750 | motor[TIRE_BL].dir = BRAKE; |
yabahiro | 45:878f8f385635 | 1751 | if(count>=10000) { |
yabahiro | 45:878f8f385635 | 1752 | mode=30; |
yabahiro | 45:878f8f385635 | 1753 | count=0; |
yabahiro | 45:878f8f385635 | 1754 | } |
yabahiro | 43:677f7446612e | 1755 | } |
yabahiro | 42:4f9689c0a349 | 1756 | } else { |
yabahiro | 42:4f9689c0a349 | 1757 | if(mode==22) { |
yabahiro | 45:878f8f385635 | 1758 | motor[TIRE_FR].pwm = 0; |
yabahiro | 45:878f8f385635 | 1759 | motor[TIRE_FR].dir = FREE; |
yabahiro | 45:878f8f385635 | 1760 | motor[TIRE_FL].pwm = 25; |
yabahiro | 45:878f8f385635 | 1761 | motor[TIRE_FL].dir = FOR; |
yabahiro | 45:878f8f385635 | 1762 | motor[TIRE_BR].pwm = 25; |
yabahiro | 45:878f8f385635 | 1763 | motor[TIRE_BR].dir = BACK; |
yabahiro | 45:878f8f385635 | 1764 | motor[TIRE_BL].pwm = 0; |
yabahiro | 45:878f8f385635 | 1765 | motor[TIRE_BL].dir = FREE; |
yabahiro | 45:878f8f385635 | 1766 | if(g[0]==0&&count>=10000) { |
yabahiro | 45:878f8f385635 | 1767 | mode=30; |
yabahiro | 42:4f9689c0a349 | 1768 | count=0; |
yabahiro | 45:878f8f385635 | 1769 | cros=0; |
yabahiro | 42:4f9689c0a349 | 1770 | } |
yabahiro | 42:4f9689c0a349 | 1771 | } |
yabahiro | 42:4f9689c0a349 | 1772 | } |
yabahiro | 42:4f9689c0a349 | 1773 | if(mode==30) { |
yabahiro | 43:677f7446612e | 1774 | motor[TIRE_FR].pwm = 60; |
yabahiro | 40:7f93984e8ba1 | 1775 | motor[TIRE_FR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1776 | motor[TIRE_FL].pwm = 60; |
yabahiro | 40:7f93984e8ba1 | 1777 | motor[TIRE_FL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1778 | motor[TIRE_BR].pwm = 60; |
yabahiro | 40:7f93984e8ba1 | 1779 | motor[TIRE_BR].dir = FOR; |
yabahiro | 45:878f8f385635 | 1780 | motor[TIRE_BL].pwm = 57; |
yabahiro | 40:7f93984e8ba1 | 1781 | motor[TIRE_BL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1782 | if(g[1]==98) { |
yabahiro | 40:7f93984e8ba1 | 1783 | mode=31; |
yabahiro | 41:e1dd6d97f17d | 1784 | count=0; |
yabahiro | 40:7f93984e8ba1 | 1785 | } |
yabahiro | 40:7f93984e8ba1 | 1786 | } else if(mode==31) { |
yabahiro | 42:4f9689c0a349 | 1787 | motor[TIRE_FR].pwm = 0; |
yabahiro | 41:e1dd6d97f17d | 1788 | motor[TIRE_FR].dir = FREE; |
yabahiro | 42:4f9689c0a349 | 1789 | motor[TIRE_FL].pwm = 0; |
yabahiro | 41:e1dd6d97f17d | 1790 | motor[TIRE_FL].dir = FREE; |
yabahiro | 42:4f9689c0a349 | 1791 | motor[TIRE_BR].pwm = 0; |
yabahiro | 41:e1dd6d97f17d | 1792 | motor[TIRE_BR].dir = FREE; |
yabahiro | 42:4f9689c0a349 | 1793 | motor[TIRE_BL].pwm = 0; |
yabahiro | 41:e1dd6d97f17d | 1794 | motor[TIRE_BL].dir = FREE; |
yabahiro | 42:4f9689c0a349 | 1795 | if(count>=5000) { |
yabahiro | 41:e1dd6d97f17d | 1796 | mode=32; |
yabahiro | 40:7f93984e8ba1 | 1797 | count=0; |
yabahiro | 40:7f93984e8ba1 | 1798 | } |
yabahiro | 40:7f93984e8ba1 | 1799 | } else if(mode==32) { |
yabahiro | 42:4f9689c0a349 | 1800 | motor[TIRE_FR].pwm = 10; |
yabahiro | 41:e1dd6d97f17d | 1801 | motor[TIRE_FR].dir = BRAKE; |
yabahiro | 42:4f9689c0a349 | 1802 | motor[TIRE_FL].pwm = 10; |
yabahiro | 41:e1dd6d97f17d | 1803 | motor[TIRE_FL].dir = BRAKE; |
yabahiro | 42:4f9689c0a349 | 1804 | motor[TIRE_BR].pwm = 10; |
yabahiro | 41:e1dd6d97f17d | 1805 | motor[TIRE_BR].dir = BRAKE; |
yabahiro | 42:4f9689c0a349 | 1806 | motor[TIRE_BL].pwm = 10; |
yabahiro | 41:e1dd6d97f17d | 1807 | motor[TIRE_BL].dir = BRAKE; |
yabahiro | 42:4f9689c0a349 | 1808 | if(count>=30000) { |
yabahiro | 41:e1dd6d97f17d | 1809 | mode=33; |
yabahiro | 41:e1dd6d97f17d | 1810 | count=0; |
yabahiro | 41:e1dd6d97f17d | 1811 | } |
yabahiro | 41:e1dd6d97f17d | 1812 | } else if(mode==33) { |
yabahiro | 45:878f8f385635 | 1813 | motor[TIRE_FR].pwm = 30; |
yabahiro | 45:878f8f385635 | 1814 | motor[TIRE_FR].dir = FOR; |
yabahiro | 45:878f8f385635 | 1815 | motor[TIRE_FL].pwm = 0; |
yabahiro | 45:878f8f385635 | 1816 | motor[TIRE_FL].dir = FREE; |
yabahiro | 45:878f8f385635 | 1817 | motor[TIRE_BR].pwm = 0; |
yabahiro | 45:878f8f385635 | 1818 | motor[TIRE_BR].dir = FREE; |
yabahiro | 45:878f8f385635 | 1819 | motor[TIRE_BL].pwm = 30; |
yabahiro | 45:878f8f385635 | 1820 | motor[TIRE_BL].dir = BACK; |
yabahiro | 45:878f8f385635 | 1821 | if(g[3]==0&&count>=20000) { |
yabahiro | 40:7f93984e8ba1 | 1822 | count=0; |
yabahiro | 40:7f93984e8ba1 | 1823 | if(Twsh==2) { |
yabahiro | 40:7f93984e8ba1 | 1824 | solenoid.solenoid2 = SOLENOID_OFF; |
yabahiro | 40:7f93984e8ba1 | 1825 | } |
yabahiro | 40:7f93984e8ba1 | 1826 | mode=40; |
yabahiro | 40:7f93984e8ba1 | 1827 | } |
yabahiro | 40:7f93984e8ba1 | 1828 | } else if(mode==40) { |
yabahiro | 45:878f8f385635 | 1829 | if(LIB) { |
yabahiro | 40:7f93984e8ba1 | 1830 | mode=42; |
yabahiro | 40:7f93984e8ba1 | 1831 | } |
yabahiro | 40:7f93984e8ba1 | 1832 | switch(g[3]) { |
yabahiro | 40:7f93984e8ba1 | 1833 | case 98: |
yabahiro | 40:7f93984e8ba1 | 1834 | motor[TIRE_FR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1835 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1836 | motor[TIRE_FL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1837 | motor[TIRE_FL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1838 | motor[TIRE_BR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1839 | motor[TIRE_BR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1840 | motor[TIRE_BL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1841 | motor[TIRE_BL].dir = FOR; |
yabahiro | 45:878f8f385635 | 1842 | if(count>=10000) { |
yabahiro | 40:7f93984e8ba1 | 1843 | cross++; |
yabahiro | 40:7f93984e8ba1 | 1844 | count=0; |
yabahiro | 40:7f93984e8ba1 | 1845 | } |
yabahiro | 40:7f93984e8ba1 | 1846 | mtc2=true; |
yabahiro | 45:878f8f385635 | 1847 | if(cross==2) { |
yabahiro | 40:7f93984e8ba1 | 1848 | mode=41; |
yabahiro | 40:7f93984e8ba1 | 1849 | count=0; |
yabahiro | 40:7f93984e8ba1 | 1850 | cross=0; |
yabahiro | 40:7f93984e8ba1 | 1851 | } |
yabahiro | 40:7f93984e8ba1 | 1852 | break; |
yabahiro | 40:7f93984e8ba1 | 1853 | case 0: |
yabahiro | 40:7f93984e8ba1 | 1854 | motor[TIRE_FR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1855 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1856 | motor[TIRE_FL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1857 | motor[TIRE_FL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1858 | motor[TIRE_BR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1859 | motor[TIRE_BR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1860 | motor[TIRE_BL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1861 | motor[TIRE_BL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1862 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1863 | break; |
yabahiro | 40:7f93984e8ba1 | 1864 | case 255: |
yabahiro | 40:7f93984e8ba1 | 1865 | motor[TIRE_FR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1866 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1867 | motor[TIRE_FL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1868 | motor[TIRE_FL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1869 | motor[TIRE_BR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1870 | motor[TIRE_BR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1871 | motor[TIRE_BL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1872 | motor[TIRE_BL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1873 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1874 | break; |
yabahiro | 40:7f93984e8ba1 | 1875 | case 253: |
yabahiro | 40:7f93984e8ba1 | 1876 | motor[TIRE_FR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1877 | motor[TIRE_FR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1878 | motor[TIRE_FL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1879 | motor[TIRE_FL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1880 | motor[TIRE_BR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1881 | motor[TIRE_BR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1882 | motor[TIRE_BL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1883 | motor[TIRE_BL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1884 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1885 | break; |
yabahiro | 40:7f93984e8ba1 | 1886 | case 254: |
yabahiro | 40:7f93984e8ba1 | 1887 | motor[TIRE_FR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1888 | motor[TIRE_FR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1889 | motor[TIRE_FL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1890 | motor[TIRE_FL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1891 | motor[TIRE_BR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1892 | motor[TIRE_BR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1893 | motor[TIRE_BL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1894 | motor[TIRE_BL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1895 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1896 | break; |
yabahiro | 40:7f93984e8ba1 | 1897 | case 1: |
yabahiro | 40:7f93984e8ba1 | 1898 | motor[TIRE_FR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1899 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1900 | motor[TIRE_FL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1901 | motor[TIRE_FL].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1902 | motor[TIRE_BR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1903 | motor[TIRE_BR].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1904 | motor[TIRE_BL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 1905 | motor[TIRE_BL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1906 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1907 | break; |
yabahiro | 40:7f93984e8ba1 | 1908 | case 3: |
yabahiro | 40:7f93984e8ba1 | 1909 | motor[TIRE_FR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1910 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1911 | motor[TIRE_FL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1912 | motor[TIRE_FL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1913 | motor[TIRE_BR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1914 | motor[TIRE_BR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1915 | motor[TIRE_BL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 1916 | motor[TIRE_BL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1917 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1918 | break; |
yabahiro | 40:7f93984e8ba1 | 1919 | case 2: |
yabahiro | 40:7f93984e8ba1 | 1920 | motor[TIRE_FR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1921 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1922 | motor[TIRE_FL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1923 | motor[TIRE_FL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1924 | motor[TIRE_BR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1925 | motor[TIRE_BR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1926 | motor[TIRE_BL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 1927 | motor[TIRE_BL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1928 | mtc2=true; |
yabahiro | 40:7f93984e8ba1 | 1929 | break; |
yabahiro | 40:7f93984e8ba1 | 1930 | } |
yabahiro | 40:7f93984e8ba1 | 1931 | if(g[2]!=98&&mtc2==true) { |
yabahiro | 40:7f93984e8ba1 | 1932 | switch(g[2]) { |
yabahiro | 40:7f93984e8ba1 | 1933 | case 0: |
yabahiro | 40:7f93984e8ba1 | 1934 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1935 | break; |
yabahiro | 40:7f93984e8ba1 | 1936 | case 255: |
yabahiro | 40:7f93984e8ba1 | 1937 | motor[TIRE_FR].pwm += 5; |
yabahiro | 40:7f93984e8ba1 | 1938 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1939 | break; |
yabahiro | 40:7f93984e8ba1 | 1940 | case 253: |
yabahiro | 40:7f93984e8ba1 | 1941 | motor[TIRE_FR].pwm += 10; |
yabahiro | 40:7f93984e8ba1 | 1942 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1943 | break; |
yabahiro | 40:7f93984e8ba1 | 1944 | case 254: |
yabahiro | 40:7f93984e8ba1 | 1945 | motor[TIRE_FR].pwm += 20; |
yabahiro | 40:7f93984e8ba1 | 1946 | motor[TIRE_BR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1947 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1948 | break; |
yabahiro | 40:7f93984e8ba1 | 1949 | case 1: |
yabahiro | 40:7f93984e8ba1 | 1950 | motor[TIRE_BR].pwm += 5; |
yabahiro | 40:7f93984e8ba1 | 1951 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1952 | break; |
yabahiro | 40:7f93984e8ba1 | 1953 | case 3: |
yabahiro | 40:7f93984e8ba1 | 1954 | motor[TIRE_BR].pwm += 10; |
yabahiro | 40:7f93984e8ba1 | 1955 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1956 | break; |
yabahiro | 40:7f93984e8ba1 | 1957 | case 2: |
yabahiro | 40:7f93984e8ba1 | 1958 | motor[TIRE_BR].pwm += 20; |
yabahiro | 40:7f93984e8ba1 | 1959 | motor[TIRE_FR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1960 | mtc2=false; |
yabahiro | 40:7f93984e8ba1 | 1961 | break; |
yabahiro | 40:7f93984e8ba1 | 1962 | } |
yabahiro | 40:7f93984e8ba1 | 1963 | } |
yabahiro | 40:7f93984e8ba1 | 1964 | } else if(mode==41) { |
yabahiro | 41:e1dd6d97f17d | 1965 | if(LIF||LIB) { |
yabahiro | 41:e1dd6d97f17d | 1966 | mode=42; |
yabahiro | 41:e1dd6d97f17d | 1967 | } |
yabahiro | 40:7f93984e8ba1 | 1968 | motor[TIRE_FR].pwm = 30; |
yabahiro | 40:7f93984e8ba1 | 1969 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 1970 | motor[TIRE_FL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1971 | motor[TIRE_FL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1972 | motor[TIRE_BR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 1973 | motor[TIRE_BR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 1974 | motor[TIRE_BL].pwm = 30; |
yabahiro | 40:7f93984e8ba1 | 1975 | motor[TIRE_BL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 1976 | if(g[1]==0) { |
yabahiro | 40:7f93984e8ba1 | 1977 | count=0; |
yabahiro | 40:7f93984e8ba1 | 1978 | mode=70; |
yabahiro | 40:7f93984e8ba1 | 1979 | normal=60; |
yabahiro | 45:878f8f385635 | 1980 | fast=70; |
yabahiro | 40:7f93984e8ba1 | 1981 | slow=40; |
yabahiro | 40:7f93984e8ba1 | 1982 | } |
yabahiro | 40:7f93984e8ba1 | 1983 | } else if(mode==42) { |
yabahiro | 41:e1dd6d97f17d | 1984 | motor[TIRE_FR].pwm = 0; |
yabahiro | 41:e1dd6d97f17d | 1985 | motor[TIRE_FR].dir = FREE; |
yabahiro | 45:878f8f385635 | 1986 | motor[TIRE_FL].pwm = 20; |
yabahiro | 40:7f93984e8ba1 | 1987 | motor[TIRE_FL].dir = FOR; |
yabahiro | 45:878f8f385635 | 1988 | motor[TIRE_BR].pwm = 20; |
yabahiro | 40:7f93984e8ba1 | 1989 | motor[TIRE_BR].dir = BACK; |
yabahiro | 41:e1dd6d97f17d | 1990 | motor[TIRE_BL].pwm = 0; |
yabahiro | 41:e1dd6d97f17d | 1991 | motor[TIRE_BL].dir = FREE; |
yabahiro | 41:e1dd6d97f17d | 1992 | if(g[0]==0) { |
yabahiro | 40:7f93984e8ba1 | 1993 | count=0; |
yabahiro | 40:7f93984e8ba1 | 1994 | slow=40; |
yabahiro | 40:7f93984e8ba1 | 1995 | } |
yabahiro | 40:7f93984e8ba1 | 1996 | |
yabahiro | 40:7f93984e8ba1 | 1997 | } else if(mode==70) |
yabahiro | 40:7f93984e8ba1 | 1998 | switch(g[0]) { |
yabahiro | 40:7f93984e8ba1 | 1999 | case 99: |
yabahiro | 40:7f93984e8ba1 | 2000 | if(count>=100000) { |
yabahiro | 40:7f93984e8ba1 | 2001 | cross++; |
yabahiro | 40:7f93984e8ba1 | 2002 | mode=100; |
yabahiro | 40:7f93984e8ba1 | 2003 | count=0; |
yabahiro | 40:7f93984e8ba1 | 2004 | } |
yabahiro | 41:e1dd6d97f17d | 2005 | if(cross==2) { |
yabahiro | 40:7f93984e8ba1 | 2006 | cross=0; |
yabahiro | 40:7f93984e8ba1 | 2007 | mode=100; |
yabahiro | 40:7f93984e8ba1 | 2008 | } |
yabahiro | 40:7f93984e8ba1 | 2009 | break; |
yabahiro | 40:7f93984e8ba1 | 2010 | case 98: |
yabahiro | 40:7f93984e8ba1 | 2011 | motor[TIRE_FR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 2012 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2013 | motor[TIRE_FL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 2014 | motor[TIRE_FL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2015 | motor[TIRE_BR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 2016 | motor[TIRE_BR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2017 | motor[TIRE_BL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 2018 | motor[TIRE_BL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2019 | break; |
yabahiro | 40:7f93984e8ba1 | 2020 | case 0: |
yabahiro | 40:7f93984e8ba1 | 2021 | motor[TIRE_FR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 2022 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2023 | motor[TIRE_FL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 2024 | motor[TIRE_FL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2025 | motor[TIRE_BR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 2026 | motor[TIRE_BR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2027 | motor[TIRE_BL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 2028 | motor[TIRE_BL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2029 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 2030 | break; |
yabahiro | 40:7f93984e8ba1 | 2031 | case 255: |
yabahiro | 40:7f93984e8ba1 | 2032 | motor[TIRE_FR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 2033 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2034 | motor[TIRE_FL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 2035 | motor[TIRE_FL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2036 | motor[TIRE_BR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 2037 | motor[TIRE_BR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2038 | motor[TIRE_BL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 2039 | motor[TIRE_BL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2040 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 2041 | break; |
yabahiro | 40:7f93984e8ba1 | 2042 | case 253: |
yabahiro | 40:7f93984e8ba1 | 2043 | motor[TIRE_FR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 2044 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2045 | motor[TIRE_FL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 2046 | motor[TIRE_FL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 2047 | motor[TIRE_BR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 2048 | motor[TIRE_BR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 2049 | motor[TIRE_BL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 2050 | motor[TIRE_BL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2051 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 2052 | break; |
yabahiro | 40:7f93984e8ba1 | 2053 | case 254: |
yabahiro | 40:7f93984e8ba1 | 2054 | motor[TIRE_FR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 2055 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2056 | motor[TIRE_FL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 2057 | motor[TIRE_FL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 2058 | motor[TIRE_BR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 2059 | motor[TIRE_BR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 2060 | motor[TIRE_BL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 2061 | motor[TIRE_BL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2062 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 2063 | break; |
yabahiro | 40:7f93984e8ba1 | 2064 | case 1: |
yabahiro | 40:7f93984e8ba1 | 2065 | motor[TIRE_FR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 2066 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2067 | motor[TIRE_FL].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 2068 | motor[TIRE_FL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2069 | motor[TIRE_BR].pwm = fast; |
yabahiro | 40:7f93984e8ba1 | 2070 | motor[TIRE_BR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2071 | motor[TIRE_BL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 2072 | motor[TIRE_BL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2073 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 2074 | break; |
yabahiro | 40:7f93984e8ba1 | 2075 | case 3: |
yabahiro | 40:7f93984e8ba1 | 2076 | motor[TIRE_FR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 2077 | motor[TIRE_FR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 2078 | motor[TIRE_FL].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 2079 | motor[TIRE_FL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2080 | motor[TIRE_BR].pwm = slow; |
yabahiro | 40:7f93984e8ba1 | 2081 | motor[TIRE_BR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2082 | motor[TIRE_BL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 2083 | motor[TIRE_BL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 2084 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 2085 | break; |
yabahiro | 40:7f93984e8ba1 | 2086 | case 2: |
yabahiro | 40:7f93984e8ba1 | 2087 | motor[TIRE_FR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 2088 | motor[TIRE_FR].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 2089 | motor[TIRE_FL].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 2090 | motor[TIRE_FL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2091 | motor[TIRE_BR].pwm = normal; |
yabahiro | 40:7f93984e8ba1 | 2092 | motor[TIRE_BR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2093 | motor[TIRE_BL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 2094 | motor[TIRE_BL].dir = FREE; |
yabahiro | 40:7f93984e8ba1 | 2095 | mtc=true; |
yabahiro | 40:7f93984e8ba1 | 2096 | break; |
yabahiro | 40:7f93984e8ba1 | 2097 | } |
yabahiro | 40:7f93984e8ba1 | 2098 | if(g[1]!=98&&mtc==true) { |
yabahiro | 40:7f93984e8ba1 | 2099 | switch(g[1]) { |
yabahiro | 40:7f93984e8ba1 | 2100 | case 0: |
yabahiro | 40:7f93984e8ba1 | 2101 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 2102 | break; |
yabahiro | 40:7f93984e8ba1 | 2103 | case 255: |
yabahiro | 40:7f93984e8ba1 | 2104 | motor[TIRE_BR].pwm += 5; |
yabahiro | 40:7f93984e8ba1 | 2105 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 2106 | break; |
yabahiro | 40:7f93984e8ba1 | 2107 | case 253: |
yabahiro | 40:7f93984e8ba1 | 2108 | motor[TIRE_BR].pwm += 10; |
yabahiro | 40:7f93984e8ba1 | 2109 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 2110 | break; |
yabahiro | 40:7f93984e8ba1 | 2111 | case 254: |
yabahiro | 40:7f93984e8ba1 | 2112 | motor[TIRE_BR].pwm += 20; |
yabahiro | 40:7f93984e8ba1 | 2113 | motor[TIRE_BL].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 2114 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 2115 | break; |
yabahiro | 40:7f93984e8ba1 | 2116 | case 1: |
yabahiro | 40:7f93984e8ba1 | 2117 | motor[TIRE_BL].pwm += 5; |
yabahiro | 40:7f93984e8ba1 | 2118 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 2119 | break; |
yabahiro | 40:7f93984e8ba1 | 2120 | case 3: |
yabahiro | 40:7f93984e8ba1 | 2121 | motor[TIRE_BL].pwm += 10; |
yabahiro | 40:7f93984e8ba1 | 2122 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 2123 | break; |
yabahiro | 40:7f93984e8ba1 | 2124 | case 2: |
yabahiro | 40:7f93984e8ba1 | 2125 | motor[TIRE_BL].pwm += 20; |
yabahiro | 40:7f93984e8ba1 | 2126 | motor[TIRE_BR].pwm = 0; |
yabahiro | 40:7f93984e8ba1 | 2127 | mtc=false; |
yabahiro | 40:7f93984e8ba1 | 2128 | break; |
yabahiro | 40:7f93984e8ba1 | 2129 | } |
yabahiro | 40:7f93984e8ba1 | 2130 | } else if(mode==100) { |
yabahiro | 40:7f93984e8ba1 | 2131 | motor[TIRE_FR].pwm = 20; |
yabahiro | 40:7f93984e8ba1 | 2132 | motor[TIRE_FR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2133 | motor[TIRE_FL].pwm = 20; |
yabahiro | 40:7f93984e8ba1 | 2134 | motor[TIRE_FL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2135 | motor[TIRE_BR].pwm = 23; |
yabahiro | 40:7f93984e8ba1 | 2136 | motor[TIRE_BR].dir = BACK; |
yabahiro | 40:7f93984e8ba1 | 2137 | motor[TIRE_BL].pwm = 20; |
yabahiro | 40:7f93984e8ba1 | 2138 | motor[TIRE_BL].dir = FOR; |
yabahiro | 40:7f93984e8ba1 | 2139 | } |
yabahiro | 43:677f7446612e | 2140 | } |
yabahiro | 43:677f7446612e | 2141 | #endif |
yabahiro | 40:7f93984e8ba1 | 2142 | |
yabahiro | 43:677f7446612e | 2143 | #if USE_PROCESS_NUM>5 |
yabahiro | 43:677f7446612e | 2144 | static void Process5() |
yabahiro | 43:677f7446612e | 2145 | { |
kishibekairohan | 13:b6e02d6261d7 | 2146 | } |
kishibekairohan | 13:b6e02d6261d7 | 2147 | #endif |
kishibekairohan | 13:b6e02d6261d7 | 2148 | |
kishibekairohan | 13:b6e02d6261d7 | 2149 | #if USE_PROCESS_NUM>6 |
yabahiro | 21:1f1e9c585da8 | 2150 | static void Process6() |
kishibekairohan | 13:b6e02d6261d7 | 2151 | { |
yabahiro | 44:c208a908583c | 2152 | // 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 | 44:c208a908583c | 2153 | LedMode(3); |
yabahiro | 44:c208a908583c | 2154 | count++; |
yabahiro | 44:c208a908583c | 2155 | if(mode==1) {//スタートゾーンから白線検知 |
yabahiro | 44:c208a908583c | 2156 | fast=40; |
yabahiro | 44:c208a908583c | 2157 | normal=30; |
yabahiro | 44:c208a908583c | 2158 | slow=20; |
yabahiro | 44:c208a908583c | 2159 | motor[TIRE_FR].pwm = normal; |
yabahiro | 44:c208a908583c | 2160 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2161 | motor[TIRE_FL].pwm = normal; |
yabahiro | 44:c208a908583c | 2162 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2163 | motor[TIRE_BR].pwm = normal; |
yabahiro | 44:c208a908583c | 2164 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2165 | motor[TIRE_BL].pwm = normal; |
yabahiro | 44:c208a908583c | 2166 | motor[TIRE_BL].dir = FOR; |
yabahiro | 46:4a8bca4cc1fd | 2167 | if(g[2]==0&&count>=100000) { |
yabahiro | 44:c208a908583c | 2168 | count=100000; |
yabahiro | 44:c208a908583c | 2169 | cross=0; |
yabahiro | 44:c208a908583c | 2170 | mode=3; |
yabahiro | 44:c208a908583c | 2171 | } |
yabahiro | 44:c208a908583c | 2172 | } else if(mode==3) { //横ライントレースから縦ライントレースへ |
yabahiro | 44:c208a908583c | 2173 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2174 | motor[TIRE_FR].dir = FREE; |
yabahiro | 44:c208a908583c | 2175 | motor[TIRE_FL].pwm = 25; |
yabahiro | 44:c208a908583c | 2176 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2177 | motor[TIRE_BR].pwm = 25; |
yabahiro | 44:c208a908583c | 2178 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2179 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2180 | motor[TIRE_BL].dir = FREE; |
yabahiro | 44:c208a908583c | 2181 | if(g[0]==0) { |
yabahiro | 44:c208a908583c | 2182 | mode=10; |
yabahiro | 44:c208a908583c | 2183 | count=100000; |
yabahiro | 44:c208a908583c | 2184 | } |
yabahiro | 44:c208a908583c | 2185 | } else if(mode==10) { //縦ライントレース |
yabahiro | 44:c208a908583c | 2186 | if(counts==false&&g[2]==0) { |
yabahiro | 44:c208a908583c | 2187 | cros++; |
yabahiro | 44:c208a908583c | 2188 | counts=true; |
yabahiro | 44:c208a908583c | 2189 | } |
yabahiro | 44:c208a908583c | 2190 | if(counts==true&&g[2]==99) { |
yabahiro | 44:c208a908583c | 2191 | counts=false; |
yabahiro | 44:c208a908583c | 2192 | } |
yabahiro | 21:1f1e9c585da8 | 2193 | |
yabahiro | 44:c208a908583c | 2194 | if(cros==Twsh) { |
yabahiro | 44:c208a908583c | 2195 | mode=11; |
yabahiro | 44:c208a908583c | 2196 | count=0; |
yabahiro | 44:c208a908583c | 2197 | cros=0; |
yabahiro | 44:c208a908583c | 2198 | }//ゆっくりモードに入れなかった時の保険 |
yabahiro | 44:c208a908583c | 2199 | switch(g[0]) { |
yabahiro | 44:c208a908583c | 2200 | case 98: |
yabahiro | 44:c208a908583c | 2201 | motor[TIRE_FR].pwm = normal; |
yabahiro | 44:c208a908583c | 2202 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2203 | motor[TIRE_FL].pwm = normal; |
yabahiro | 44:c208a908583c | 2204 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2205 | motor[TIRE_BR].pwm = normal; |
yabahiro | 44:c208a908583c | 2206 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2207 | motor[TIRE_BL].pwm = normal; |
yabahiro | 44:c208a908583c | 2208 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2209 | mtc=true; |
yabahiro | 44:c208a908583c | 2210 | if(count>80000) { |
yabahiro | 44:c208a908583c | 2211 | cross++; |
yabahiro | 44:c208a908583c | 2212 | count=0; |
yabahiro | 44:c208a908583c | 2213 | } |
yabahiro | 44:c208a908583c | 2214 | if(cross==Twsh) { |
yabahiro | 44:c208a908583c | 2215 | mode=11; |
yabahiro | 44:c208a908583c | 2216 | count=0; |
yabahiro | 44:c208a908583c | 2217 | cross=0; |
yabahiro | 44:c208a908583c | 2218 | } |
yabahiro | 44:c208a908583c | 2219 | break; |
yabahiro | 44:c208a908583c | 2220 | case 0: |
yabahiro | 44:c208a908583c | 2221 | motor[TIRE_FR].pwm = fast; |
yabahiro | 44:c208a908583c | 2222 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2223 | motor[TIRE_FL].pwm = fast; |
yabahiro | 44:c208a908583c | 2224 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2225 | motor[TIRE_BR].pwm = fast; |
yabahiro | 44:c208a908583c | 2226 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2227 | motor[TIRE_BL].pwm = fast; |
yabahiro | 44:c208a908583c | 2228 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2229 | mtc=true; |
yabahiro | 44:c208a908583c | 2230 | break; |
yabahiro | 44:c208a908583c | 2231 | case 255: |
yabahiro | 44:c208a908583c | 2232 | motor[TIRE_FR].pwm = fast; |
yabahiro | 44:c208a908583c | 2233 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2234 | motor[TIRE_FL].pwm = slow; |
yabahiro | 44:c208a908583c | 2235 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2236 | motor[TIRE_BR].pwm = slow; |
yabahiro | 44:c208a908583c | 2237 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2238 | motor[TIRE_BL].pwm = fast; |
yabahiro | 44:c208a908583c | 2239 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2240 | mtc=true; |
yabahiro | 44:c208a908583c | 2241 | break; |
yabahiro | 44:c208a908583c | 2242 | case 253: |
yabahiro | 44:c208a908583c | 2243 | motor[TIRE_FR].pwm = slow; |
yabahiro | 44:c208a908583c | 2244 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2245 | motor[TIRE_FL].pwm = 0; |
yabahiro | 44:c208a908583c | 2246 | motor[TIRE_FL].dir = FREE; |
yabahiro | 44:c208a908583c | 2247 | motor[TIRE_BR].pwm = 0; |
yabahiro | 44:c208a908583c | 2248 | motor[TIRE_BR].dir = FREE; |
yabahiro | 44:c208a908583c | 2249 | motor[TIRE_BL].pwm = slow; |
yabahiro | 44:c208a908583c | 2250 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2251 | mtc=true; |
yabahiro | 44:c208a908583c | 2252 | break; |
yabahiro | 44:c208a908583c | 2253 | case 254: |
yabahiro | 44:c208a908583c | 2254 | motor[TIRE_FR].pwm = normal; |
yabahiro | 44:c208a908583c | 2255 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2256 | motor[TIRE_FL].pwm = 0; |
yabahiro | 44:c208a908583c | 2257 | motor[TIRE_FL].dir = FREE; |
yabahiro | 44:c208a908583c | 2258 | motor[TIRE_BR].pwm = 0; |
yabahiro | 44:c208a908583c | 2259 | motor[TIRE_BR].dir = FREE; |
yabahiro | 44:c208a908583c | 2260 | motor[TIRE_BL].pwm = normal; |
yabahiro | 44:c208a908583c | 2261 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2262 | mtc=true; |
yabahiro | 44:c208a908583c | 2263 | break; |
yabahiro | 44:c208a908583c | 2264 | case 1: |
yabahiro | 44:c208a908583c | 2265 | motor[TIRE_FR].pwm = slow; |
yabahiro | 44:c208a908583c | 2266 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2267 | motor[TIRE_FL].pwm = fast; |
yabahiro | 44:c208a908583c | 2268 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2269 | motor[TIRE_BR].pwm = fast; |
yabahiro | 44:c208a908583c | 2270 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2271 | motor[TIRE_BL].pwm = slow; |
yabahiro | 44:c208a908583c | 2272 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2273 | mtc=true; |
yabahiro | 44:c208a908583c | 2274 | break; |
yabahiro | 44:c208a908583c | 2275 | case 3: |
yabahiro | 44:c208a908583c | 2276 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2277 | motor[TIRE_FR].dir = FREE; |
yabahiro | 44:c208a908583c | 2278 | motor[TIRE_FL].pwm = slow; |
yabahiro | 44:c208a908583c | 2279 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2280 | motor[TIRE_BR].pwm = slow; |
yabahiro | 44:c208a908583c | 2281 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2282 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2283 | motor[TIRE_BL].dir = FREE; |
yabahiro | 44:c208a908583c | 2284 | mtc=true; |
yabahiro | 44:c208a908583c | 2285 | break; |
yabahiro | 44:c208a908583c | 2286 | case 2: |
yabahiro | 44:c208a908583c | 2287 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2288 | motor[TIRE_FR].dir = FREE; |
yabahiro | 44:c208a908583c | 2289 | motor[TIRE_FL].pwm = normal; |
yabahiro | 44:c208a908583c | 2290 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2291 | motor[TIRE_BR].pwm = normal; |
yabahiro | 44:c208a908583c | 2292 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2293 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2294 | motor[TIRE_BL].dir = FREE; |
yabahiro | 44:c208a908583c | 2295 | mtc=true; |
yabahiro | 44:c208a908583c | 2296 | break; |
yabahiro | 44:c208a908583c | 2297 | } |
yabahiro | 44:c208a908583c | 2298 | if(g[0]!=98&&mtc==true) { |
yabahiro | 44:c208a908583c | 2299 | switch(g[1]) { |
yabahiro | 44:c208a908583c | 2300 | case 0: |
yabahiro | 44:c208a908583c | 2301 | mtc=false; |
yabahiro | 44:c208a908583c | 2302 | break; |
yabahiro | 44:c208a908583c | 2303 | case 255: |
yabahiro | 44:c208a908583c | 2304 | motor[TIRE_BR].pwm += 5; |
yabahiro | 44:c208a908583c | 2305 | mtc=false; |
yabahiro | 44:c208a908583c | 2306 | break; |
yabahiro | 44:c208a908583c | 2307 | case 253: |
yabahiro | 44:c208a908583c | 2308 | motor[TIRE_BR].pwm += 10; |
yabahiro | 44:c208a908583c | 2309 | mtc=false; |
yabahiro | 44:c208a908583c | 2310 | break; |
yabahiro | 44:c208a908583c | 2311 | case 254: |
yabahiro | 44:c208a908583c | 2312 | motor[TIRE_BR].pwm += 20; |
yabahiro | 44:c208a908583c | 2313 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2314 | mtc=false; |
yabahiro | 44:c208a908583c | 2315 | break; |
yabahiro | 44:c208a908583c | 2316 | case 1: |
yabahiro | 44:c208a908583c | 2317 | motor[TIRE_BL].pwm += 5; |
yabahiro | 44:c208a908583c | 2318 | mtc=false; |
yabahiro | 44:c208a908583c | 2319 | break; |
yabahiro | 44:c208a908583c | 2320 | case 3: |
yabahiro | 44:c208a908583c | 2321 | motor[TIRE_BL].pwm += 10; |
yabahiro | 44:c208a908583c | 2322 | mtc=false; |
yabahiro | 44:c208a908583c | 2323 | break; |
yabahiro | 44:c208a908583c | 2324 | case 2: |
yabahiro | 44:c208a908583c | 2325 | motor[TIRE_BL].pwm += 20; |
yabahiro | 44:c208a908583c | 2326 | motor[TIRE_BR].pwm = 0; |
yabahiro | 44:c208a908583c | 2327 | mtc=false; |
yabahiro | 44:c208a908583c | 2328 | break; |
yabahiro | 44:c208a908583c | 2329 | } |
yabahiro | 44:c208a908583c | 2330 | } |
yabahiro | 44:c208a908583c | 2331 | } else if(mode==11) { |
yabahiro | 44:c208a908583c | 2332 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2333 | motor[TIRE_FR].dir = FREE; |
yabahiro | 44:c208a908583c | 2334 | motor[TIRE_FL].pwm = normal; |
yabahiro | 44:c208a908583c | 2335 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2336 | motor[TIRE_BR].pwm = normal; |
yabahiro | 44:c208a908583c | 2337 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2338 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2339 | motor[TIRE_BL].dir = FREE; |
yabahiro | 44:c208a908583c | 2340 | if(g[2]==0) { |
yabahiro | 44:c208a908583c | 2341 | count=0; |
yabahiro | 44:c208a908583c | 2342 | cross=0; |
yabahiro | 44:c208a908583c | 2343 | mode=20; |
yabahiro | 44:c208a908583c | 2344 | } |
yabahiro | 44:c208a908583c | 2345 | } else if(mode==20) { |
yabahiro | 44:c208a908583c | 2346 | |
yabahiro | 44:c208a908583c | 2347 | if(Twsh==2) { |
yabahiro | 44:c208a908583c | 2348 | solenoid.solenoid2 = SOLENOID_ON; |
yabahiro | 44:c208a908583c | 2349 | } |
yabahiro | 44:c208a908583c | 2350 | if(counts==false&&g[0]==0) { |
yabahiro | 44:c208a908583c | 2351 | cros++; |
yabahiro | 44:c208a908583c | 2352 | counts=true; |
yabahiro | 44:c208a908583c | 2353 | } |
yabahiro | 44:c208a908583c | 2354 | if(counts==true&&g[0]==99) { |
yabahiro | 44:c208a908583c | 2355 | counts=false; |
yabahiro | 44:c208a908583c | 2356 | } |
yabahiro | 44:c208a908583c | 2357 | |
yabahiro | 44:c208a908583c | 2358 | if(cros==2) { |
yabahiro | 44:c208a908583c | 2359 | |
yabahiro | 44:c208a908583c | 2360 | // mode=21; |
yabahiro | 44:c208a908583c | 2361 | // count=0; |
yabahiro | 44:c208a908583c | 2362 | // cros=0; |
yabahiro | 44:c208a908583c | 2363 | }//ゆっくりモードに入れなかった時の保険 |
yabahiro | 44:c208a908583c | 2364 | if(g[0]==0) { |
yabahiro | 44:c208a908583c | 2365 | fast=35; |
yabahiro | 44:c208a908583c | 2366 | normal=20; |
yabahiro | 44:c208a908583c | 2367 | slow=15; |
yabahiro | 44:c208a908583c | 2368 | } |
yabahiro | 44:c208a908583c | 2369 | switch(g[2]) { |
yabahiro | 44:c208a908583c | 2370 | case 98: |
yabahiro | 44:c208a908583c | 2371 | motor[TIRE_FR].pwm = normal; |
yabahiro | 44:c208a908583c | 2372 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2373 | motor[TIRE_FL].pwm = normal; |
yabahiro | 44:c208a908583c | 2374 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2375 | motor[TIRE_BR].pwm = normal; |
yabahiro | 44:c208a908583c | 2376 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2377 | motor[TIRE_BL].pwm = normal; |
yabahiro | 44:c208a908583c | 2378 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2379 | if(count>30000) { |
yabahiro | 44:c208a908583c | 2380 | cross++; |
yabahiro | 44:c208a908583c | 2381 | count=0; |
yabahiro | 44:c208a908583c | 2382 | } |
yabahiro | 44:c208a908583c | 2383 | mtc2=true; |
yabahiro | 44:c208a908583c | 2384 | if(cross==2) { |
yabahiro | 44:c208a908583c | 2385 | mode=22; |
yabahiro | 44:c208a908583c | 2386 | count=0; |
yabahiro | 44:c208a908583c | 2387 | cross=0; |
yabahiro | 44:c208a908583c | 2388 | fast=40; |
yabahiro | 44:c208a908583c | 2389 | normal=30; |
yabahiro | 44:c208a908583c | 2390 | slow=20; |
yabahiro | 44:c208a908583c | 2391 | } |
yabahiro | 44:c208a908583c | 2392 | break; |
yabahiro | 44:c208a908583c | 2393 | case 0: |
yabahiro | 44:c208a908583c | 2394 | motor[TIRE_FR].pwm = fast; |
yabahiro | 44:c208a908583c | 2395 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2396 | motor[TIRE_FL].pwm = fast; |
yabahiro | 44:c208a908583c | 2397 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2398 | motor[TIRE_BR].pwm = fast; |
yabahiro | 44:c208a908583c | 2399 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2400 | motor[TIRE_BL].pwm = fast; |
yabahiro | 44:c208a908583c | 2401 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2402 | mtc2=true; |
yabahiro | 44:c208a908583c | 2403 | break; |
yabahiro | 44:c208a908583c | 2404 | case 255: |
yabahiro | 44:c208a908583c | 2405 | motor[TIRE_FR].pwm = normal; |
yabahiro | 44:c208a908583c | 2406 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2407 | motor[TIRE_FL].pwm = fast; |
yabahiro | 44:c208a908583c | 2408 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2409 | motor[TIRE_BR].pwm = fast; |
yabahiro | 44:c208a908583c | 2410 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2411 | motor[TIRE_BL].pwm = normal; |
yabahiro | 44:c208a908583c | 2412 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2413 | mtc2=true; |
yabahiro | 44:c208a908583c | 2414 | break; |
yabahiro | 44:c208a908583c | 2415 | case 253: |
yabahiro | 44:c208a908583c | 2416 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2417 | motor[TIRE_FR].dir = FREE; |
yabahiro | 44:c208a908583c | 2418 | motor[TIRE_FL].pwm = slow; |
yabahiro | 44:c208a908583c | 2419 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2420 | motor[TIRE_BR].pwm = slow; |
yabahiro | 44:c208a908583c | 2421 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2422 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2423 | motor[TIRE_BL].dir = FREE; |
yabahiro | 44:c208a908583c | 2424 | mtc2=true; |
yabahiro | 44:c208a908583c | 2425 | break; |
yabahiro | 44:c208a908583c | 2426 | case 254: |
yabahiro | 44:c208a908583c | 2427 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2428 | motor[TIRE_FR].dir = FREE; |
yabahiro | 44:c208a908583c | 2429 | motor[TIRE_FL].pwm = normal; |
yabahiro | 44:c208a908583c | 2430 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2431 | motor[TIRE_BR].pwm = normal; |
yabahiro | 44:c208a908583c | 2432 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2433 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2434 | motor[TIRE_BL].dir = FREE; |
yabahiro | 44:c208a908583c | 2435 | mtc2=true; |
yabahiro | 44:c208a908583c | 2436 | break; |
yabahiro | 44:c208a908583c | 2437 | case 1: |
yabahiro | 44:c208a908583c | 2438 | motor[TIRE_FR].pwm = fast; |
yabahiro | 44:c208a908583c | 2439 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2440 | motor[TIRE_FL].pwm = slow; |
yabahiro | 44:c208a908583c | 2441 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2442 | motor[TIRE_BR].pwm = slow; |
yabahiro | 44:c208a908583c | 2443 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2444 | motor[TIRE_BL].pwm = fast; |
yabahiro | 44:c208a908583c | 2445 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2446 | mtc2=true; |
yabahiro | 44:c208a908583c | 2447 | break; |
yabahiro | 44:c208a908583c | 2448 | case 3: |
yabahiro | 44:c208a908583c | 2449 | motor[TIRE_FR].pwm = slow; |
yabahiro | 44:c208a908583c | 2450 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2451 | motor[TIRE_FL].pwm = 0; |
yabahiro | 44:c208a908583c | 2452 | motor[TIRE_FL].dir = FREE; |
yabahiro | 44:c208a908583c | 2453 | motor[TIRE_BR].pwm = 0; |
yabahiro | 44:c208a908583c | 2454 | motor[TIRE_BR].dir = FREE; |
yabahiro | 44:c208a908583c | 2455 | motor[TIRE_BL].pwm = slow; |
yabahiro | 44:c208a908583c | 2456 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2457 | mtc2=true; |
yabahiro | 44:c208a908583c | 2458 | break; |
yabahiro | 44:c208a908583c | 2459 | case 2: |
yabahiro | 44:c208a908583c | 2460 | motor[TIRE_FR].pwm = normal; |
yabahiro | 44:c208a908583c | 2461 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2462 | motor[TIRE_FL].pwm = 0; |
yabahiro | 44:c208a908583c | 2463 | motor[TIRE_FL].dir = FREE; |
yabahiro | 44:c208a908583c | 2464 | motor[TIRE_BR].pwm = 0; |
yabahiro | 44:c208a908583c | 2465 | motor[TIRE_BR].dir = FREE; |
yabahiro | 44:c208a908583c | 2466 | motor[TIRE_BL].pwm = normal; |
yabahiro | 44:c208a908583c | 2467 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2468 | mtc2=true; |
yabahiro | 44:c208a908583c | 2469 | break; |
yabahiro | 44:c208a908583c | 2470 | } |
yabahiro | 44:c208a908583c | 2471 | if(g[2]!=98&&mtc2==true) { |
yabahiro | 44:c208a908583c | 2472 | switch(g[3]) { |
yabahiro | 44:c208a908583c | 2473 | case 0: |
yabahiro | 44:c208a908583c | 2474 | mtc2=false; |
yabahiro | 44:c208a908583c | 2475 | break; |
yabahiro | 44:c208a908583c | 2476 | case 255: |
yabahiro | 44:c208a908583c | 2477 | motor[TIRE_BL].pwm += 5; |
yabahiro | 44:c208a908583c | 2478 | mtc2=false; |
yabahiro | 44:c208a908583c | 2479 | break; |
yabahiro | 44:c208a908583c | 2480 | case 253: |
yabahiro | 44:c208a908583c | 2481 | motor[TIRE_BL].pwm += 10; |
yabahiro | 44:c208a908583c | 2482 | mtc2=false; |
yabahiro | 44:c208a908583c | 2483 | break; |
yabahiro | 44:c208a908583c | 2484 | case 254: |
yabahiro | 44:c208a908583c | 2485 | motor[TIRE_BL].pwm += 20; |
yabahiro | 44:c208a908583c | 2486 | motor[TIRE_FL].pwm = 0; |
yabahiro | 44:c208a908583c | 2487 | mtc2=false; |
yabahiro | 44:c208a908583c | 2488 | break; |
yabahiro | 44:c208a908583c | 2489 | case 1: |
yabahiro | 44:c208a908583c | 2490 | motor[TIRE_FL].pwm += 5; |
yabahiro | 44:c208a908583c | 2491 | mtc2=false; |
yabahiro | 44:c208a908583c | 2492 | break; |
yabahiro | 44:c208a908583c | 2493 | case 3: |
yabahiro | 44:c208a908583c | 2494 | motor[TIRE_FL].pwm += 10; |
yabahiro | 44:c208a908583c | 2495 | mtc2=false; |
yabahiro | 44:c208a908583c | 2496 | break; |
yabahiro | 44:c208a908583c | 2497 | case 2: |
yabahiro | 44:c208a908583c | 2498 | motor[TIRE_FL].pwm += 20; |
yabahiro | 44:c208a908583c | 2499 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2500 | mtc2=false; |
yabahiro | 44:c208a908583c | 2501 | break; |
yabahiro | 44:c208a908583c | 2502 | } |
yabahiro | 44:c208a908583c | 2503 | } |
yabahiro | 44:c208a908583c | 2504 | } else if(mode==21) { |
yabahiro | 44:c208a908583c | 2505 | motor[TIRE_FR].pwm = 30; |
yabahiro | 44:c208a908583c | 2506 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2507 | motor[TIRE_FL].pwm = 30; |
yabahiro | 44:c208a908583c | 2508 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2509 | motor[TIRE_BR].pwm = 30; |
yabahiro | 44:c208a908583c | 2510 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2511 | motor[TIRE_BL].pwm = 30; |
yabahiro | 44:c208a908583c | 2512 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2513 | if(g[2]==98&&count>=10000) { |
yabahiro | 44:c208a908583c | 2514 | mode=22; |
yabahiro | 44:c208a908583c | 2515 | count=0; |
yabahiro | 44:c208a908583c | 2516 | } |
yabahiro | 44:c208a908583c | 2517 | } |
yabahiro | 44:c208a908583c | 2518 | kiri=true; |
yabahiro | 44:c208a908583c | 2519 | if(kiri) { |
yabahiro | 44:c208a908583c | 2520 | if(mode==22) { |
yabahiro | 44:c208a908583c | 2521 | motor[TIRE_FR].pwm = 100; |
yabahiro | 44:c208a908583c | 2522 | motor[TIRE_FR].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2523 | motor[TIRE_FL].pwm = 100; |
yabahiro | 44:c208a908583c | 2524 | motor[TIRE_FL].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2525 | motor[TIRE_BR].pwm = 100; |
yabahiro | 44:c208a908583c | 2526 | motor[TIRE_BR].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2527 | motor[TIRE_BL].pwm = 100; |
yabahiro | 44:c208a908583c | 2528 | motor[TIRE_BL].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2529 | if(count>=10000) { |
yabahiro | 44:c208a908583c | 2530 | mode=23; |
yabahiro | 44:c208a908583c | 2531 | } |
yabahiro | 44:c208a908583c | 2532 | } else if(mode==23) { |
yabahiro | 44:c208a908583c | 2533 | motor[TIRE_FR].pwm = 20; |
yabahiro | 44:c208a908583c | 2534 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2535 | motor[TIRE_FL].pwm = 20; |
yabahiro | 44:c208a908583c | 2536 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2537 | motor[TIRE_BR].pwm = 20; |
yabahiro | 44:c208a908583c | 2538 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2539 | motor[TIRE_BL].pwm = 20; |
yabahiro | 44:c208a908583c | 2540 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2541 | if(g[2]==98) { |
yabahiro | 44:c208a908583c | 2542 | mode=24; |
yabahiro | 44:c208a908583c | 2543 | count=0; |
yabahiro | 44:c208a908583c | 2544 | } |
yabahiro | 44:c208a908583c | 2545 | } else if(mode==24) { |
yabahiro | 44:c208a908583c | 2546 | motor[TIRE_FR].pwm = 20; |
yabahiro | 44:c208a908583c | 2547 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2548 | motor[TIRE_FL].pwm = 20; |
yabahiro | 44:c208a908583c | 2549 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2550 | motor[TIRE_BR].pwm = 20; |
yabahiro | 44:c208a908583c | 2551 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2552 | motor[TIRE_BL].pwm = 20; |
yabahiro | 44:c208a908583c | 2553 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2554 | if(g[2]!=98) { |
yabahiro | 44:c208a908583c | 2555 | count=0; |
yabahiro | 44:c208a908583c | 2556 | mode=25; |
yabahiro | 44:c208a908583c | 2557 | } |
yabahiro | 44:c208a908583c | 2558 | } else if(mode==25) { |
yabahiro | 44:c208a908583c | 2559 | motor[TIRE_FR].pwm = 10; |
yabahiro | 44:c208a908583c | 2560 | motor[TIRE_FR].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2561 | motor[TIRE_FL].pwm = 10; |
yabahiro | 44:c208a908583c | 2562 | motor[TIRE_FL].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2563 | motor[TIRE_BR].pwm = 10; |
yabahiro | 44:c208a908583c | 2564 | motor[TIRE_BR].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2565 | motor[TIRE_BL].pwm = 10; |
yabahiro | 44:c208a908583c | 2566 | motor[TIRE_BL].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2567 | if(count>=10000) { |
yabahiro | 44:c208a908583c | 2568 | mode=26; |
yabahiro | 44:c208a908583c | 2569 | count=0; |
yabahiro | 44:c208a908583c | 2570 | } |
yabahiro | 44:c208a908583c | 2571 | } else if(mode==26) { |
yabahiro | 44:c208a908583c | 2572 | motor[TIRE_FR].pwm = 20; |
yabahiro | 44:c208a908583c | 2573 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2574 | motor[TIRE_FL].pwm = 20; |
yabahiro | 44:c208a908583c | 2575 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2576 | motor[TIRE_BR].pwm = 20; |
yabahiro | 44:c208a908583c | 2577 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2578 | motor[TIRE_BL].pwm = 20; |
yabahiro | 44:c208a908583c | 2579 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2580 | if(count>=5000) { |
yabahiro | 44:c208a908583c | 2581 | mode=27; |
yabahiro | 44:c208a908583c | 2582 | count=0; |
yabahiro | 44:c208a908583c | 2583 | } |
yabahiro | 44:c208a908583c | 2584 | } else if(mode==27) { |
yabahiro | 44:c208a908583c | 2585 | motor[TIRE_FR].pwm = 20; |
yabahiro | 44:c208a908583c | 2586 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2587 | motor[TIRE_FL].pwm = 20; |
yabahiro | 44:c208a908583c | 2588 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2589 | motor[TIRE_BR].pwm = 20; |
yabahiro | 44:c208a908583c | 2590 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2591 | motor[TIRE_BL].pwm = 20; |
yabahiro | 44:c208a908583c | 2592 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2593 | //どれくらい回転するかって値 |
yabahiro | 45:878f8f385635 | 2594 | if(count>=100) { |
yabahiro | 44:c208a908583c | 2595 | count=0; |
yabahiro | 44:c208a908583c | 2596 | mode=30; |
yabahiro | 44:c208a908583c | 2597 | } |
yabahiro | 44:c208a908583c | 2598 | } else if(mode==24) { |
yabahiro | 44:c208a908583c | 2599 | motor[TIRE_FR].pwm = 10; |
yabahiro | 44:c208a908583c | 2600 | motor[TIRE_FR].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2601 | motor[TIRE_FL].pwm = 10; |
yabahiro | 44:c208a908583c | 2602 | motor[TIRE_FL].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2603 | motor[TIRE_BR].pwm = 10; |
yabahiro | 44:c208a908583c | 2604 | motor[TIRE_BR].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2605 | motor[TIRE_BL].pwm = 10; |
yabahiro | 44:c208a908583c | 2606 | motor[TIRE_BL].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2607 | if(count>=10000) { |
yabahiro | 44:c208a908583c | 2608 | mode=30; |
yabahiro | 44:c208a908583c | 2609 | count=0; |
yabahiro | 44:c208a908583c | 2610 | } |
yabahiro | 44:c208a908583c | 2611 | } |
yabahiro | 44:c208a908583c | 2612 | } else { |
yabahiro | 44:c208a908583c | 2613 | if(mode==22) { |
yabahiro | 44:c208a908583c | 2614 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2615 | motor[TIRE_FR].dir = FREE; |
yabahiro | 44:c208a908583c | 2616 | motor[TIRE_FL].pwm = 25; |
yabahiro | 44:c208a908583c | 2617 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2618 | motor[TIRE_BR].pwm = 25; |
yabahiro | 44:c208a908583c | 2619 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2620 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2621 | motor[TIRE_BL].dir = FREE; |
yabahiro | 45:878f8f385635 | 2622 | if(g[0]==0&&count>=10000) { |
yabahiro | 44:c208a908583c | 2623 | mode=30; |
yabahiro | 45:878f8f385635 | 2624 | count=0; |
yabahiro | 44:c208a908583c | 2625 | cros=0; |
yabahiro | 44:c208a908583c | 2626 | } |
yabahiro | 44:c208a908583c | 2627 | } |
yabahiro | 44:c208a908583c | 2628 | } |
yabahiro | 44:c208a908583c | 2629 | if(mode==30) { |
yabahiro | 44:c208a908583c | 2630 | motor[TIRE_FR].pwm = 59; |
yabahiro | 44:c208a908583c | 2631 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2632 | motor[TIRE_FL].pwm = 62; |
yabahiro | 44:c208a908583c | 2633 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2634 | motor[TIRE_BR].pwm = 59; |
yabahiro | 44:c208a908583c | 2635 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2636 | motor[TIRE_BL].pwm = 62; |
yabahiro | 44:c208a908583c | 2637 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2638 | if(g[0]==98) { |
yabahiro | 44:c208a908583c | 2639 | mode=31; |
yabahiro | 44:c208a908583c | 2640 | count=0; |
yabahiro | 44:c208a908583c | 2641 | } |
yabahiro | 44:c208a908583c | 2642 | } else if(mode==31) { |
yabahiro | 44:c208a908583c | 2643 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2644 | motor[TIRE_FR].dir = FREE; |
yabahiro | 44:c208a908583c | 2645 | motor[TIRE_FL].pwm = 0; |
yabahiro | 44:c208a908583c | 2646 | motor[TIRE_FL].dir = FREE; |
yabahiro | 44:c208a908583c | 2647 | motor[TIRE_BR].pwm = 0; |
yabahiro | 44:c208a908583c | 2648 | motor[TIRE_BR].dir = FREE; |
yabahiro | 44:c208a908583c | 2649 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2650 | motor[TIRE_BL].dir = FREE; |
yabahiro | 44:c208a908583c | 2651 | if(count>=5000) { |
yabahiro | 44:c208a908583c | 2652 | count=0; |
yabahiro | 44:c208a908583c | 2653 | mode=32; |
yabahiro | 44:c208a908583c | 2654 | } |
yabahiro | 44:c208a908583c | 2655 | } else if(mode==32) { |
yabahiro | 44:c208a908583c | 2656 | motor[TIRE_FR].pwm = 10; |
yabahiro | 44:c208a908583c | 2657 | motor[TIRE_FR].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2658 | motor[TIRE_FL].pwm = 10; |
yabahiro | 44:c208a908583c | 2659 | motor[TIRE_FL].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2660 | motor[TIRE_BR].pwm = 10; |
yabahiro | 44:c208a908583c | 2661 | motor[TIRE_BR].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2662 | motor[TIRE_BL].pwm = 10; |
yabahiro | 44:c208a908583c | 2663 | motor[TIRE_BL].dir = BRAKE; |
yabahiro | 44:c208a908583c | 2664 | if(count>=40000) { |
yabahiro | 44:c208a908583c | 2665 | mode=33; |
yabahiro | 44:c208a908583c | 2666 | count=0; |
yabahiro | 44:c208a908583c | 2667 | } |
yabahiro | 44:c208a908583c | 2668 | } else if(mode==33) { |
yabahiro | 44:c208a908583c | 2669 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2670 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2671 | motor[TIRE_FL].pwm = 30; |
yabahiro | 44:c208a908583c | 2672 | motor[TIRE_FL].dir = FOR; |
yabahiro | 44:c208a908583c | 2673 | motor[TIRE_BR].pwm = 30; |
yabahiro | 44:c208a908583c | 2674 | motor[TIRE_BR].dir = BACK; |
yabahiro | 44:c208a908583c | 2675 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2676 | motor[TIRE_BL].dir = FOR; |
yabahiro | 45:878f8f385635 | 2677 | if(g[3]==0&&count>=20000) { |
yabahiro | 44:c208a908583c | 2678 | count=0; |
yabahiro | 44:c208a908583c | 2679 | if(Twsh==2) { |
yabahiro | 44:c208a908583c | 2680 | solenoid.solenoid2 = SOLENOID_OFF; |
yabahiro | 44:c208a908583c | 2681 | } |
yabahiro | 44:c208a908583c | 2682 | mode=40; |
yabahiro | 44:c208a908583c | 2683 | } |
yabahiro | 44:c208a908583c | 2684 | } else if(mode==40) { |
yabahiro | 44:c208a908583c | 2685 | if(LIB) { |
yabahiro | 44:c208a908583c | 2686 | mode=42; |
yabahiro | 44:c208a908583c | 2687 | } |
yabahiro | 44:c208a908583c | 2688 | if(counts==false&&g[0]==0) { |
yabahiro | 44:c208a908583c | 2689 | cros++; |
yabahiro | 44:c208a908583c | 2690 | counts=true; |
yabahiro | 44:c208a908583c | 2691 | } |
yabahiro | 44:c208a908583c | 2692 | if(counts==true&&g[0]==99) { |
yabahiro | 44:c208a908583c | 2693 | counts=false; |
yabahiro | 44:c208a908583c | 2694 | } |
yabahiro | 44:c208a908583c | 2695 | |
yabahiro | 44:c208a908583c | 2696 | if(cros==1) { |
yabahiro | 44:c208a908583c | 2697 | // mode=41; |
yabahiro | 44:c208a908583c | 2698 | //count=0; |
yabahiro | 44:c208a908583c | 2699 | //cros=0; |
yabahiro | 44:c208a908583c | 2700 | }//ゆっくりモードに入れなかった時の保険 |
yabahiro | 44:c208a908583c | 2701 | |
yabahiro | 44:c208a908583c | 2702 | switch(g[3]) { |
yabahiro | 44:c208a908583c | 2703 | case 98: |
yabahiro | 44:c208a908583c | 2704 | motor[TIRE_FR].pwm = normal; |
yabahiro | 44:c208a908583c | 2705 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2706 | motor[TIRE_FL].pwm = normal; |
yabahiro | 44:c208a908583c | 2707 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2708 | motor[TIRE_BR].pwm = normal; |
yabahiro | 44:c208a908583c | 2709 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2710 | motor[TIRE_BL].pwm = normal; |
yabahiro | 44:c208a908583c | 2711 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2712 | if(count>20000) { |
yabahiro | 44:c208a908583c | 2713 | cross++; |
yabahiro | 44:c208a908583c | 2714 | count=0; |
yabahiro | 44:c208a908583c | 2715 | } |
yabahiro | 44:c208a908583c | 2716 | mtc2=true; |
yabahiro | 44:c208a908583c | 2717 | if(cross==2) { |
yabahiro | 44:c208a908583c | 2718 | mode=41; |
yabahiro | 44:c208a908583c | 2719 | count=0; |
yabahiro | 44:c208a908583c | 2720 | cross=0; |
yabahiro | 44:c208a908583c | 2721 | } |
yabahiro | 44:c208a908583c | 2722 | break; |
yabahiro | 44:c208a908583c | 2723 | case 0: |
yabahiro | 44:c208a908583c | 2724 | motor[TIRE_FR].pwm = fast; |
yabahiro | 44:c208a908583c | 2725 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2726 | motor[TIRE_FL].pwm = fast; |
yabahiro | 44:c208a908583c | 2727 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2728 | motor[TIRE_BR].pwm = fast; |
yabahiro | 44:c208a908583c | 2729 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2730 | motor[TIRE_BL].pwm = fast; |
yabahiro | 44:c208a908583c | 2731 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2732 | mtc2=true; |
yabahiro | 44:c208a908583c | 2733 | break; |
yabahiro | 44:c208a908583c | 2734 | case 255: |
yabahiro | 44:c208a908583c | 2735 | motor[TIRE_FR].pwm = slow; |
yabahiro | 44:c208a908583c | 2736 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2737 | motor[TIRE_FL].pwm = fast; |
yabahiro | 44:c208a908583c | 2738 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2739 | motor[TIRE_BR].pwm = fast; |
yabahiro | 44:c208a908583c | 2740 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2741 | motor[TIRE_BL].pwm = slow; |
yabahiro | 44:c208a908583c | 2742 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2743 | mtc2=true; |
yabahiro | 44:c208a908583c | 2744 | break; |
yabahiro | 44:c208a908583c | 2745 | case 253: |
yabahiro | 44:c208a908583c | 2746 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2747 | motor[TIRE_FR].dir = FREE; |
yabahiro | 44:c208a908583c | 2748 | motor[TIRE_FL].pwm = slow; |
yabahiro | 44:c208a908583c | 2749 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2750 | motor[TIRE_BR].pwm = slow; |
yabahiro | 44:c208a908583c | 2751 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2752 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2753 | motor[TIRE_BL].dir = FREE; |
yabahiro | 44:c208a908583c | 2754 | mtc2=true; |
yabahiro | 44:c208a908583c | 2755 | break; |
yabahiro | 44:c208a908583c | 2756 | case 254: |
yabahiro | 44:c208a908583c | 2757 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2758 | motor[TIRE_FR].dir = FREE; |
yabahiro | 44:c208a908583c | 2759 | motor[TIRE_FL].pwm = normal; |
yabahiro | 44:c208a908583c | 2760 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2761 | motor[TIRE_BR].pwm = normal; |
yabahiro | 44:c208a908583c | 2762 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2763 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2764 | motor[TIRE_BL].dir = FREE; |
yabahiro | 44:c208a908583c | 2765 | mtc2=true; |
yabahiro | 44:c208a908583c | 2766 | break; |
yabahiro | 44:c208a908583c | 2767 | case 1: |
yabahiro | 44:c208a908583c | 2768 | motor[TIRE_FR].pwm = fast; |
yabahiro | 44:c208a908583c | 2769 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2770 | motor[TIRE_FL].pwm = slow; |
yabahiro | 44:c208a908583c | 2771 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2772 | motor[TIRE_BR].pwm = slow; |
yabahiro | 44:c208a908583c | 2773 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2774 | motor[TIRE_BL].pwm = fast; |
yabahiro | 44:c208a908583c | 2775 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2776 | mtc2=true; |
yabahiro | 44:c208a908583c | 2777 | break; |
yabahiro | 44:c208a908583c | 2778 | case 3: |
yabahiro | 44:c208a908583c | 2779 | motor[TIRE_FR].pwm = slow; |
yabahiro | 44:c208a908583c | 2780 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2781 | motor[TIRE_FL].pwm = 0; |
yabahiro | 44:c208a908583c | 2782 | motor[TIRE_FL].dir = FREE; |
yabahiro | 44:c208a908583c | 2783 | motor[TIRE_BR].pwm = 0; |
yabahiro | 44:c208a908583c | 2784 | motor[TIRE_BR].dir = FREE; |
yabahiro | 44:c208a908583c | 2785 | motor[TIRE_BL].pwm = slow; |
yabahiro | 44:c208a908583c | 2786 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2787 | mtc2=true; |
yabahiro | 44:c208a908583c | 2788 | break; |
yabahiro | 44:c208a908583c | 2789 | case 2: |
yabahiro | 44:c208a908583c | 2790 | motor[TIRE_FR].pwm = normal; |
yabahiro | 44:c208a908583c | 2791 | motor[TIRE_FR].dir = BACK; |
yabahiro | 44:c208a908583c | 2792 | motor[TIRE_FL].pwm = 0; |
yabahiro | 44:c208a908583c | 2793 | motor[TIRE_FL].dir = FREE; |
yabahiro | 44:c208a908583c | 2794 | motor[TIRE_BR].pwm = 0; |
yabahiro | 44:c208a908583c | 2795 | motor[TIRE_BR].dir = FREE; |
yabahiro | 44:c208a908583c | 2796 | motor[TIRE_BL].pwm = normal; |
yabahiro | 44:c208a908583c | 2797 | motor[TIRE_BL].dir = FOR; |
yabahiro | 44:c208a908583c | 2798 | mtc2=true; |
yabahiro | 44:c208a908583c | 2799 | break; |
yabahiro | 44:c208a908583c | 2800 | } |
yabahiro | 44:c208a908583c | 2801 | if(g[2]!=98&&mtc2==true) { |
yabahiro | 44:c208a908583c | 2802 | switch(g[2]) { |
yabahiro | 44:c208a908583c | 2803 | case 0: |
yabahiro | 44:c208a908583c | 2804 | mtc2=false; |
yabahiro | 44:c208a908583c | 2805 | break; |
yabahiro | 44:c208a908583c | 2806 | case 255: |
yabahiro | 44:c208a908583c | 2807 | motor[TIRE_FL].pwm += 5; |
yabahiro | 44:c208a908583c | 2808 | mtc2=false; |
yabahiro | 44:c208a908583c | 2809 | break; |
yabahiro | 44:c208a908583c | 2810 | case 253: |
yabahiro | 44:c208a908583c | 2811 | motor[TIRE_FL].pwm += 10; |
yabahiro | 44:c208a908583c | 2812 | mtc2=false; |
yabahiro | 44:c208a908583c | 2813 | break; |
yabahiro | 44:c208a908583c | 2814 | case 254: |
yabahiro | 44:c208a908583c | 2815 | motor[TIRE_FL].pwm += 20; |
yabahiro | 44:c208a908583c | 2816 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2817 | mtc2=false; |
yabahiro | 44:c208a908583c | 2818 | break; |
yabahiro | 44:c208a908583c | 2819 | case 1: |
yabahiro | 44:c208a908583c | 2820 | motor[TIRE_BL].pwm += 5; |
yabahiro | 44:c208a908583c | 2821 | mtc2=false; |
yabahiro | 44:c208a908583c | 2822 | break; |
yabahiro | 44:c208a908583c | 2823 | case 3: |
yabahiro | 44:c208a908583c | 2824 | motor[TIRE_BL].pwm += 10; |
yabahiro | 44:c208a908583c | 2825 | mtc2=false; |
yabahiro | 44:c208a908583c | 2826 | break; |
yabahiro | 44:c208a908583c | 2827 | case 2: |
yabahiro | 44:c208a908583c | 2828 | motor[TIRE_BL].pwm += 20; |
yabahiro | 44:c208a908583c | 2829 | motor[TIRE_FL].pwm = 0; |
yabahiro | 44:c208a908583c | 2830 | mtc2=false; |
yabahiro | 44:c208a908583c | 2831 | break; |
yabahiro | 44:c208a908583c | 2832 | } |
yabahiro | 44:c208a908583c | 2833 | } |
yabahiro | 44:c208a908583c | 2834 | } else if(mode==41) { |
yabahiro | 44:c208a908583c | 2835 | if(LIF||LIB) { |
yabahiro | 44:c208a908583c | 2836 | mode=42; |
yabahiro | 44:c208a908583c | 2837 | } |
yabahiro | 44:c208a908583c | 2838 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2839 | motor[TIRE_FR].dir = FREE; |
yabahiro | 44:c208a908583c | 2840 | motor[TIRE_FL].pwm = 30; |
yabahiro | 44:c208a908583c | 2841 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2842 | motor[TIRE_BR].pwm = 30; |
yabahiro | 44:c208a908583c | 2843 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2844 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2845 | motor[TIRE_BL].dir = FREE; |
yabahiro | 44:c208a908583c | 2846 | if(g[1]==0) { |
yabahiro | 44:c208a908583c | 2847 | count=0; |
yabahiro | 44:c208a908583c | 2848 | mode=70; |
yabahiro | 45:878f8f385635 | 2849 | normal=60; |
yabahiro | 45:878f8f385635 | 2850 | fast=70; |
yabahiro | 45:878f8f385635 | 2851 | slow=40; |
yabahiro | 44:c208a908583c | 2852 | } |
yabahiro | 44:c208a908583c | 2853 | } else if(mode==42) { |
yabahiro | 44:c208a908583c | 2854 | motor[TIRE_FR].pwm = 20; |
yabahiro | 44:c208a908583c | 2855 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2856 | motor[TIRE_FL].pwm = 0; |
yabahiro | 44:c208a908583c | 2857 | motor[TIRE_FL].dir = FREE; |
yabahiro | 44:c208a908583c | 2858 | motor[TIRE_BR].pwm = 0; |
yabahiro | 44:c208a908583c | 2859 | motor[TIRE_BR].dir = FREE; |
yabahiro | 44:c208a908583c | 2860 | motor[TIRE_BL].pwm = 20; |
yabahiro | 44:c208a908583c | 2861 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2862 | if(g[1]==0) { |
yabahiro | 44:c208a908583c | 2863 | count=0; |
yabahiro | 44:c208a908583c | 2864 | mode=70; |
yabahiro | 44:c208a908583c | 2865 | } |
yabahiro | 44:c208a908583c | 2866 | } else if(mode==70) { |
yabahiro | 44:c208a908583c | 2867 | switch(g[1]) { |
yabahiro | 44:c208a908583c | 2868 | case 99: |
yabahiro | 44:c208a908583c | 2869 | if(count>=100000) { |
yabahiro | 44:c208a908583c | 2870 | mode=100; |
yabahiro | 44:c208a908583c | 2871 | } |
yabahiro | 44:c208a908583c | 2872 | break; |
yabahiro | 44:c208a908583c | 2873 | case 98: |
yabahiro | 44:c208a908583c | 2874 | motor[TIRE_FR].pwm = normal; |
yabahiro | 44:c208a908583c | 2875 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2876 | motor[TIRE_FL].pwm = normal; |
yabahiro | 44:c208a908583c | 2877 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2878 | motor[TIRE_BR].pwm = normal; |
yabahiro | 44:c208a908583c | 2879 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2880 | motor[TIRE_BL].pwm = normal; |
yabahiro | 44:c208a908583c | 2881 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2882 | break; |
yabahiro | 44:c208a908583c | 2883 | case 0: |
yabahiro | 44:c208a908583c | 2884 | motor[TIRE_FR].pwm = 80; |
yabahiro | 44:c208a908583c | 2885 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2886 | motor[TIRE_FL].pwm = 80; |
yabahiro | 44:c208a908583c | 2887 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2888 | motor[TIRE_BR].pwm = 80; |
yabahiro | 44:c208a908583c | 2889 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2890 | motor[TIRE_BL].pwm = 80; |
yabahiro | 44:c208a908583c | 2891 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2892 | mtc=true; |
yabahiro | 44:c208a908583c | 2893 | break; |
yabahiro | 44:c208a908583c | 2894 | case 255: |
yabahiro | 44:c208a908583c | 2895 | motor[TIRE_FR].pwm = fast; |
yabahiro | 44:c208a908583c | 2896 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2897 | motor[TIRE_FL].pwm = slow; |
yabahiro | 44:c208a908583c | 2898 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2899 | motor[TIRE_BR].pwm = slow; |
yabahiro | 44:c208a908583c | 2900 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2901 | motor[TIRE_BL].pwm = fast; |
yabahiro | 44:c208a908583c | 2902 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2903 | mtc=true; |
yabahiro | 44:c208a908583c | 2904 | break; |
yabahiro | 44:c208a908583c | 2905 | case 253: |
yabahiro | 44:c208a908583c | 2906 | motor[TIRE_FR].pwm = slow; |
yabahiro | 44:c208a908583c | 2907 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2908 | motor[TIRE_FL].pwm = 0; |
yabahiro | 44:c208a908583c | 2909 | motor[TIRE_FL].dir = FREE; |
yabahiro | 44:c208a908583c | 2910 | motor[TIRE_BR].pwm = 0; |
yabahiro | 44:c208a908583c | 2911 | motor[TIRE_BR].dir = FREE; |
yabahiro | 44:c208a908583c | 2912 | motor[TIRE_BL].pwm = slow; |
yabahiro | 44:c208a908583c | 2913 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2914 | mtc=true; |
yabahiro | 44:c208a908583c | 2915 | break; |
yabahiro | 44:c208a908583c | 2916 | case 254: |
yabahiro | 44:c208a908583c | 2917 | motor[TIRE_FR].pwm = normal; |
yabahiro | 44:c208a908583c | 2918 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2919 | motor[TIRE_FL].pwm = 0; |
yabahiro | 44:c208a908583c | 2920 | motor[TIRE_FL].dir = FREE; |
yabahiro | 44:c208a908583c | 2921 | motor[TIRE_BR].pwm = 0; |
yabahiro | 44:c208a908583c | 2922 | motor[TIRE_BR].dir = FREE; |
yabahiro | 44:c208a908583c | 2923 | motor[TIRE_BL].pwm = normal; |
yabahiro | 44:c208a908583c | 2924 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2925 | mtc=true; |
yabahiro | 44:c208a908583c | 2926 | break; |
yabahiro | 44:c208a908583c | 2927 | case 1: |
yabahiro | 44:c208a908583c | 2928 | motor[TIRE_FR].pwm = slow; |
yabahiro | 44:c208a908583c | 2929 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2930 | motor[TIRE_FL].pwm = fast; |
yabahiro | 44:c208a908583c | 2931 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2932 | motor[TIRE_BR].pwm = fast; |
yabahiro | 44:c208a908583c | 2933 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2934 | motor[TIRE_BL].pwm = slow; |
yabahiro | 44:c208a908583c | 2935 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 2936 | mtc=true; |
yabahiro | 44:c208a908583c | 2937 | break; |
yabahiro | 44:c208a908583c | 2938 | case 3: |
yabahiro | 44:c208a908583c | 2939 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2940 | motor[TIRE_FR].dir = FREE; |
yabahiro | 44:c208a908583c | 2941 | motor[TIRE_FL].pwm = slow; |
yabahiro | 44:c208a908583c | 2942 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2943 | motor[TIRE_BR].pwm = slow; |
yabahiro | 44:c208a908583c | 2944 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2945 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2946 | motor[TIRE_BL].dir = FREE; |
yabahiro | 44:c208a908583c | 2947 | mtc=true; |
yabahiro | 44:c208a908583c | 2948 | break; |
yabahiro | 44:c208a908583c | 2949 | case 2: |
yabahiro | 44:c208a908583c | 2950 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2951 | motor[TIRE_FR].dir = FREE; |
yabahiro | 44:c208a908583c | 2952 | motor[TIRE_FL].pwm = normal; |
yabahiro | 44:c208a908583c | 2953 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2954 | motor[TIRE_BR].pwm = normal; |
yabahiro | 44:c208a908583c | 2955 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 2956 | motor[TIRE_BL].pwm = 0; |
yabahiro | 44:c208a908583c | 2957 | motor[TIRE_BL].dir = FREE; |
yabahiro | 44:c208a908583c | 2958 | mtc=true; |
yabahiro | 44:c208a908583c | 2959 | break; |
yabahiro | 44:c208a908583c | 2960 | } |
yabahiro | 44:c208a908583c | 2961 | if(g[1]!=98&&mtc==true) { |
yabahiro | 44:c208a908583c | 2962 | switch(g[0]) { |
yabahiro | 44:c208a908583c | 2963 | case 0: |
yabahiro | 44:c208a908583c | 2964 | mtc=false; |
yabahiro | 44:c208a908583c | 2965 | break; |
yabahiro | 44:c208a908583c | 2966 | case 255: |
yabahiro | 44:c208a908583c | 2967 | motor[TIRE_FL].pwm += 5; |
yabahiro | 44:c208a908583c | 2968 | mtc=false; |
yabahiro | 44:c208a908583c | 2969 | break; |
yabahiro | 44:c208a908583c | 2970 | case 253: |
yabahiro | 44:c208a908583c | 2971 | motor[TIRE_FL].pwm += 10; |
yabahiro | 44:c208a908583c | 2972 | mtc=false; |
yabahiro | 44:c208a908583c | 2973 | break; |
yabahiro | 44:c208a908583c | 2974 | case 254: |
yabahiro | 44:c208a908583c | 2975 | motor[TIRE_FL].pwm += 20; |
yabahiro | 44:c208a908583c | 2976 | motor[TIRE_FR].pwm = 0; |
yabahiro | 44:c208a908583c | 2977 | mtc=false; |
yabahiro | 44:c208a908583c | 2978 | break; |
yabahiro | 44:c208a908583c | 2979 | case 1: |
yabahiro | 44:c208a908583c | 2980 | motor[TIRE_FR].pwm += 5; |
yabahiro | 44:c208a908583c | 2981 | mtc=false; |
yabahiro | 44:c208a908583c | 2982 | break; |
yabahiro | 44:c208a908583c | 2983 | case 3: |
yabahiro | 44:c208a908583c | 2984 | motor[TIRE_FR].pwm += 10; |
yabahiro | 44:c208a908583c | 2985 | mtc=false; |
yabahiro | 44:c208a908583c | 2986 | break; |
yabahiro | 44:c208a908583c | 2987 | case 2: |
yabahiro | 44:c208a908583c | 2988 | motor[TIRE_FR].pwm += 20; |
yabahiro | 44:c208a908583c | 2989 | motor[TIRE_FL].pwm = 0; |
yabahiro | 44:c208a908583c | 2990 | mtc=false; |
yabahiro | 44:c208a908583c | 2991 | break; |
yabahiro | 44:c208a908583c | 2992 | } |
yabahiro | 44:c208a908583c | 2993 | } |
yabahiro | 44:c208a908583c | 2994 | } else if(mode==100) { |
yabahiro | 44:c208a908583c | 2995 | motor[TIRE_FR].pwm = 20; |
yabahiro | 44:c208a908583c | 2996 | motor[TIRE_FR].dir = FOR; |
yabahiro | 44:c208a908583c | 2997 | motor[TIRE_FL].pwm = 20; |
yabahiro | 44:c208a908583c | 2998 | motor[TIRE_FL].dir = BACK; |
yabahiro | 44:c208a908583c | 2999 | motor[TIRE_BR].pwm = 23; |
yabahiro | 44:c208a908583c | 3000 | motor[TIRE_BR].dir = FOR; |
yabahiro | 44:c208a908583c | 3001 | motor[TIRE_BL].pwm = 20; |
yabahiro | 44:c208a908583c | 3002 | motor[TIRE_BL].dir = BACK; |
yabahiro | 44:c208a908583c | 3003 | } else { |
yabahiro | 44:c208a908583c | 3004 | } |
kishibekairohan | 13:b6e02d6261d7 | 3005 | } |
kishibekairohan | 13:b6e02d6261d7 | 3006 | #endif |
kishibekairohan | 13:b6e02d6261d7 | 3007 | |
kishibekairohan | 13:b6e02d6261d7 | 3008 | #if USE_PROCESS_NUM>7 |
kishibekairohan | 13:b6e02d6261d7 | 3009 | static void Process7() |
kishibekairohan | 13:b6e02d6261d7 | 3010 | { |
yabahiro | 21:1f1e9c585da8 | 3011 | |
kishibekairohan | 12:c09b3e08a316 | 3012 | } |
kishibekairohan | 12:c09b3e08a316 | 3013 | #endif |
kishibekairohan | 12:c09b3e08a316 | 3014 | |
yabahiro | 21:1f1e9c585da8 | 3015 | #if USE_PROCESS_NUM>8 |
kishibekairohan | 13:b6e02d6261d7 | 3016 | static void Process8() |
kishibekairohan | 12:c09b3e08a316 | 3017 | { |
yabahiro | 21:1f1e9c585da8 | 3018 | |
kishibekairohan | 12:c09b3e08a316 | 3019 | } |
kishibekairohan | 12:c09b3e08a316 | 3020 | #endif |
kishibekairohan | 12:c09b3e08a316 | 3021 | |
kishibekairohan | 13:b6e02d6261d7 | 3022 | #if USE_PROCESS_NUM>9 |
kishibekairohan | 13:b6e02d6261d7 | 3023 | static void Process9() |
kishibekairohan | 12:c09b3e08a316 | 3024 | { |
yabahiro | 21:1f1e9c585da8 | 3025 | |
t_yamamoto | 0:669ef71cba68 | 3026 | } |
t_yamamoto | 0:669ef71cba68 | 3027 | #endif |
t_yamamoto | 0:669ef71cba68 | 3028 | #endif |
t_yamamoto | 0:669ef71cba68 | 3029 | #pragma endregion PROCESS |
t_yamamoto | 0:669ef71cba68 | 3030 | |
t_yamamoto | 0:669ef71cba68 | 3031 | static void AllActuatorReset() |
t_yamamoto | 0:669ef71cba68 | 3032 | { |
t_yamamoto | 0:669ef71cba68 | 3033 | |
yabahiro | 21:1f1e9c585da8 | 3034 | #ifdef USE_SOLENOID |
yabahiro | 21:1f1e9c585da8 | 3035 | solenoid.all = ALL_SOLENOID_OFF; |
yabahiro | 21:1f1e9c585da8 | 3036 | #endif |
t_yamamoto | 0:669ef71cba68 | 3037 | |
yabahiro | 21:1f1e9c585da8 | 3038 | #ifdef USE_MOTOR |
yabahiro | 21:1f1e9c585da8 | 3039 | for (uint8_t i = 0; i < MOUNTING_MOTOR_NUM; i++) { |
yabahiro | 21:1f1e9c585da8 | 3040 | motor[i].dir = FREE; |
yabahiro | 21:1f1e9c585da8 | 3041 | motor[i].pwm = 0; |
yabahiro | 21:1f1e9c585da8 | 3042 | } |
yabahiro | 21:1f1e9c585da8 | 3043 | #endif |
t_yamamoto | 0:669ef71cba68 | 3044 | } |
t_yamamoto | 0:669ef71cba68 | 3045 | |
yabahiro | 21:1f1e9c585da8 | 3046 | /* |
yabahiro | 21:1f1e9c585da8 | 3047 | void BuzzerTimer_func() |
yabahiro | 21:1f1e9c585da8 | 3048 | { |
kishibekairohan | 16:3f2c2d89372b | 3049 | buzzer = !buzzer; |
kishibekairohan | 17:50dc4b449e69 | 3050 | //LED_DEBUG0 = !LED_DEBUG0; |
kishibekairohan | 11:028a150943b5 | 3051 | } |
yabahiro | 21:1f1e9c585da8 | 3052 | */ |
yabahiro | 21:1f1e9c585da8 | 3053 | void TapeLedEms_func() |
yabahiro | 21:1f1e9c585da8 | 3054 | { |
kishibekairohan | 16:3f2c2d89372b | 3055 | sendLedData.code = sendLedData.code == (uint32_t)Red ? (uint32_t)Black : (uint32_t)Red; |
kishibekairohan | 9:f93fc79a49ea | 3056 | } |
kishibekairohan | 16:3f2c2d89372b | 3057 | |
kishibekairohan | 16:3f2c2d89372b | 3058 | #pragma region USER-DEFINED-FUNCTIONS |
kishibekairohan | 16:3f2c2d89372b | 3059 | |
kishibekairohan | 16:3f2c2d89372b | 3060 | |
t_yamamoto | 0:669ef71cba68 | 3061 | #pragma endregion |