Version 16 Working

Dependencies:   mbed mbed-rtos TextLCD

Committer:
thomasmorris
Date:
Tue Feb 19 14:40:01 2019 +0000
Revision:
26:83550fc299aa
Parent:
25:9751619fa030
Child:
28:3193157ebb0c
Working code (needs stepper motor and mosfet output checking

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thomasmorris 23:07a368f2cdb1 1 #include "Interface.hpp" //Include the header file, this acts like a series of forward declarations
thomasmorris 16:9f98ec0ededb 2 //Constructor
thomasmorris 25:9751619fa030 3 INTERFACE::INTERFACE(){}//Set all values to 0
thomasmorris 16:9f98ec0ededb 4 INTERFACE::~INTERFACE(){} //Destructor
thomasmorris 17:68b3fdabe4c5 5 void INTERFACE::Interface_Init()//Set all values to 0 bar the default turns
thomasmorris 16:9f98ec0ededb 6 {
thomasmorris 24:728de4bf961e 7 Led_Select_Left_mutex.lock();
thomasmorris 24:728de4bf961e 8 Led_Select_Left = 0;
thomasmorris 24:728de4bf961e 9 Led_Select_Left_mutex.unlock();
thomasmorris 24:728de4bf961e 10
thomasmorris 24:728de4bf961e 11 Led_Select_Right_mutex.lock();
thomasmorris 24:728de4bf961e 12 Led_Select_Right= 0;
thomasmorris 24:728de4bf961e 13 Led_Select_Right_mutex.unlock();
thomasmorris 24:728de4bf961e 14
thomasmorris 23:07a368f2cdb1 15 _Function_mutex.lock();
thomasmorris 26:83550fc299aa 16 _Function = Type_of_Rig;
thomasmorris 23:07a368f2cdb1 17 _Function_mutex.unlock();
thomasmorris 23:07a368f2cdb1 18
thomasmorris 23:07a368f2cdb1 19 _Twist_Go_mutex.lock();
thomasmorris 17:68b3fdabe4c5 20 _Twist_Go =0;
thomasmorris 23:07a368f2cdb1 21 _Twist_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 22
thomasmorris 23:07a368f2cdb1 23 _Anneal_Go_mutex.lock();
thomasmorris 17:68b3fdabe4c5 24 _Anneal_Go =0;
thomasmorris 23:07a368f2cdb1 25 _Anneal_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 26
thomasmorris 23:07a368f2cdb1 27 _Test_Go_mutex.lock();
thomasmorris 17:68b3fdabe4c5 28 _Test_Go =0;
thomasmorris 23:07a368f2cdb1 29 _Test_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 30
thomasmorris 23:07a368f2cdb1 31 _Select_mutex.lock();
thomasmorris 17:68b3fdabe4c5 32 _Select =0;
thomasmorris 23:07a368f2cdb1 33 _Select_mutex.unlock();
thomasmorris 23:07a368f2cdb1 34
thomasmorris 23:07a368f2cdb1 35 _Turns_Done_mutex.lock();
thomasmorris 17:68b3fdabe4c5 36 _Turns_Done =0;
thomasmorris 23:07a368f2cdb1 37 _Turns_Done_mutex.unlock();
thomasmorris 23:07a368f2cdb1 38
thomasmorris 23:07a368f2cdb1 39 _Loop_mutex.lock();
thomasmorris 25:9751619fa030 40 _Loop =6;
thomasmorris 23:07a368f2cdb1 41 _Loop_mutex.unlock();
thomasmorris 23:07a368f2cdb1 42
thomasmorris 25:9751619fa030 43 _On_Time_mutex.lock();
thomasmorris 25:9751619fa030 44 _On_Time =6;
thomasmorris 25:9751619fa030 45 _On_Time_mutex.unlock();
thomasmorris 25:9751619fa030 46
thomasmorris 25:9751619fa030 47 _Off_Time_mutex.lock();
thomasmorris 25:9751619fa030 48 _Off_Time =6;
thomasmorris 25:9751619fa030 49 _Off_Time_mutex.unlock();
thomasmorris 23:07a368f2cdb1 50
thomasmorris 23:07a368f2cdb1 51 _Duty_Cycle_mutex.lock();
thomasmorris 17:68b3fdabe4c5 52 _Duty_Cycle =0;
thomasmorris 23:07a368f2cdb1 53 _Duty_Cycle_mutex.unlock();
thomasmorris 23:07a368f2cdb1 54
thomasmorris 23:07a368f2cdb1 55 _Power_Time_mutex.lock();
thomasmorris 17:68b3fdabe4c5 56 _Power_Time =0;
thomasmorris 23:07a368f2cdb1 57 _Power_Time_mutex.unlock();
thomasmorris 23:07a368f2cdb1 58
thomasmorris 23:07a368f2cdb1 59 Led_Select_Left_mutex.lock();
thomasmorris 23:07a368f2cdb1 60 Led_Select_Left = 0;
thomasmorris 23:07a368f2cdb1 61 Led_Select_Left_mutex.unlock();
thomasmorris 23:07a368f2cdb1 62
thomasmorris 23:07a368f2cdb1 63 Led_Select_Right_mutex.lock();
thomasmorris 23:07a368f2cdb1 64 Led_Select_Right= 0;
thomasmorris 23:07a368f2cdb1 65 Led_Select_Right_mutex.unlock();
thomasmorris 23:07a368f2cdb1 66
thomasmorris 23:07a368f2cdb1 67 Led_Power_mutex.lock();
thomasmorris 23:07a368f2cdb1 68 Led_Power =0;
thomasmorris 23:07a368f2cdb1 69 Led_Power_mutex.unlock();
thomasmorris 23:07a368f2cdb1 70
thomasmorris 23:07a368f2cdb1 71 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 72 _System_Running =0;
thomasmorris 23:07a368f2cdb1 73 _System_Running_mutex.unlock();
thomasmorris 24:728de4bf961e 74
thomasmorris 24:728de4bf961e 75
thomasmorris 26:83550fc299aa 76 Led_Select_Left_mutex.lock();
thomasmorris 26:83550fc299aa 77 Led_Select_Left = 0;
thomasmorris 26:83550fc299aa 78 Led_Select_Left_mutex.unlock();
thomasmorris 24:728de4bf961e 79
thomasmorris 26:83550fc299aa 80 Led_Select_Right_mutex.lock();
thomasmorris 26:83550fc299aa 81 Led_Select_Right= 1;
thomasmorris 26:83550fc299aa 82 Led_Select_Right_mutex.unlock();
thomasmorris 26:83550fc299aa 83
thomasmorris 26:83550fc299aa 84 _Turns_Todo_mutex.lock();
thomasmorris 26:83550fc299aa 85 if(Type_of_Rig == 2)
thomasmorris 26:83550fc299aa 86 {
thomasmorris 26:83550fc299aa 87 _Turns_Todo = Default_Coiling_Turns;
thomasmorris 26:83550fc299aa 88 }
thomasmorris 26:83550fc299aa 89 else if(Type_of_Rig == 3)
thomasmorris 26:83550fc299aa 90 {
thomasmorris 26:83550fc299aa 91 _Turns_Todo = Default_Twisting_Turns;
thomasmorris 26:83550fc299aa 92 }
thomasmorris 26:83550fc299aa 93 _Turns_Todo_mutex.unlock();
thomasmorris 16:9f98ec0ededb 94 }
thomasmorris 17:68b3fdabe4c5 95 void INTERFACE::Up()//Up Routine
thomasmorris 16:9f98ec0ededb 96 {
thomasmorris 26:83550fc299aa 97 printf("In up routine\n");
thomasmorris 26:83550fc299aa 98 printf("Function value is: %d\n",_Function);
thomasmorris 26:83550fc299aa 99 printf("Select Value is :%d\n",_Select);
thomasmorris 25:9751619fa030 100 if (_Function == 2 || _Function == 3 )//Coiling or twist Function
thomasmorris 16:9f98ec0ededb 101 {
thomasmorris 23:07a368f2cdb1 102 _Turns_Todo_mutex.lock();
thomasmorris 26:83550fc299aa 103 _Turns_Todo = _Turns_Todo +1;
thomasmorris 23:07a368f2cdb1 104 _Turns_Todo_mutex.unlock();
thomasmorris 16:9f98ec0ededb 105 }
thomasmorris 25:9751619fa030 106 else if (_Function == 0)//Annealing Function
thomasmorris 16:9f98ec0ededb 107 {
thomasmorris 25:9751619fa030 108 if (_Select == 0)//Select = 0
thomasmorris 23:07a368f2cdb1 109 {
thomasmorris 26:83550fc299aa 110 if(_On_Time > 0)
thomasmorris 26:83550fc299aa 111 {
thomasmorris 26:83550fc299aa 112 _On_Time_mutex.lock();
thomasmorris 26:83550fc299aa 113 _On_Time = _On_Time+ 1; //Increments On time
thomasmorris 26:83550fc299aa 114 _On_Time_mutex.unlock();
thomasmorris 26:83550fc299aa 115 }
thomasmorris 16:9f98ec0ededb 116 }
thomasmorris 25:9751619fa030 117 else if (_Select == 1)//Select = 1
thomasmorris 16:9f98ec0ededb 118 {
thomasmorris 26:83550fc299aa 119 if(_Loop > 0)
thomasmorris 26:83550fc299aa 120 {
thomasmorris 26:83550fc299aa 121 _Loop_mutex.lock();
thomasmorris 26:83550fc299aa 122 _Loop = _Loop + 1; //Increments Repetitions in Annealing
thomasmorris 26:83550fc299aa 123 _Loop_mutex.unlock();
thomasmorris 26:83550fc299aa 124 }
thomasmorris 25:9751619fa030 125 }
thomasmorris 26:83550fc299aa 126 else if (_Select == 2)//Select = 2
thomasmorris 25:9751619fa030 127 {
thomasmorris 26:83550fc299aa 128 if(_Off_Time > 0)
thomasmorris 26:83550fc299aa 129 {
thomasmorris 26:83550fc299aa 130 _Off_Time_mutex.lock();
thomasmorris 26:83550fc299aa 131 _Off_Time = _Off_Time + 1; //Increments Off time
thomasmorris 26:83550fc299aa 132 _Off_Time_mutex.unlock();
thomasmorris 26:83550fc299aa 133 }
thomasmorris 16:9f98ec0ededb 134 }
thomasmorris 16:9f98ec0ededb 135 }
thomasmorris 25:9751619fa030 136 else if (_Function == 1)//Test Function
thomasmorris 16:9f98ec0ededb 137 {
thomasmorris 26:83550fc299aa 138 if (_Select == 1)//Select = 1
thomasmorris 16:9f98ec0ededb 139 {
thomasmorris 16:9f98ec0ededb 140 if (_Duty_Cycle < 100)
thomasmorris 16:9f98ec0ededb 141 {
thomasmorris 23:07a368f2cdb1 142 _Duty_Cycle_mutex.lock();
thomasmorris 16:9f98ec0ededb 143 _Duty_Cycle = _Duty_Cycle + 10; //Increases Testing Duty Cycle
thomasmorris 23:07a368f2cdb1 144 _Duty_Cycle_mutex.unlock();
thomasmorris 16:9f98ec0ededb 145 }
thomasmorris 24:728de4bf961e 146 }
thomasmorris 26:83550fc299aa 147 else if (_Select == 0)//Select = 0
thomasmorris 24:728de4bf961e 148 {
thomasmorris 24:728de4bf961e 149 _Power_Time_mutex.lock();
thomasmorris 24:728de4bf961e 150 _Power_Time = _Power_Time + 1; //Increases time on
thomasmorris 24:728de4bf961e 151 _Power_Time_mutex.unlock();
thomasmorris 16:9f98ec0ededb 152 }
thomasmorris 16:9f98ec0ededb 153 }
thomasmorris 16:9f98ec0ededb 154 }
thomasmorris 17:68b3fdabe4c5 155 void INTERFACE::Down()//Down Routine
thomasmorris 16:9f98ec0ededb 156 {
thomasmorris 25:9751619fa030 157 if (_Function == 2 || _Function == 3)//Coiling or twist Function
thomasmorris 25:9751619fa030 158 {
thomasmorris 23:07a368f2cdb1 159 _Turns_Todo_mutex.lock();
thomasmorris 26:83550fc299aa 160 _Turns_Todo = _Turns_Todo -1;
thomasmorris 23:07a368f2cdb1 161 _Turns_Todo_mutex.unlock();
thomasmorris 16:9f98ec0ededb 162 }
thomasmorris 26:83550fc299aa 163 else if (_Function == 0)//Annealing Function
thomasmorris 16:9f98ec0ededb 164 {
thomasmorris 25:9751619fa030 165 if (_Select == 0)//Select = 0
thomasmorris 26:83550fc299aa 166 {
thomasmorris 26:83550fc299aa 167 if(_On_Time > 1)
thomasmorris 16:9f98ec0ededb 168 {
thomasmorris 26:83550fc299aa 169 _On_Time_mutex.lock();
thomasmorris 26:83550fc299aa 170 _On_Time = _On_Time - 1; //Decrements On time
thomasmorris 26:83550fc299aa 171 _On_Time_mutex.unlock();
thomasmorris 16:9f98ec0ededb 172 }
thomasmorris 24:728de4bf961e 173 }
thomasmorris 25:9751619fa030 174 else if (_Select == 1)//Select = 1
thomasmorris 24:728de4bf961e 175 {
thomasmorris 26:83550fc299aa 176 if(_Loop > 1)
thomasmorris 26:83550fc299aa 177 {
thomasmorris 26:83550fc299aa 178 _Loop_mutex.lock();
thomasmorris 26:83550fc299aa 179 _Loop = _Loop - 1; //Decrements Repetitions in Annealing
thomasmorris 26:83550fc299aa 180 _Loop_mutex.unlock();
thomasmorris 26:83550fc299aa 181 }
thomasmorris 25:9751619fa030 182 }
thomasmorris 26:83550fc299aa 183 else if (_Select == 2)//Select = 2
thomasmorris 25:9751619fa030 184 {
thomasmorris 26:83550fc299aa 185 if(_Off_Time > 1)
thomasmorris 26:83550fc299aa 186 {
thomasmorris 26:83550fc299aa 187 _Off_Time_mutex.lock();
thomasmorris 26:83550fc299aa 188 _Off_Time = _Off_Time - 1; //Decrements Off time
thomasmorris 26:83550fc299aa 189 _Off_Time_mutex.unlock();
thomasmorris 26:83550fc299aa 190 }
thomasmorris 16:9f98ec0ededb 191 }
thomasmorris 16:9f98ec0ededb 192 }
thomasmorris 25:9751619fa030 193 else if (_Function == 1)//Test Function
thomasmorris 16:9f98ec0ededb 194 {
thomasmorris 26:83550fc299aa 195 if (_Select == 1)//Select = 1
thomasmorris 16:9f98ec0ededb 196 {
thomasmorris 16:9f98ec0ededb 197 if (_Duty_Cycle > 0)
thomasmorris 16:9f98ec0ededb 198 {
thomasmorris 23:07a368f2cdb1 199 _Duty_Cycle_mutex.lock();
thomasmorris 16:9f98ec0ededb 200 _Duty_Cycle = _Duty_Cycle - 10; //Decreases duty
thomasmorris 23:07a368f2cdb1 201 _Duty_Cycle_mutex.unlock();
thomasmorris 16:9f98ec0ededb 202 }
thomasmorris 24:728de4bf961e 203 }
thomasmorris 26:83550fc299aa 204 else if (_Select == 0)//Select = 0
thomasmorris 24:728de4bf961e 205 {
thomasmorris 24:728de4bf961e 206 if (_Power_Time > 0)
thomasmorris 16:9f98ec0ededb 207 {
thomasmorris 24:728de4bf961e 208 _Power_Time_mutex.lock();
thomasmorris 24:728de4bf961e 209 _Power_Time = _Power_Time - 1; //Decreases Time on
thomasmorris 24:728de4bf961e 210 _Power_Time_mutex.unlock();
thomasmorris 16:9f98ec0ededb 211 }
thomasmorris 16:9f98ec0ededb 212 }
thomasmorris 16:9f98ec0ededb 213 }
thomasmorris 16:9f98ec0ededb 214 }
thomasmorris 17:68b3fdabe4c5 215 void INTERFACE::Start_Stop()//Start / Stop Routine
thomasmorris 16:9f98ec0ededb 216 {
thomasmorris 24:728de4bf961e 217 if(_System_Running != 2)
thomasmorris 24:728de4bf961e 218 {
thomasmorris 24:728de4bf961e 219 _System_Running = !_System_Running;
thomasmorris 24:728de4bf961e 220 }
thomasmorris 23:07a368f2cdb1 221 //System not running cases (START)
thomasmorris 24:728de4bf961e 222 printf("Function is: %d, System is: %d\n",_Function,_System_Running);
thomasmorris 24:728de4bf961e 223
thomasmorris 24:728de4bf961e 224 //System Running cases (Unpause)
thomasmorris 25:9751619fa030 225 if ((_Function == 2 || _Function == 3) & _System_Running == 2)//Coil Twist selected to be unpaused
thomasmorris 23:07a368f2cdb1 226 {
thomasmorris 24:728de4bf961e 227 _Twist_Stop_mutex.lock();
thomasmorris 24:728de4bf961e 228 _Twist_Stop = false;
thomasmorris 24:728de4bf961e 229 _Twist_Stop_mutex.unlock();
thomasmorris 24:728de4bf961e 230
thomasmorris 23:07a368f2cdb1 231 _Twist_Go_mutex.lock();
thomasmorris 23:07a368f2cdb1 232 _Twist_Go = true;//toggle used for coiling and twisting and Running the code
thomasmorris 23:07a368f2cdb1 233 _Twist_Go_mutex.unlock();
thomasmorris 24:728de4bf961e 234
thomasmorris 24:728de4bf961e 235 STEPPER_MOTOR_1.Unpause_Code();
thomasmorris 24:728de4bf961e 236
thomasmorris 25:9751619fa030 237 if(_Function == 2)//Coiling
thomasmorris 25:9751619fa030 238 {
thomasmorris 25:9751619fa030 239 printf("Coiling Code unpaused\n");
thomasmorris 25:9751619fa030 240 }
thomasmorris 25:9751619fa030 241 if(_Function == 3)//Twisiting
thomasmorris 25:9751619fa030 242 {
thomasmorris 25:9751619fa030 243 printf("Twisting Code unpaused\n");
thomasmorris 25:9751619fa030 244 }
thomasmorris 24:728de4bf961e 245 _System_Running = 0;
thomasmorris 24:728de4bf961e 246
thomasmorris 23:07a368f2cdb1 247 }
thomasmorris 25:9751619fa030 248 else if (_Function == 0 & _System_Running == 2) //Annealing selected to be unpaused
thomasmorris 23:07a368f2cdb1 249 {
thomasmorris 24:728de4bf961e 250 _Anneal_Stop_mutex.lock();
thomasmorris 24:728de4bf961e 251 _Anneal_Stop = false;
thomasmorris 24:728de4bf961e 252 _Anneal_Stop_mutex.unlock();
thomasmorris 24:728de4bf961e 253 printf("Annealing Code unpaused\n");
thomasmorris 24:728de4bf961e 254
thomasmorris 23:07a368f2cdb1 255 _Anneal_Go_mutex.lock();
thomasmorris 23:07a368f2cdb1 256 _Anneal_Go = true;//toggle and Run the code
thomasmorris 23:07a368f2cdb1 257 _Anneal_Go_mutex.unlock();
thomasmorris 24:728de4bf961e 258 _System_Running = 0;
thomasmorris 23:07a368f2cdb1 259 }
thomasmorris 25:9751619fa030 260 else if (_Function == 1 & _System_Running == 2) //Testing selected to be re run
thomasmorris 16:9f98ec0ededb 261 {
thomasmorris 24:728de4bf961e 262 _Test_Stop_mutex.lock();
thomasmorris 24:728de4bf961e 263 _Test_Stop = false;
thomasmorris 24:728de4bf961e 264 _Test_Stop_mutex.unlock();
thomasmorris 24:728de4bf961e 265 printf("Testing Code unpaused\n");
thomasmorris 23:07a368f2cdb1 266 _Test_Go_mutex.lock();
thomasmorris 23:07a368f2cdb1 267 _Test_Go = true;//toggle and run the code
thomasmorris 23:07a368f2cdb1 268 _Test_Go_mutex.unlock();
thomasmorris 24:728de4bf961e 269 _System_Running = 0;
thomasmorris 24:728de4bf961e 270
thomasmorris 16:9f98ec0ededb 271 }
thomasmorris 23:07a368f2cdb1 272 //System Running cases (STOP)
thomasmorris 25:9751619fa030 273 else if ((_Function == 2 || _Function == 3) & _System_Running == 1)//Coiling / Twisting selected to be stopped
thomasmorris 23:07a368f2cdb1 274 {
thomasmorris 23:07a368f2cdb1 275 _Twist_Stop_mutex.lock();
thomasmorris 23:07a368f2cdb1 276 _Twist_Stop = true;
thomasmorris 23:07a368f2cdb1 277 _Twist_Stop_mutex.unlock();
thomasmorris 25:9751619fa030 278
thomasmorris 25:9751619fa030 279 if(_Function == 2)
thomasmorris 25:9751619fa030 280 {
thomasmorris 25:9751619fa030 281 printf("Coiling Code Paused\n");
thomasmorris 25:9751619fa030 282 }
thomasmorris 25:9751619fa030 283 if(_Function == 3)
thomasmorris 25:9751619fa030 284 {
thomasmorris 25:9751619fa030 285 printf("Twisting Code Paused\n");
thomasmorris 25:9751619fa030 286 }
thomasmorris 23:07a368f2cdb1 287 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 288 _System_Running = 2;
thomasmorris 23:07a368f2cdb1 289 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 290 STEPPER_MOTOR_1.Pause_Code();
thomasmorris 23:07a368f2cdb1 291 }
thomasmorris 25:9751619fa030 292 else if (_Function == 0 & _System_Running == 1) //Annealing selected to be stopped
thomasmorris 23:07a368f2cdb1 293 {
thomasmorris 23:07a368f2cdb1 294 _Anneal_Stop_mutex.lock();
thomasmorris 23:07a368f2cdb1 295 _Anneal_Stop = true;
thomasmorris 23:07a368f2cdb1 296 _Anneal_Stop_mutex.unlock();
thomasmorris 23:07a368f2cdb1 297 printf("Annealing Code Paused\n");
thomasmorris 23:07a368f2cdb1 298 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 299 _System_Running = 2;
thomasmorris 23:07a368f2cdb1 300 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 301 }
thomasmorris 25:9751619fa030 302 else if (_Function == 1 & _System_Running == 1) //Testing selected to be stopped
thomasmorris 16:9f98ec0ededb 303 {
thomasmorris 23:07a368f2cdb1 304 _Test_Stop_mutex.lock();
thomasmorris 23:07a368f2cdb1 305 _Test_Stop = true;
thomasmorris 23:07a368f2cdb1 306 _Test_Stop_mutex.unlock();
thomasmorris 24:728de4bf961e 307
thomasmorris 23:07a368f2cdb1 308 printf("Testing Code Paused\n");
thomasmorris 24:728de4bf961e 309
thomasmorris 23:07a368f2cdb1 310 _Tendon_mutex.lock();
thomasmorris 23:07a368f2cdb1 311 Tendon_Power=0;
thomasmorris 23:07a368f2cdb1 312 _Tendon_mutex.unlock();
thomasmorris 23:07a368f2cdb1 313
thomasmorris 23:07a368f2cdb1 314 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 315 _System_Running = 2;
thomasmorris 23:07a368f2cdb1 316 _System_Running_mutex.unlock();
thomasmorris 16:9f98ec0ededb 317 }
thomasmorris 24:728de4bf961e 318 //Start Cases
thomasmorris 25:9751619fa030 319 else if ((_Function == 2 || _Function == 3) & _System_Running == 0)//Twist selected
thomasmorris 23:07a368f2cdb1 320 {
thomasmorris 23:07a368f2cdb1 321 _Twist_Go_mutex.lock();
thomasmorris 23:07a368f2cdb1 322 _Twist_Go = true;//toggle used for coiling and twisting and Running the code
thomasmorris 23:07a368f2cdb1 323 _Twist_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 324 }
thomasmorris 25:9751619fa030 325 else if (_Function == 0 & _System_Running == 0) //Annealing selected
thomasmorris 16:9f98ec0ededb 326 {
thomasmorris 23:07a368f2cdb1 327 _Anneal_Go_mutex.lock();
thomasmorris 23:07a368f2cdb1 328 _Anneal_Go = true;//toggle and Run the code
thomasmorris 23:07a368f2cdb1 329 _Anneal_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 330 }
thomasmorris 25:9751619fa030 331 else if (_Function == 1 & _System_Running == 0) //Testing selected
thomasmorris 23:07a368f2cdb1 332 {
thomasmorris 23:07a368f2cdb1 333 _Test_Go_mutex.lock();
thomasmorris 23:07a368f2cdb1 334 _Test_Go = true;//toggle and run the code
thomasmorris 23:07a368f2cdb1 335 _Test_Go_mutex.unlock();
thomasmorris 16:9f98ec0ededb 336 }
thomasmorris 16:9f98ec0ededb 337 }
thomasmorris 17:68b3fdabe4c5 338 void INTERFACE::Function()//Function Routine used to increment through the three functions
thomasmorris 16:9f98ec0ededb 339 {
thomasmorris 17:68b3fdabe4c5 340 /*
thomasmorris 25:9751619fa030 341 Function 0 = Anneal
thomasmorris 25:9751619fa030 342 Function 1 = Test
thomasmorris 25:9751619fa030 343 Function 2 = Coiling
thomasmorris 25:9751619fa030 344 Function 3 = Twisting
thomasmorris 17:68b3fdabe4c5 345 */
thomasmorris 26:83550fc299aa 346 if(Type_of_Rig == 3)
thomasmorris 26:83550fc299aa 347 {
thomasmorris 26:83550fc299aa 348 if(_Function < 3)
thomasmorris 26:83550fc299aa 349 {
thomasmorris 26:83550fc299aa 350 if(_Function == 1)//Skip coiling
thomasmorris 26:83550fc299aa 351 {
thomasmorris 26:83550fc299aa 352 _Function_mutex.lock();
thomasmorris 26:83550fc299aa 353 _Function = _Function + 1;
thomasmorris 26:83550fc299aa 354 _Function_mutex.unlock();
thomasmorris 26:83550fc299aa 355 }
thomasmorris 26:83550fc299aa 356 _Function_mutex.lock();
thomasmorris 26:83550fc299aa 357 _Function = _Function + 1;
thomasmorris 26:83550fc299aa 358 _Function_mutex.unlock();
thomasmorris 26:83550fc299aa 359 }
thomasmorris 26:83550fc299aa 360 else if(_Function == 3)
thomasmorris 26:83550fc299aa 361 {
thomasmorris 26:83550fc299aa 362 _Function = 0;
thomasmorris 26:83550fc299aa 363 }
thomasmorris 26:83550fc299aa 364 }
thomasmorris 25:9751619fa030 365 if(Type_of_Rig == 2)
thomasmorris 25:9751619fa030 366 {
thomasmorris 25:9751619fa030 367 if(_Function < 2)
thomasmorris 25:9751619fa030 368 {
thomasmorris 25:9751619fa030 369 _Function_mutex.lock();
thomasmorris 26:83550fc299aa 370 _Function = _Function + 1;
thomasmorris 26:83550fc299aa 371 _Function_mutex.unlock();
thomasmorris 25:9751619fa030 372 }
thomasmorris 25:9751619fa030 373 else if(_Function == 2)
thomasmorris 25:9751619fa030 374 {
thomasmorris 26:83550fc299aa 375 _Function = 0;
thomasmorris 25:9751619fa030 376 }
thomasmorris 16:9f98ec0ededb 377 }
thomasmorris 16:9f98ec0ededb 378 }
thomasmorris 17:68b3fdabe4c5 379 void INTERFACE::Select()//Select Routine
thomasmorris 16:9f98ec0ededb 380 {
thomasmorris 23:07a368f2cdb1 381 _Select_mutex.lock();
thomasmorris 26:83550fc299aa 382 if(_Function == 0)//Anneal
thomasmorris 25:9751619fa030 383 {
thomasmorris 26:83550fc299aa 384 printf("Select Value is :%d\n",_Select);
thomasmorris 26:83550fc299aa 385 if(_Select == 2)
thomasmorris 26:83550fc299aa 386 {
thomasmorris 26:83550fc299aa 387 _Select = 0;
thomasmorris 26:83550fc299aa 388 }
thomasmorris 26:83550fc299aa 389 else if(_Select == 1)
thomasmorris 26:83550fc299aa 390 {
thomasmorris 26:83550fc299aa 391 _Select = 2;
thomasmorris 26:83550fc299aa 392 }
thomasmorris 26:83550fc299aa 393 else if(_Select == 0)
thomasmorris 26:83550fc299aa 394 {
thomasmorris 26:83550fc299aa 395 _Select = 1;
thomasmorris 26:83550fc299aa 396 }
thomasmorris 26:83550fc299aa 397 if(_Select == 0 || _Select == 2)
thomasmorris 26:83550fc299aa 398 {
thomasmorris 26:83550fc299aa 399 Led_Select_Left_mutex.lock();
thomasmorris 26:83550fc299aa 400 Led_Select_Left = 0;
thomasmorris 26:83550fc299aa 401 Led_Select_Left_mutex.unlock();
thomasmorris 26:83550fc299aa 402
thomasmorris 26:83550fc299aa 403 Led_Select_Right_mutex.lock();
thomasmorris 26:83550fc299aa 404 Led_Select_Right= 1;
thomasmorris 26:83550fc299aa 405 Led_Select_Right_mutex.unlock();
thomasmorris 26:83550fc299aa 406 }
thomasmorris 26:83550fc299aa 407 else if(_Select == 1)
thomasmorris 26:83550fc299aa 408 {
thomasmorris 26:83550fc299aa 409 Led_Select_Left_mutex.lock();
thomasmorris 26:83550fc299aa 410 Led_Select_Left = 1;
thomasmorris 26:83550fc299aa 411 Led_Select_Left_mutex.unlock();
thomasmorris 26:83550fc299aa 412
thomasmorris 26:83550fc299aa 413 Led_Select_Right_mutex.lock();
thomasmorris 26:83550fc299aa 414 Led_Select_Right= 0;
thomasmorris 26:83550fc299aa 415 Led_Select_Right_mutex.unlock();
thomasmorris 26:83550fc299aa 416 }
thomasmorris 26:83550fc299aa 417 printf("Select Value is :%d\n",_Select);
thomasmorris 25:9751619fa030 418 }
thomasmorris 26:83550fc299aa 419 else if(_Function == 1)//Test
thomasmorris 23:07a368f2cdb1 420 {
thomasmorris 26:83550fc299aa 421 if(_Select == 0)
thomasmorris 26:83550fc299aa 422 {
thomasmorris 26:83550fc299aa 423 _Select = 1;
thomasmorris 26:83550fc299aa 424 }
thomasmorris 26:83550fc299aa 425 else if(_Select == 1)
thomasmorris 26:83550fc299aa 426 {
thomasmorris 26:83550fc299aa 427 _Select = 0;
thomasmorris 26:83550fc299aa 428 }
thomasmorris 23:07a368f2cdb1 429
thomasmorris 26:83550fc299aa 430 if(_Select == 0)
thomasmorris 26:83550fc299aa 431 {
thomasmorris 26:83550fc299aa 432 Led_Select_Left_mutex.lock();
thomasmorris 26:83550fc299aa 433 Led_Select_Left = 0;
thomasmorris 26:83550fc299aa 434 Led_Select_Left_mutex.unlock();
thomasmorris 26:83550fc299aa 435
thomasmorris 26:83550fc299aa 436 Led_Select_Right_mutex.lock();
thomasmorris 26:83550fc299aa 437 Led_Select_Right= 1;
thomasmorris 26:83550fc299aa 438 Led_Select_Right_mutex.unlock();
thomasmorris 26:83550fc299aa 439 }
thomasmorris 26:83550fc299aa 440 else if(_Select ==1)
thomasmorris 26:83550fc299aa 441 {
thomasmorris 26:83550fc299aa 442 Led_Select_Left_mutex.lock();
thomasmorris 26:83550fc299aa 443 Led_Select_Left = 1;
thomasmorris 26:83550fc299aa 444 Led_Select_Left_mutex.unlock();
thomasmorris 26:83550fc299aa 445
thomasmorris 26:83550fc299aa 446 Led_Select_Right_mutex.lock();
thomasmorris 26:83550fc299aa 447 Led_Select_Right= 0;
thomasmorris 26:83550fc299aa 448 Led_Select_Right_mutex.unlock();
thomasmorris 26:83550fc299aa 449 }
thomasmorris 21:6d9f6a986647 450 }
thomasmorris 26:83550fc299aa 451 else if(_Function == 2 || _Function == 3)
thomasmorris 21:6d9f6a986647 452 {
thomasmorris 26:83550fc299aa 453 _Select = 0;
thomasmorris 23:07a368f2cdb1 454 Led_Select_Left_mutex.lock();
thomasmorris 21:6d9f6a986647 455 Led_Select_Left = 0;
thomasmorris 23:07a368f2cdb1 456 Led_Select_Left_mutex.unlock();
thomasmorris 23:07a368f2cdb1 457
thomasmorris 23:07a368f2cdb1 458 Led_Select_Right_mutex.lock();
thomasmorris 21:6d9f6a986647 459 Led_Select_Right= 1;
thomasmorris 26:83550fc299aa 460 Led_Select_Right_mutex.unlock();
thomasmorris 21:6d9f6a986647 461 }
thomasmorris 26:83550fc299aa 462 _Select_mutex.unlock();
thomasmorris 16:9f98ec0ededb 463 }
thomasmorris 17:68b3fdabe4c5 464 void INTERFACE::Interface_main()//Main Routine to execute commands when the start button has been pressed
thomasmorris 16:9f98ec0ededb 465 {
thomasmorris 25:9751619fa030 466 if (_Function == 2 || _Function == 3) //Turning Code
thomasmorris 16:9f98ec0ededb 467 {
thomasmorris 16:9f98ec0ededb 468 if (_Twist_Go == true)
thomasmorris 16:9f98ec0ededb 469 {
thomasmorris 23:07a368f2cdb1 470 Led_Power_mutex.lock();
thomasmorris 21:6d9f6a986647 471 Led_Power = 1;
thomasmorris 23:07a368f2cdb1 472 Led_Power_mutex.unlock();
thomasmorris 23:07a368f2cdb1 473
thomasmorris 23:07a368f2cdb1 474 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 475 _System_Running = 1;
thomasmorris 23:07a368f2cdb1 476 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 477
thomasmorris 25:9751619fa030 478 STEPPER_MOTOR_1.Rotate_Steps(_Turns_Todo,_Function);//Rotates for the specified number of steps given
thomasmorris 23:07a368f2cdb1 479
thomasmorris 23:07a368f2cdb1 480 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 481 _System_Running = 0;
thomasmorris 23:07a368f2cdb1 482 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 483
thomasmorris 23:07a368f2cdb1 484
thomasmorris 23:07a368f2cdb1 485 _Twist_Go_mutex.lock();
thomasmorris 17:68b3fdabe4c5 486 _Twist_Go = false;
thomasmorris 23:07a368f2cdb1 487 _Twist_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 488
thomasmorris 23:07a368f2cdb1 489 Led_Power_mutex.lock();
thomasmorris 21:6d9f6a986647 490 Led_Power = 0;
thomasmorris 23:07a368f2cdb1 491 Led_Power_mutex.unlock();
thomasmorris 16:9f98ec0ededb 492 }
thomasmorris 16:9f98ec0ededb 493 }
thomasmorris 25:9751619fa030 494 else if (_Function == 0) //Annealing Code
thomasmorris 16:9f98ec0ededb 495 {
thomasmorris 16:9f98ec0ededb 496 if (_Anneal_Go == true)
thomasmorris 16:9f98ec0ededb 497 {
thomasmorris 23:07a368f2cdb1 498 Led_Power_mutex.lock();
thomasmorris 21:6d9f6a986647 499 Led_Power = 1;
thomasmorris 23:07a368f2cdb1 500 Led_Power_mutex.unlock();
thomasmorris 23:07a368f2cdb1 501
thomasmorris 23:07a368f2cdb1 502 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 503 _System_Running = 1;
thomasmorris 23:07a368f2cdb1 504 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 505
thomasmorris 16:9f98ec0ededb 506 for ( int counter = 0; counter < _Loop; counter++) //Loop value, check if works
thomasmorris 16:9f98ec0ededb 507 {
thomasmorris 23:07a368f2cdb1 508 if(_System_Running == 1)
thomasmorris 23:07a368f2cdb1 509 {
thomasmorris 23:07a368f2cdb1 510 _Tendon_mutex.lock();
thomasmorris 23:07a368f2cdb1 511 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
thomasmorris 23:07a368f2cdb1 512 Tendon_Power=1; // set duty cycle to 100%
thomasmorris 25:9751619fa030 513 _On_Time_mutex.lock();
thomasmorris 25:9751619fa030 514 wait(_On_Time);//Variable
thomasmorris 25:9751619fa030 515 _On_Time_mutex.unlock();
thomasmorris 23:07a368f2cdb1 516 Tendon_Power=0; // set duty cycle to 0%
thomasmorris 25:9751619fa030 517 _Off_Time_mutex.lock();
thomasmorris 25:9751619fa030 518 wait(_Off_Time);//Fixed off time
thomasmorris 25:9751619fa030 519 _Off_Time_mutex.unlock();
thomasmorris 23:07a368f2cdb1 520 _Tendon_mutex.unlock();
thomasmorris 23:07a368f2cdb1 521 }
thomasmorris 23:07a368f2cdb1 522 while(_System_Running == 2)//Stops the system and just spins in this while loop until system running is not paused
thomasmorris 23:07a368f2cdb1 523 {
thomasmorris 23:07a368f2cdb1 524 _Tendon_mutex.lock();
thomasmorris 23:07a368f2cdb1 525 Tendon_Power =0;
thomasmorris 23:07a368f2cdb1 526 _Tendon_mutex.unlock();
thomasmorris 23:07a368f2cdb1 527 }
thomasmorris 16:9f98ec0ededb 528 }
thomasmorris 23:07a368f2cdb1 529
thomasmorris 23:07a368f2cdb1 530 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 531 _System_Running = 0;
thomasmorris 23:07a368f2cdb1 532 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 533
thomasmorris 23:07a368f2cdb1 534 _Anneal_Go_mutex.lock();
thomasmorris 17:68b3fdabe4c5 535 _Anneal_Go = false;
thomasmorris 23:07a368f2cdb1 536 _Anneal_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 537
thomasmorris 23:07a368f2cdb1 538 Led_Power_mutex.lock();
thomasmorris 21:6d9f6a986647 539 Led_Power = 0;
thomasmorris 23:07a368f2cdb1 540 Led_Power_mutex.unlock();
thomasmorris 16:9f98ec0ededb 541 }
thomasmorris 16:9f98ec0ededb 542 }
thomasmorris 25:9751619fa030 543 else if (_Function == 1) //Testing Code //This code is paused / unpaused in start / stop note this code is not paused it is re run.
thomasmorris 16:9f98ec0ededb 544 {
thomasmorris 16:9f98ec0ededb 545 if (_Test_Go == true)
thomasmorris 16:9f98ec0ededb 546 {
thomasmorris 23:07a368f2cdb1 547 Led_Power_mutex.lock();
thomasmorris 21:6d9f6a986647 548 Led_Power = 1;
thomasmorris 23:07a368f2cdb1 549 Led_Power_mutex.unlock();
thomasmorris 23:07a368f2cdb1 550
thomasmorris 23:07a368f2cdb1 551 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 552 _System_Running = 1;
thomasmorris 23:07a368f2cdb1 553 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 554
thomasmorris 23:07a368f2cdb1 555 _Tendon_mutex.lock();
thomasmorris 16:9f98ec0ededb 556 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
thomasmorris 16:9f98ec0ededb 557 Tendon_Power= _Duty_Cycle / 100; // set duty cycle to variable input from buttons between 0-1 (on lcd this is a percentage) also increment by values of 10
thomasmorris 16:9f98ec0ededb 558 wait(_Power_Time);//Variable on time for power on
thomasmorris 16:9f98ec0ededb 559 Tendon_Power=0; // set duty cycle to 0% and power off
thomasmorris 23:07a368f2cdb1 560 _Tendon_mutex.unlock();
thomasmorris 23:07a368f2cdb1 561
thomasmorris 23:07a368f2cdb1 562 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 563 _System_Running = 0;
thomasmorris 23:07a368f2cdb1 564 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 565
thomasmorris 23:07a368f2cdb1 566 _Test_Go_mutex.lock();
thomasmorris 17:68b3fdabe4c5 567 _Test_Go = false;
thomasmorris 23:07a368f2cdb1 568 _Test_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 569
thomasmorris 23:07a368f2cdb1 570 Led_Power_mutex.lock();
thomasmorris 21:6d9f6a986647 571 Led_Power = 0;
thomasmorris 23:07a368f2cdb1 572 Led_Power_mutex.unlock();
thomasmorris 16:9f98ec0ededb 573 }
thomasmorris 16:9f98ec0ededb 574 }
thomasmorris 16:9f98ec0ededb 575 }
thomasmorris 17:68b3fdabe4c5 576 //Setter functions
thomasmorris 23:07a368f2cdb1 577 void INTERFACE::Set_System_Running(int System_Running){_System_Running_mutex.lock(); _System_Running = System_Running; _System_Running_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 578 void INTERFACE::Set_Function(int Function){_Function_mutex.lock();_Function = Function;_Function_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 579 void INTERFACE::Set_Twist_Go(bool Twist_Go){_Twist_Go_mutex.lock();_Twist_Go = Twist_Go;_Twist_Go_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 580 void INTERFACE::Set_Anneal_Go(bool Anneal_Go){_Anneal_Go_mutex.lock();_Anneal_Go = Anneal_Go;_Anneal_Go_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 581 void INTERFACE::Set_Test_Go(bool Test_Go){_Test_Go_mutex.lock();_Test_Go = Test_Go;_Test_Go_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 582 void INTERFACE::Set_Twist_Stop(bool Twist_Stop){_Twist_Stop_mutex.lock();_Twist_Stop = Twist_Stop;_Twist_Stop_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 583 void INTERFACE::Set_Anneal_Stop(bool Anneal_Stop){_Anneal_Stop_mutex.lock();_Anneal_Stop = Anneal_Stop;_Anneal_Stop_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 584 void INTERFACE::Set_Test_Stop(bool Test_Stop){_Test_Stop_mutex.lock();_Test_Go = Test_Stop;_Test_Stop_mutex.unlock();}
thomasmorris 25:9751619fa030 585 void INTERFACE::Set_Select(int Select){_Select_mutex.lock();_Select = Select;_Select_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 586 void INTERFACE::Set_Turns_Done(int Turns_Done){_Turns_Done_mutex.lock();_Turns_Done = Turns_Done;_Turns_Done_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 587 void INTERFACE::Set_Turns_To_Do(int Turns_Todo){_Turns_Todo_mutex.lock();_Turns_Todo = Turns_Todo;_Turns_Todo_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 588 void INTERFACE::Set_Loop(int Loop){_Loop_mutex.lock();Loop = Loop;_Loop_mutex.unlock();}
thomasmorris 25:9751619fa030 589 void INTERFACE::Set_On_Time(int On_Time){_On_Time_mutex.lock();_On_Time = On_Time;_On_Time_mutex.unlock();}
thomasmorris 25:9751619fa030 590 void INTERFACE::Set_Off_Time(int Off_Time){_Off_Time_mutex.lock();_Off_Time = Off_Time;_Off_Time_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 591 void INTERFACE::Set_Duty_Cycle(int Duty_Cycle){_Duty_Cycle_mutex.lock();_Duty_Cycle = Duty_Cycle;_Duty_Cycle_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 592 void INTERFACE::Set_Power_Time(float Power_Time){_Power_Time_mutex.lock();_Power_Time = Power_Time;_Power_Time_mutex.unlock();}
thomasmorris 17:68b3fdabe4c5 593 //Getter functions
thomasmorris 23:07a368f2cdb1 594 int INTERFACE::Get_System_Running(){return _System_Running;}
thomasmorris 23:07a368f2cdb1 595 int INTERFACE::Get_Function(){return _Function;}
thomasmorris 16:9f98ec0ededb 596 bool INTERFACE::Get_Twist_Go(){return _Twist_Go;}
thomasmorris 16:9f98ec0ededb 597 bool INTERFACE::Get_Anneal_Go(){return _Anneal_Go;}
thomasmorris 16:9f98ec0ededb 598 bool INTERFACE::Get_Test_Go(){return _Test_Go;}
thomasmorris 23:07a368f2cdb1 599 bool INTERFACE::Get_Twist_Stop(){return _Twist_Stop;}
thomasmorris 23:07a368f2cdb1 600 bool INTERFACE::Get_Anneal_Stop(){return _Anneal_Stop;}
thomasmorris 23:07a368f2cdb1 601 bool INTERFACE::Get_Test_Stop(){return _Test_Stop;}
thomasmorris 25:9751619fa030 602 int INTERFACE::Get_Select(){return _Select;}
thomasmorris 18:3523660f3930 603 int INTERFACE::Get_Turns_Done(){_Turns_Done = STEPPER_MOTOR_1.Get_Turns(); return _Turns_Done;}
thomasmorris 16:9f98ec0ededb 604 int INTERFACE::Get_Turns_To_Do(){return _Turns_Todo;}
thomasmorris 16:9f98ec0ededb 605 int INTERFACE::Get_Loop(){return _Loop;}
thomasmorris 25:9751619fa030 606 int INTERFACE::Get_On_Time(){return _On_Time;}
thomasmorris 25:9751619fa030 607 int INTERFACE::Get_Off_Time(){return _Off_Time;}
thomasmorris 16:9f98ec0ededb 608 int INTERFACE::Get_Duty_Cycle(){return _Duty_Cycle;}
thomasmorris 23:07a368f2cdb1 609 int INTERFACE::Get_Power_Time(){return _Power_Time;}