da
Dependencies: mbed TrapezoidControl QEI
System/Process/Process.cpp@0:669ef71cba68, 2018-09-08 (annotated)
- Committer:
- t_yamamoto
- Date:
- Sat Sep 08 06:05:22 2018 +0000
- Revision:
- 0:669ef71cba68
- Child:
- 1:b1219d8ca117
???????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
t_yamamoto | 0:669ef71cba68 | 1 | #include "mbed.h" |
t_yamamoto | 0:669ef71cba68 | 2 | #include "Process.h" |
t_yamamoto | 0:669ef71cba68 | 3 | |
t_yamamoto | 0:669ef71cba68 | 4 | #include "../../Communication/RS485/ActuatorHub/ActuatorHub.h" |
t_yamamoto | 0:669ef71cba68 | 5 | #include "../../Communication/Controller/Controller.h" |
t_yamamoto | 0:669ef71cba68 | 6 | #include "../../Input/ExternalInt/ExternalInt.h" |
t_yamamoto | 0:669ef71cba68 | 7 | #include "../../Input/Switch/Switch.h" |
t_yamamoto | 0:669ef71cba68 | 8 | #include "../../Input/Potentiometer/Potentiometer.h" |
t_yamamoto | 0:669ef71cba68 | 9 | #include "../../LED/LED.h" |
t_yamamoto | 0:669ef71cba68 | 10 | #include "../../Safty/Safty.h" |
t_yamamoto | 0:669ef71cba68 | 11 | #include "../Using.h" |
t_yamamoto | 0:669ef71cba68 | 12 | |
t_yamamoto | 0:669ef71cba68 | 13 | using namespace SWITCH; |
t_yamamoto | 0:669ef71cba68 | 14 | |
t_yamamoto | 0:669ef71cba68 | 15 | static CONTROLLER::ControllerData *controller; |
t_yamamoto | 0:669ef71cba68 | 16 | ACTUATORHUB::MOTOR::MotorStatus motor[MOUNTING_MOTOR_NUM]; |
t_yamamoto | 0:669ef71cba68 | 17 | ACTUATORHUB::SOLENOID::SolenoidStatus solenoid; |
t_yamamoto | 0:669ef71cba68 | 18 | |
t_yamamoto | 0:669ef71cba68 | 19 | static bool lock; |
t_yamamoto | 0:669ef71cba68 | 20 | static bool processChangeComp; |
t_yamamoto | 0:669ef71cba68 | 21 | static int current; |
t_yamamoto | 0:669ef71cba68 | 22 | |
t_yamamoto | 0:669ef71cba68 | 23 | static void AllActuatorReset(); |
t_yamamoto | 0:669ef71cba68 | 24 | |
t_yamamoto | 0:669ef71cba68 | 25 | #ifdef USE_SUBPROCESS |
t_yamamoto | 0:669ef71cba68 | 26 | static void (*Process[USE_PROCESS_NUM])(void); |
t_yamamoto | 0:669ef71cba68 | 27 | #endif |
t_yamamoto | 0:669ef71cba68 | 28 | |
t_yamamoto | 0:669ef71cba68 | 29 | #pragma region USER-DEFINED_VARIABLES_AND_PROTOTYPE |
t_yamamoto | 0:669ef71cba68 | 30 | |
t_yamamoto | 0:669ef71cba68 | 31 | /*Replace here with the definition code of your variables.*/ |
t_yamamoto | 0:669ef71cba68 | 32 | |
t_yamamoto | 0:669ef71cba68 | 33 | #pragma endregion USER-DEFINED_VARIABLES_AND_PROTOTYPE |
t_yamamoto | 0:669ef71cba68 | 34 | |
t_yamamoto | 0:669ef71cba68 | 35 | #ifdef USE_SUBPROCESS |
t_yamamoto | 0:669ef71cba68 | 36 | #if USE_PROCESS_NUM>0 |
t_yamamoto | 0:669ef71cba68 | 37 | static void Process0(void); |
t_yamamoto | 0:669ef71cba68 | 38 | #endif |
t_yamamoto | 0:669ef71cba68 | 39 | #if USE_PROCESS_NUM>1 |
t_yamamoto | 0:669ef71cba68 | 40 | static void Process1(void); |
t_yamamoto | 0:669ef71cba68 | 41 | #endif |
t_yamamoto | 0:669ef71cba68 | 42 | #if USE_PROCESS_NUM>2 |
t_yamamoto | 0:669ef71cba68 | 43 | static void Process2(void); |
t_yamamoto | 0:669ef71cba68 | 44 | #endif |
t_yamamoto | 0:669ef71cba68 | 45 | #if USE_PROCESS_NUM>3 |
t_yamamoto | 0:669ef71cba68 | 46 | static void Process3(void); |
t_yamamoto | 0:669ef71cba68 | 47 | #endif |
t_yamamoto | 0:669ef71cba68 | 48 | #if USE_PROCESS_NUM>4 |
t_yamamoto | 0:669ef71cba68 | 49 | static void Process4(void); |
t_yamamoto | 0:669ef71cba68 | 50 | #endif |
t_yamamoto | 0:669ef71cba68 | 51 | #if USE_PROCESS_NUM>5 |
t_yamamoto | 0:669ef71cba68 | 52 | static void Process5(void); |
t_yamamoto | 0:669ef71cba68 | 53 | #endif |
t_yamamoto | 0:669ef71cba68 | 54 | #if USE_PROCESS_NUM>6 |
t_yamamoto | 0:669ef71cba68 | 55 | static void Process6(void); |
t_yamamoto | 0:669ef71cba68 | 56 | #endif |
t_yamamoto | 0:669ef71cba68 | 57 | #if USE_PROCESS_NUM>7 |
t_yamamoto | 0:669ef71cba68 | 58 | static void Process7(void); |
t_yamamoto | 0:669ef71cba68 | 59 | #endif |
t_yamamoto | 0:669ef71cba68 | 60 | #if USE_PROCESS_NUM>8 |
t_yamamoto | 0:669ef71cba68 | 61 | static void Process8(void); |
t_yamamoto | 0:669ef71cba68 | 62 | #endif |
t_yamamoto | 0:669ef71cba68 | 63 | #if USE_PROCESS_NUM>9 |
t_yamamoto | 0:669ef71cba68 | 64 | static void Process9(void); |
t_yamamoto | 0:669ef71cba68 | 65 | #endif |
t_yamamoto | 0:669ef71cba68 | 66 | #endif |
t_yamamoto | 0:669ef71cba68 | 67 | |
t_yamamoto | 0:669ef71cba68 | 68 | void SystemProcessInitialize() |
t_yamamoto | 0:669ef71cba68 | 69 | { |
t_yamamoto | 0:669ef71cba68 | 70 | #pragma region USER-DEFINED_VARIABLE_INIT |
t_yamamoto | 0:669ef71cba68 | 71 | |
t_yamamoto | 0:669ef71cba68 | 72 | /*Replace here with the initialization code of your variables.*/ |
t_yamamoto | 0:669ef71cba68 | 73 | |
t_yamamoto | 0:669ef71cba68 | 74 | #pragma endregion USER-DEFINED_VARIABLE_INIT |
t_yamamoto | 0:669ef71cba68 | 75 | |
t_yamamoto | 0:669ef71cba68 | 76 | lock = true; |
t_yamamoto | 0:669ef71cba68 | 77 | processChangeComp = true; |
t_yamamoto | 0:669ef71cba68 | 78 | current = DEFAULT_PROCESS; |
t_yamamoto | 0:669ef71cba68 | 79 | |
t_yamamoto | 0:669ef71cba68 | 80 | #ifdef USE_SUBPROCESS |
t_yamamoto | 0:669ef71cba68 | 81 | #if USE_PROCESS_NUM>0 |
t_yamamoto | 0:669ef71cba68 | 82 | Process[0] = Process0; |
t_yamamoto | 0:669ef71cba68 | 83 | #endif |
t_yamamoto | 0:669ef71cba68 | 84 | #if USE_PROCESS_NUM>1 |
t_yamamoto | 0:669ef71cba68 | 85 | Process[1] = Process1; |
t_yamamoto | 0:669ef71cba68 | 86 | #endif |
t_yamamoto | 0:669ef71cba68 | 87 | #if USE_PROCESS_NUM>2 |
t_yamamoto | 0:669ef71cba68 | 88 | Process[2] = Process2; |
t_yamamoto | 0:669ef71cba68 | 89 | #endif |
t_yamamoto | 0:669ef71cba68 | 90 | #if USE_PROCESS_NUM>3 |
t_yamamoto | 0:669ef71cba68 | 91 | Process[3] = Process3; |
t_yamamoto | 0:669ef71cba68 | 92 | #endif |
t_yamamoto | 0:669ef71cba68 | 93 | #if USE_PROCESS_NUM>4 |
t_yamamoto | 0:669ef71cba68 | 94 | Process[4] = Process4; |
t_yamamoto | 0:669ef71cba68 | 95 | #endif |
t_yamamoto | 0:669ef71cba68 | 96 | #if USE_PROCESS_NUM>5 |
t_yamamoto | 0:669ef71cba68 | 97 | Process[5] = Process5; |
t_yamamoto | 0:669ef71cba68 | 98 | #endif |
t_yamamoto | 0:669ef71cba68 | 99 | #if USE_PROCESS_NUM>6 |
t_yamamoto | 0:669ef71cba68 | 100 | Process[6] = Process6; |
t_yamamoto | 0:669ef71cba68 | 101 | #endif |
t_yamamoto | 0:669ef71cba68 | 102 | #if USE_PROCESS_NUM>7 |
t_yamamoto | 0:669ef71cba68 | 103 | Process[7] = Process7; |
t_yamamoto | 0:669ef71cba68 | 104 | #endif |
t_yamamoto | 0:669ef71cba68 | 105 | #if USE_PROCESS_NUM>8 |
t_yamamoto | 0:669ef71cba68 | 106 | Process[8] = Process8; |
t_yamamoto | 0:669ef71cba68 | 107 | #endif |
t_yamamoto | 0:669ef71cba68 | 108 | #if USE_PROCESS_NUM>9 |
t_yamamoto | 0:669ef71cba68 | 109 | Process[9] = Process9; |
t_yamamoto | 0:669ef71cba68 | 110 | #endif |
t_yamamoto | 0:669ef71cba68 | 111 | #endif |
t_yamamoto | 0:669ef71cba68 | 112 | } |
t_yamamoto | 0:669ef71cba68 | 113 | |
t_yamamoto | 0:669ef71cba68 | 114 | static void SystemProcessUpdate() |
t_yamamoto | 0:669ef71cba68 | 115 | { |
t_yamamoto | 0:669ef71cba68 | 116 | #ifdef USE_SUBPROCESS |
t_yamamoto | 0:669ef71cba68 | 117 | if(controller->Button.HOME) lock = false; |
t_yamamoto | 0:669ef71cba68 | 118 | |
t_yamamoto | 0:669ef71cba68 | 119 | if(controller->Button.START && processChangeComp) |
t_yamamoto | 0:669ef71cba68 | 120 | { |
t_yamamoto | 0:669ef71cba68 | 121 | current++; |
t_yamamoto | 0:669ef71cba68 | 122 | if (USE_PROCESS_NUM < current) current = USE_PROCESS_NUM; |
t_yamamoto | 0:669ef71cba68 | 123 | processChangeComp = false; |
t_yamamoto | 0:669ef71cba68 | 124 | } |
t_yamamoto | 0:669ef71cba68 | 125 | else if(controller->Button.SELECT && processChangeComp) |
t_yamamoto | 0:669ef71cba68 | 126 | { |
t_yamamoto | 0:669ef71cba68 | 127 | current--; |
t_yamamoto | 0:669ef71cba68 | 128 | if (current < 0) current = 0; |
t_yamamoto | 0:669ef71cba68 | 129 | processChangeComp = false; |
t_yamamoto | 0:669ef71cba68 | 130 | } |
t_yamamoto | 0:669ef71cba68 | 131 | else if(!controller->Button.SELECT && !controller->Button.START) processChangeComp = true; |
t_yamamoto | 0:669ef71cba68 | 132 | #endif |
t_yamamoto | 0:669ef71cba68 | 133 | |
t_yamamoto | 0:669ef71cba68 | 134 | #ifdef USE_MOTOR |
t_yamamoto | 0:669ef71cba68 | 135 | ACTUATORHUB::MOTOR::Motor::Update(motor); |
t_yamamoto | 0:669ef71cba68 | 136 | #endif |
t_yamamoto | 0:669ef71cba68 | 137 | |
t_yamamoto | 0:669ef71cba68 | 138 | #ifdef USE_SOLENOID |
t_yamamoto | 0:669ef71cba68 | 139 | ACTUATORHUB::SOLENOID::Solenoid::Update(solenoid); |
t_yamamoto | 0:669ef71cba68 | 140 | #endif |
t_yamamoto | 0:669ef71cba68 | 141 | |
t_yamamoto | 0:669ef71cba68 | 142 | #ifdef USE_RS485 |
t_yamamoto | 0:669ef71cba68 | 143 | ACTUATORHUB::ActuatorHub::Update(); |
t_yamamoto | 0:669ef71cba68 | 144 | #endif |
t_yamamoto | 0:669ef71cba68 | 145 | |
t_yamamoto | 0:669ef71cba68 | 146 | } |
t_yamamoto | 0:669ef71cba68 | 147 | |
t_yamamoto | 0:669ef71cba68 | 148 | void SystemProcess() |
t_yamamoto | 0:669ef71cba68 | 149 | { |
t_yamamoto | 0:669ef71cba68 | 150 | SystemProcessInitialize(); |
t_yamamoto | 0:669ef71cba68 | 151 | |
t_yamamoto | 0:669ef71cba68 | 152 | while(1) |
t_yamamoto | 0:669ef71cba68 | 153 | { |
t_yamamoto | 0:669ef71cba68 | 154 | #ifdef USE_MU |
t_yamamoto | 0:669ef71cba68 | 155 | controller = CONTROLLER::Controller::GetData(); |
t_yamamoto | 0:669ef71cba68 | 156 | #endif |
t_yamamoto | 0:669ef71cba68 | 157 | |
t_yamamoto | 0:669ef71cba68 | 158 | #ifdef USE_ERRORCHECK |
t_yamamoto | 0:669ef71cba68 | 159 | if(SAFTY::ErrorCheck::Check() & SAFTY::Error::ControllerLost) |
t_yamamoto | 0:669ef71cba68 | 160 | { |
t_yamamoto | 0:669ef71cba68 | 161 | CONTROLLER::Controller::DataReset(); |
t_yamamoto | 0:669ef71cba68 | 162 | AllActuatorReset(); |
t_yamamoto | 0:669ef71cba68 | 163 | lock = true; |
t_yamamoto | 0:669ef71cba68 | 164 | } |
t_yamamoto | 0:669ef71cba68 | 165 | else |
t_yamamoto | 0:669ef71cba68 | 166 | #endif |
t_yamamoto | 0:669ef71cba68 | 167 | { |
t_yamamoto | 0:669ef71cba68 | 168 | |
t_yamamoto | 0:669ef71cba68 | 169 | #ifdef USE_SUBPROCESS |
t_yamamoto | 0:669ef71cba68 | 170 | if(!lock) |
t_yamamoto | 0:669ef71cba68 | 171 | { |
t_yamamoto | 0:669ef71cba68 | 172 | Process[current](); |
t_yamamoto | 0:669ef71cba68 | 173 | } |
t_yamamoto | 0:669ef71cba68 | 174 | else |
t_yamamoto | 0:669ef71cba68 | 175 | #endif |
t_yamamoto | 0:669ef71cba68 | 176 | { |
t_yamamoto | 0:669ef71cba68 | 177 | //ロック時の処理 |
t_yamamoto | 0:669ef71cba68 | 178 | } |
t_yamamoto | 0:669ef71cba68 | 179 | } |
t_yamamoto | 0:669ef71cba68 | 180 | |
t_yamamoto | 0:669ef71cba68 | 181 | SystemProcessUpdate(); |
t_yamamoto | 0:669ef71cba68 | 182 | } |
t_yamamoto | 0:669ef71cba68 | 183 | } |
t_yamamoto | 0:669ef71cba68 | 184 | |
t_yamamoto | 0:669ef71cba68 | 185 | #pragma region PROCESS |
t_yamamoto | 0:669ef71cba68 | 186 | #ifdef USE_SUBPROCESS |
t_yamamoto | 0:669ef71cba68 | 187 | #if USE_PROCESS_NUM>0 |
t_yamamoto | 0:669ef71cba68 | 188 | static void Process0() |
t_yamamoto | 0:669ef71cba68 | 189 | { |
t_yamamoto | 0:669ef71cba68 | 190 | |
t_yamamoto | 0:669ef71cba68 | 191 | } |
t_yamamoto | 0:669ef71cba68 | 192 | #endif |
t_yamamoto | 0:669ef71cba68 | 193 | |
t_yamamoto | 0:669ef71cba68 | 194 | #if USE_PROCESS_NUM>1 |
t_yamamoto | 0:669ef71cba68 | 195 | static void Process1() |
t_yamamoto | 0:669ef71cba68 | 196 | { |
t_yamamoto | 0:669ef71cba68 | 197 | |
t_yamamoto | 0:669ef71cba68 | 198 | } |
t_yamamoto | 0:669ef71cba68 | 199 | #endif |
t_yamamoto | 0:669ef71cba68 | 200 | |
t_yamamoto | 0:669ef71cba68 | 201 | #if USE_PROCESS_NUM>2 |
t_yamamoto | 0:669ef71cba68 | 202 | static void Process2() |
t_yamamoto | 0:669ef71cba68 | 203 | { |
t_yamamoto | 0:669ef71cba68 | 204 | |
t_yamamoto | 0:669ef71cba68 | 205 | } |
t_yamamoto | 0:669ef71cba68 | 206 | #endif |
t_yamamoto | 0:669ef71cba68 | 207 | |
t_yamamoto | 0:669ef71cba68 | 208 | #if USE_PROCESS_NUM>3 |
t_yamamoto | 0:669ef71cba68 | 209 | static void Process3() |
t_yamamoto | 0:669ef71cba68 | 210 | { |
t_yamamoto | 0:669ef71cba68 | 211 | |
t_yamamoto | 0:669ef71cba68 | 212 | } |
t_yamamoto | 0:669ef71cba68 | 213 | #endif |
t_yamamoto | 0:669ef71cba68 | 214 | |
t_yamamoto | 0:669ef71cba68 | 215 | #if USE_PROCESS_NUM>4 |
t_yamamoto | 0:669ef71cba68 | 216 | static void Process4() |
t_yamamoto | 0:669ef71cba68 | 217 | { |
t_yamamoto | 0:669ef71cba68 | 218 | |
t_yamamoto | 0:669ef71cba68 | 219 | } |
t_yamamoto | 0:669ef71cba68 | 220 | #endif |
t_yamamoto | 0:669ef71cba68 | 221 | |
t_yamamoto | 0:669ef71cba68 | 222 | #if USE_PROCESS_NUM>5 |
t_yamamoto | 0:669ef71cba68 | 223 | static void Process5() |
t_yamamoto | 0:669ef71cba68 | 224 | { |
t_yamamoto | 0:669ef71cba68 | 225 | |
t_yamamoto | 0:669ef71cba68 | 226 | } |
t_yamamoto | 0:669ef71cba68 | 227 | #endif |
t_yamamoto | 0:669ef71cba68 | 228 | |
t_yamamoto | 0:669ef71cba68 | 229 | #if USE_PROCESS_NUM>6 |
t_yamamoto | 0:669ef71cba68 | 230 | static void Process6() |
t_yamamoto | 0:669ef71cba68 | 231 | { |
t_yamamoto | 0:669ef71cba68 | 232 | |
t_yamamoto | 0:669ef71cba68 | 233 | } |
t_yamamoto | 0:669ef71cba68 | 234 | #endif |
t_yamamoto | 0:669ef71cba68 | 235 | |
t_yamamoto | 0:669ef71cba68 | 236 | #if USE_PROCESS_NUM>7 |
t_yamamoto | 0:669ef71cba68 | 237 | static void Process7() |
t_yamamoto | 0:669ef71cba68 | 238 | { |
t_yamamoto | 0:669ef71cba68 | 239 | |
t_yamamoto | 0:669ef71cba68 | 240 | } |
t_yamamoto | 0:669ef71cba68 | 241 | #endif |
t_yamamoto | 0:669ef71cba68 | 242 | |
t_yamamoto | 0:669ef71cba68 | 243 | #if USE_PROCESS_NUM>8 |
t_yamamoto | 0:669ef71cba68 | 244 | static void Process8() |
t_yamamoto | 0:669ef71cba68 | 245 | { |
t_yamamoto | 0:669ef71cba68 | 246 | |
t_yamamoto | 0:669ef71cba68 | 247 | } |
t_yamamoto | 0:669ef71cba68 | 248 | #endif |
t_yamamoto | 0:669ef71cba68 | 249 | |
t_yamamoto | 0:669ef71cba68 | 250 | #if USE_PROCESS_NUM>9 |
t_yamamoto | 0:669ef71cba68 | 251 | static void Process9() |
t_yamamoto | 0:669ef71cba68 | 252 | { |
t_yamamoto | 0:669ef71cba68 | 253 | |
t_yamamoto | 0:669ef71cba68 | 254 | } |
t_yamamoto | 0:669ef71cba68 | 255 | #endif |
t_yamamoto | 0:669ef71cba68 | 256 | #endif |
t_yamamoto | 0:669ef71cba68 | 257 | #pragma endregion PROCESS |
t_yamamoto | 0:669ef71cba68 | 258 | |
t_yamamoto | 0:669ef71cba68 | 259 | static void AllActuatorReset() |
t_yamamoto | 0:669ef71cba68 | 260 | { |
t_yamamoto | 0:669ef71cba68 | 261 | |
t_yamamoto | 0:669ef71cba68 | 262 | #ifdef USE_SOLENOID |
t_yamamoto | 0:669ef71cba68 | 263 | solenoid.all = ALL_SOLENOID_OFF; |
t_yamamoto | 0:669ef71cba68 | 264 | #endif |
t_yamamoto | 0:669ef71cba68 | 265 | |
t_yamamoto | 0:669ef71cba68 | 266 | #ifdef USE_MOTOR |
t_yamamoto | 0:669ef71cba68 | 267 | for (uint8_t i = 0; i < MOUNTING_MOTOR_NUM; i++) |
t_yamamoto | 0:669ef71cba68 | 268 | { |
t_yamamoto | 0:669ef71cba68 | 269 | motor[i].dir = FREE; |
t_yamamoto | 0:669ef71cba68 | 270 | motor[i].pwm = 0; |
t_yamamoto | 0:669ef71cba68 | 271 | } |
t_yamamoto | 0:669ef71cba68 | 272 | #endif |
t_yamamoto | 0:669ef71cba68 | 273 | } |
t_yamamoto | 0:669ef71cba68 | 274 | |
t_yamamoto | 0:669ef71cba68 | 275 | #pragma region USER-DEFINED-FUNCTIONS |
t_yamamoto | 0:669ef71cba68 | 276 | |
t_yamamoto | 0:669ef71cba68 | 277 | #pragma endregion |