aa

Dependencies:   mbed

Committer:
7ka884
Date:
Mon Sep 10 01:39:15 2018 +0000
Revision:
1:b1219d8ca117
Parent:
0:669ef71cba68
Child:
2:c015739085d3
A

Who changed what in which revision?

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