Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Process.cpp
00001 #include "mbed.h" 00002 #include "Process.h" 00003 00004 #include <stdlib.h> 00005 #include "../../CommonLibraries/PID/PID.h" 00006 #include "../../Communication/RS485/ActuatorHub/ActuatorHub.h" 00007 #include "../../Communication/RS485/LineHub/LineHub.h" 00008 #include "../../Communication/Controller/Controller.h" 00009 #include "../../Switch/Switch.h" 00010 00011 #include "../../LED/LED.h" 00012 #include "../../Safty/Safty.h" 00013 #include "../Using.h" 00014 00015 using namespace SWITCH; 00016 using namespace PID_SPACE; 00017 00018 using namespace LINEHUB; 00019 00020 static CONTROLLER::ControllerData *controller; 00021 ACTUATORHUB::MOTOR::MotorStatus motor[MOUNTING_MOTOR_NUM]; 00022 ACTUATORHUB::SOLENOID::SolenoidStatus solenoid; 00023 00024 static bool lock; 00025 static bool processChangeComp; 00026 static int current; 00027 00028 static void AllActuatorReset(); 00029 00030 #ifdef USE_SUBPROCESS 00031 static void (*Process[USE_PROCESS_NUM])(void); 00032 #endif 00033 00034 #pragma region USER-DEFINED_VARIABLES_AND_PROTOTYPE 00035 00036 /*Replace here with the definition code of your variables.*/ 00037 00038 00039 Serial pc(USBTX, USBRX); 00040 00041 uint8_t SetStatus(int); 00042 uint8_t SetPWM(int); 00043 00044 #pragma endregion USER-DEFINED_VARIABLES_AND_PROTOTYPE 00045 00046 #ifdef USE_SUBPROCESS 00047 #if USE_PROCESS_NUM>0 00048 static void Process0(void); 00049 #endif 00050 #if USE_PROCESS_NUM>1 00051 static void Process1(void); 00052 #endif 00053 #if USE_PROCESS_NUM>2 00054 static void Process2(void); 00055 #endif 00056 #if USE_PROCESS_NUM>3 00057 static void Process3(void); 00058 #endif 00059 #if USE_PROCESS_NUM>4 00060 static void Process4(void); 00061 #endif 00062 #if USE_PROCESS_NUM>5 00063 static void Process5(void); 00064 #endif 00065 #if USE_PROCESS_NUM>6 00066 static void Process6(void); 00067 #endif 00068 #if USE_PROCESS_NUM>7 00069 static void Process7(void); 00070 #endif 00071 #if USE_PROCESS_NUM>8 00072 static void Process8(void); 00073 #endif 00074 #if USE_PROCESS_NUM>9 00075 static void Process9(void); 00076 #endif 00077 #endif 00078 00079 void SystemProcessInitialize() 00080 { 00081 #pragma region USER-DEFINED_VARIABLE_INIT 00082 /*Replace here with the initialization code of your variables.*/ 00083 00084 #pragma endregion USER-DEFINED_VARIABLE_INIT 00085 00086 lock = true; 00087 processChangeComp = true; 00088 current = DEFAULT_PROCESS; 00089 00090 #ifdef USE_SUBPROCESS 00091 #if USE_PROCESS_NUM>0 00092 Process[0] = Process0; 00093 #endif 00094 #if USE_PROCESS_NUM>1 00095 Process[1] = Process1; 00096 #endif 00097 #if USE_PROCESS_NUM>2 00098 Process[2] = Process2; 00099 #endif 00100 #if USE_PROCESS_NUM>3 00101 Process[3] = Process3; 00102 #endif 00103 #if USE_PROCESS_NUM>4 00104 Process[4] = Process4; 00105 #endif 00106 #if USE_PROCESS_NUM>5 00107 Process[5] = Process5; 00108 #endif 00109 #if USE_PROCESS_NUM>6 00110 Process[6] = Process6; 00111 #endif 00112 #if USE_PROCESS_NUM>7 00113 Process[7] = Process7; 00114 #endif 00115 #if USE_PROCESS_NUM>8 00116 Process[8] = Process8; 00117 #endif 00118 #if USE_PROCESS_NUM>9 00119 Process[9] = Process9; 00120 #endif 00121 #endif 00122 } 00123 00124 static void SystemProcessUpdate() 00125 { 00126 #ifdef USE_SUBPROCESS 00127 if(controller->Button.HOME) lock = false; 00128 00129 if(controller->Button.START && processChangeComp) { 00130 current++; 00131 if (USE_PROCESS_NUM < current) current = USE_PROCESS_NUM; 00132 processChangeComp = false; 00133 } else if(controller->Button.SELECT && processChangeComp) { 00134 current--; 00135 if (current < 0) current = 0; 00136 processChangeComp = false; 00137 } else if(!controller->Button.SELECT && !controller->Button.START) processChangeComp = true; 00138 #endif 00139 00140 #ifdef USE_MOTOR 00141 ACTUATORHUB::MOTOR::Motor::Update(motor); 00142 #endif 00143 00144 #ifdef USE_SOLENOID 00145 ACTUATORHUB::SOLENOID::Solenoid::Update(solenoid); 00146 #endif 00147 00148 #ifdef USE_RS485 00149 ACTUATORHUB::ActuatorHub::Update(); 00150 //LINEHUB::LineHub::Update(); 00151 #endif 00152 00153 } 00154 00155 void SystemProcess() 00156 { 00157 SystemProcessInitialize(); 00158 00159 while(1) { 00160 00161 00162 00163 00164 00165 #ifdef USE_MU 00166 controller = CONTROLLER::Controller::GetData(); 00167 #endif 00168 00169 #ifdef USE_ERRORCHECK 00170 if(SAFTY::ErrorCheck::Check() & SAFTY::Error::ControllerLost) { 00171 CONTROLLER::Controller::DataReset(); 00172 AllActuatorReset(); 00173 lock = true; 00174 } else 00175 #endif 00176 { 00177 00178 #ifdef USE_SUBPROCESS 00179 if(!lock) { 00180 Process[current](); 00181 } else 00182 #endif 00183 { 00184 //ロック時の処理 00185 } 00186 } 00187 00188 SystemProcessUpdate(); 00189 } 00190 } 00191 00192 00193 00194 00195 #pragma region PROCESS 00196 #ifdef USE_SUBPROCESS 00197 #if USE_PROCESS_NUM>0 00198 static void Process0() 00199 { 00200 AllActuatorReset(); 00201 } 00202 #endif 00203 00204 #if USE_PROCESS_NUM>1 00205 static void Process1() 00206 { 00207 00208 } 00209 #endif 00210 00211 #if USE_PROCESS_NUM>2 00212 static void Process2() 00213 { 00214 00215 } 00216 #endif 00217 00218 #if USE_PROCESS_NUM>3 00219 static void Process3() 00220 { 00221 00222 } 00223 #endif 00224 00225 #if USE_PROCESS_NUM>4 00226 static void Process4() 00227 { 00228 00229 } 00230 #endif 00231 00232 #if USE_PROCESS_NUM>5 00233 static void Process5() 00234 { 00235 00236 } 00237 #endif 00238 00239 #if USE_PROCESS_NUM>6 00240 static void Process6() 00241 { 00242 00243 } 00244 #endif 00245 00246 #if USE_PROCESS_NUM>7 00247 static void Process7() 00248 { 00249 00250 } 00251 #endif 00252 00253 #if USE_PROCESS_NUM>8 00254 static void Process8() 00255 { 00256 00257 } 00258 #endif 00259 00260 #if USE_PROCESS_NUM>9 00261 static void Process9() 00262 { 00263 00264 } 00265 #endif 00266 #endif 00267 #pragma endregion PROCESS 00268 00269 static void AllActuatorReset() 00270 { 00271 #ifdef USE_SOLENOID 00272 solenoid.all = ALL_SOLENOID_OFF; 00273 #endif 00274 00275 #ifdef USE_MOTOR 00276 for (uint8_t i = 0; i < MOUNTING_MOTOR_NUM; i++) { 00277 motor[i].dir = FREE; 00278 motor[i].pwm = 0; 00279 } 00280 #endif 00281 } 00282 00283 #pragma region USER-DEFINED-FUNCTIONS 00284 00285 uint8_t SetStatus(int pwmVal) 00286 { 00287 if (pwmVal < 0) return BACK; 00288 else if (pwmVal > 0) return FOR; 00289 else if (pwmVal == 0) return BRAKE; 00290 else return BRAKE; 00291 } 00292 00293 uint8_t SetPWM(int pwmVal) 00294 { 00295 if (pwmVal == 0 || pwmVal > 255 || pwmVal < -255) return 255; 00296 else return abs(pwmVal); 00297 } 00298 00299 #pragma endregion
Generated on Tue Jul 12 2022 18:09:59 by
