-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab18.ino
2535 lines (2292 loc) · 71.8 KB
/
lab18.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//V18
//Fixed bug with setting duty cycle and timeout, added load calibration and load inside auto and manual modes.
//Working on changing the interupt intervals to 500ms
//Changed arrow prompts to numerical inside setup and main menu
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Keypad.h> //Custom library at http://playground.arduino.cc/code/keypad
/* initialize the library with the numbers of the interface pins
* LCD RS pin to digital pin 22
* LCD Enable pin to digital pin 23
* LCD D4 pin to digital pin 24
* LCD D5 pin to digital pin 25
* LCD D6 pin to digital pin 26
* LCD D7 pin to digital pin 27
* LCD R/W pin to ground */
LiquidCrystal lcd(22, 23, 24, 25, 26, 27);
byte Up[8] = {//Create up arrow because there is no native one
0b00000,
0b00100,
0b01110,
0b10101,
0b00100,
0b00100,
0b00000,
0b00000
};
byte Down[8] = {//Create down arrow because there is no native one
0b00000,
0b00100,
0b00100,
0b10101,
0b01110,
0b00100,
0b00000,
0b00000
};
////////////////Variables///////////////////////////////////////////
int pot; // A0 analog input for the actuator pot
int i;
int timeout = 30;//timeout variable (in seconds)
byte cursor=11;//cursor variable
int dutyCycle=25;//duty cycle variable
byte dutyCycleSelect=0;//Duty cycle selcet bit; If 0 then pause after each stroke if 1 then pause every cycle
long cycleTime = 0;//Duty cycle time in the interrupt(how long it takes for each cycle)
long dutyCyclePause=0;//duty cycle pause how long i need to puase after each cycle or stroke
float dutyCycleTimer=0;//the number showing how long it is paused for
byte setupFlag = 0; //checks if setup mode is used before using auto mode
double actualTimeout = 0; //(in seconds) to compare to timeout variable
double timeoutTimer = 0; //(in milliseconds)
byte limitSwitchFlag=1;//limit Switch Flag: 1=No limits///0=Limit switches///2=pot limits
byte limitSwitchFlagI=1;//limit Switch Flag input: 1=No limits///0=Limit switches///2=pot limits
byte auto_limitSwitchFlag=1;// auto mode limit Switch Flag: ///0=Limit switches///1=pot limits
float ext_clutch=0;// on after extend
float ret_clutch=0;// on after retract
byte load = 0;// manual mode load direction variable 0=Auto load(compression on extend and tension on retract) 1=no load;2=compression;3=tension
byte extLoadDirection = 1;// auto mode extend load direction variable 0=no load;1=compression;2=tension defaults to compression
byte retLoadDirection = 2;// auto mode retract load direction variable 0=no load;1=compression;2=tension defaults to retraction
int ext_load = 0;
int ret_load = 0;
byte load_man =0;//manual mode output variable 1=no load;2=compression;3=tension
byte manualSelect =0;//manual mode menu selector 0=load selection; 1=limit selection
byte setup_submenu = 0; //counter used to keep track of what setup menu is being used
int ext = 46; //pin for extend relay
int ret = 47; //pin for ret relay
int limitE = 48; //pin for extend limit switch
int limitR = 49; //pin for retract limit switch
int limitEstatus = 0; //checks if extend limit switch is pressed
int limitRstatus = 0; //checks if retract limit switch is pressed
int z = 0; //placeholder for array
int x; //used for array in number()
long ext_cycleTime =0;//extend duty cycle time
long ret_cycleTime = 0;//retract duty cycle time
int pot_ret =0;//retract pot limit setting
int pot_ext =10000;//extend pot limit setting
int startCycle = 0;// start cycle counter
int endCycle = 1;// end cycle counter
int totalCycles;
int cycles=0;//cycle counter
byte dummy;//LOL dummy byte to be used
int loadcell_value = 0; //initial load cell value read by the arduino
int outputValue = 0; //final load cell value after being mapped
int loadcell_start = 0;
int loadcell_max = 0;
int testStandMax_Readout = 0;
float testStandMax_Load=0;
int ten = 40;
int com = 41;
int mVolts = 0;
int mcp;
int CS= 53;
float unitPound;
float startWeight;
/*
A0 = pot
A1 = load cell
*/
/////////////For keypad//////////////////////////
const byte rows = 4;
const byte cols = 4;
//Array to represent the key positions, used default numberpad for the keys used
char keys[rows][cols] =
{
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'},
};
/*
Uses 2 as the up arrow
4 for the left arrow
6 for the right arrow
8 for the down arrow
5 for select
* for back
A for extend
B for retract
*/
byte rowPins[rows] = {9,8,7,6}; //Pin 9 is top row....
byte colPins[cols] = {5,4,3,2}; //Pin 5 is left column...
Keypad kp = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
char key; //key being read from keypad
char holdKey; //key that is held being down
///////////////End of Variables/////////////////////////////////////////
///////////////////Setup MCU///////////////////////////////
void setup() {
Serial.begin(9600);
kp.setHoldTime(10); //used to simulate holding down a key as being a normal button
//.................I/O setup..........................................
pinMode(13, OUTPUT);
pinMode(9, OUTPUT);
pinMode(ext, OUTPUT);//Ext relay
pinMode(ret, OUTPUT);//Ret relay
pinMode(limitE, INPUT_PULLUP);
pinMode(limitR, INPUT_PULLUP);
pinMode(com, OUTPUT);
pinMode(ten, OUTPUT);
pinMode(CS, OUTPUT);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV2);
//................end of I/O setup....................................*
// create a new characters
lcd.createChar(0, Up);
lcd.createChar(1, Down);
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// initialize timer1
noInterrupts(); // disable all interrupts
//set timer1 interrupt at 1kHz
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0
// set compare match register for 1khz increments
OCR1A = 31250; // compare match register 16MHz/8/1kHz ; formula= { 16000000/8*1000)
TCCR1B |= (1 << WGM12); // CTC mode
TCCR1B |= (1 << CS12); // 8 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); // enable all interrupts
main_menu();
}
/////////////////Timer1 Int routine////////////////////////////
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
{
cycleTime = cycleTime + 500 ; // Add 500ms to the duty cycle counter. Interupt routine is set for 500ms
timeoutTimer = timeoutTimer + 500;
}
/////////////////////////////////////////////////////////////
void main_menu() {
limitSwitchFlag =0;
load = 0;
manualSelect = 0;
lcd.clear();
// Print a message to the LCD.
lcd.print("Lab Test Stand V18");
lcd.setCursor(0, 1);//start at col0 and row2
//lcd.print((char)126);//display the right arrow
lcd.print("1.Manual Mode");
lcd.setCursor(0, 2);//start at col0 and row3
//lcd.print((char)127);//display the left arrow
lcd.print("2.Auto Mode");
lcd.setCursor(0, 3);//start at col0 and row4
//lcd.write(byte(0));//display the up arrow
lcd.print("3.Setup Mode");
}
////////////////////////Main Loop//////////////////////////////
void loop() {
delay(50);
noTone(44);
key = kp.getKey(); //wait for key to be pressed
if (key == '1') {
lcd.clear();
lcd.print(" Manual Mode");
lcd.setCursor(0, 1);//
lcd.print("*");
lcd.print((char)126);//display the right arrow
lcd.setCursor(4, 1);//
lcd.print("Auto Load ");
lcd.setCursor(0, 2);//
lcd.print(" ");
lcd.print((char)127);//display the left arrow
lcd.print((char)126);//display the right arrow
lcd.setCursor(4, 2);//
lcd.print("No Switches ");
load = 0;
limitSwitchFlag =1 ;
manual();
}
if (key == '2') {
lcd.clear();
if(setupFlag == 0){
lcd.print("Setup not completed.");
lcd.setCursor(0,1);
lcd.print(" Continue?");
auto_mode();
}
else{
lcd.print(" Auto Mode ");
lcd.setCursor(0, 1);//start at column 0 and row1
lcd.print(" Select to start ");
auto_mode();
}
}
if (key == '3') {
setup_submenu = 0;
lcd.clear();
lcd.print(" Setup Mode");
lcd.setCursor(0, 1);//start at column 0 and row2
set_mode();
}
if(key == 'C'){
cal_mode();
}
}
//////////////////////////////////////////////////////////////
////////////////////////MANUAL MODE////////////////////////////////////////////
void manual() {
key = kp.getKey();
if(key)
{
holdKey = key;
}
// manual mode selection: up arrow = load down arrow =limit switches
if (key == '2'){
if (manualSelect ==1){
manualSelect = manualSelect - 1;
switch (load) {
case 0:
lcd.setCursor(0, 1);//
lcd.print("*");
lcd.print((char)126);//display the right arrow
lcd.print(" ");
break;
case 1:
lcd.setCursor(0, 1);//
lcd.print("*");
lcd.print((char)127);//display the left arrow
lcd.print((char)126);//display the right arrow
break;
case 2:
lcd.setCursor(0, 1);//
lcd.print("*");
lcd.print((char)127);//display the left arrow
lcd.print((char)126);//display the right arrow
break;
case 3:
lcd.setCursor(0, 1);//
lcd.print("*");
lcd.print((char)127);//display the left arrow
lcd.print(" ");
break;
}
}
lcd.setCursor(0, 2);//
lcd.print(" ");
}
if (key == '8'){
if (manualSelect ==0){
manualSelect = manualSelect + 1;
switch (limitSwitchFlag) {
case 0:
lcd.setCursor(0, 2);//
lcd.print("*");
lcd.print((char)126);//display the right arrow
lcd.print(" ");
break;
case 1:
lcd.setCursor(0, 2);//
lcd.print("*");
lcd.print((char)127);//display the left arrow
lcd.print((char)126);//display the right arrow
break;
case 2:
lcd.setCursor(0, 2);//
lcd.print("*");
lcd.print((char)127);//display the left arrow
lcd.print(" ");
break;
}
}
lcd.setCursor(0, 1);//
lcd.print(" ");
}
//..............................................................................*
//---------------------------------------------
if (key == '6'){
if (manualSelect ==0) {//If manual select is in load position then change load menu else change the limit switches menu
switch (load) {//load direction variable 1=no load;0=compression;2=tension
case 0:
lcd.setCursor(0, 1);//
lcd.print("*");
lcd.print((char)127);//display the left arrow
lcd.print((char)126);//display the right arrow
lcd.setCursor(4, 1);//
lcd.print("No Load ");
load = load + 1;
break;
case 1:
lcd.setCursor(0, 1);//
lcd.print("*");
lcd.print((char)127);//display the left arrow
lcd.print((char)126);//display the right arrow
lcd.print(" ");
lcd.setCursor(4, 1);//
lcd.print("Compression ");
load = load + 1;
break;
case 2:
lcd.setCursor(0, 1);//
lcd.print("*");
lcd.print((char)127);//display the left arrow
lcd.print(" ");
lcd.setCursor(4, 1);//
lcd.print("Tension ");
load = load + 1;
break;
}
}
else{
switch (limitSwitchFlag) {
case 0:
lcd.setCursor(0, 2);//
lcd.print("*");
lcd.print((char)127);//display the left arrow
lcd.print((char)126);//display the right arrow
lcd.setCursor(4, 2);//
lcd.print("No Switches ");
limitSwitchFlag = limitSwitchFlag + 1;
break;
case 1:
lcd.setCursor(0, 2);//
lcd.print("*");
lcd.print((char)127);//display the left arrow
lcd.print(" ");
lcd.setCursor(4, 2);//
lcd.print("Pot Switches ");
limitSwitchFlag = limitSwitchFlag + 1;
break;
}
}
}
//-------------------------------------------*
//--------------------------------------------
if (key == '4'){
if (manualSelect ==0) {
switch (load) {
case 3:
lcd.setCursor(0, 1);//
lcd.print("*");
lcd.print((char)127);//display the left arrow
lcd.print((char)126);//display the right arrow
lcd.setCursor(4, 1);//
lcd.print("Compression ");
load = load - 1;
break;
case 2:
lcd.setCursor(0, 1);//
lcd.print("*");
lcd.print((char)127);//display the left arrow
lcd.print((char)126);//display the right arrow
lcd.setCursor(4, 1);//
lcd.print("No Load ");
load = load - 1;
break;
case 1:
lcd.setCursor(0, 1);//
lcd.print("*");
lcd.print((char)126);//display the left arrow
lcd.print(" ");
lcd.setCursor(4, 1);//
lcd.print("Auto Load ");
load = load - 1;
break;
}
}
else{
switch (limitSwitchFlag) {
case 2:
lcd.setCursor(0, 2);//
lcd.print("*");
lcd.print((char)127);//display the left arrow
lcd.print((char)126);//display the right arrow
lcd.setCursor(4, 2);//
lcd.print("No Switches ");
limitSwitchFlag = limitSwitchFlag - 1;
break;
case 1:
lcd.setCursor(0, 2);//
lcd.print("*");
lcd.print((char)126);//display the left arrow
lcd.print(" ");//clear the right arrow
lcd.setCursor(4, 2);//
lcd.print("LS Switches ");
limitSwitchFlag = limitSwitchFlag - 1;
break;
}
}
}
//----------------------------------------------------------------------------------------*
//While a button is being held down, checks to see if it is the extend or retract button
/////////////////////////Extend/Retract Sub routine////////////////////////////////////////////////
while(kp.getState() == HOLD) {
if(holdKey == 'A'){
switch (load_man) {//apply the coresponding load 0=Auto load(compression on extend and tension on retract) 1=no load;2=compression;3=tension
case 0:// auto load on extend is compression
if(ext_load == 0){
lcd.setCursor(0, 3);//
lcd.print("ext no Load set ");
break;
}
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, loadcell_start, testStandMax_Readout,startWeight, testStandMax_Load);
digitalWrite(13, HIGH);
digitalWrite(com, HIGH);
while(outputValue < ext_load){
mVolts += 1;
DAC();
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, loadcell_start, testStandMax_Readout,startWeight, testStandMax_Load);
}
lcd.setCursor(0, 3);//
lcd.print("ext Compression ");
break;
case 1:// No Load
lcd.setCursor(0, 3);//
lcd.print("ext no Load ");
break;
case 2:// compression load
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, loadcell_start, testStandMax_Readout,startWeight, testStandMax_Load);
digitalWrite(13, HIGH);
digitalWrite(com, HIGH);
while(outputValue < ext_load){
mVolts += 1;
DAC();
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, loadcell_start, testStandMax_Readout,startWeight, testStandMax_Load);
}
lcd.setCursor(0, 3);//
lcd.print("ext Compression ");
break;
case 3:// Tension load
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, testStandMax_Readout,loadcell_start, testStandMax_Load, startWeight);
outputValue = abs(outputValue);
digitalWrite(13, HIGH);
digitalWrite(ten, HIGH);
while(outputValue < ext_load){
mVolts += 1;
DAC();
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, testStandMax_Readout,loadcell_start, testStandMax_Load, startWeight);
outputValue = abs(outputValue);
}
lcd.setCursor(0, 3);//
lcd.print("ext Tension ");
break;
}
key = kp.getKey();
pot = analogRead(A0);
pot = map(pot,0,1023,0,10000);
limitEstatus = digitalRead(limitE);
switch (limitSwitchFlagI) {//1=No limits///0=Limit switches///2=pot limits
case 0: // Limit switches
if(limitEstatus == HIGH){
digitalWrite(13, HIGH); // sets the LED on
digitalWrite(ext, HIGH); // turn on ext relay
}
else{
digitalWrite(13, LOW); // sets the LED off
digitalWrite(ext, LOW); //turn off ext relay
}
break;
case 1:// //if no limts is selected then just extend
digitalWrite(13, HIGH); // sets the LED on
digitalWrite(ext, HIGH); // turn on ext relay
break;
case 2:// if pot limits the compare actuator current position with the teach mode selected position(pot_ext)
if ( pot < pot_ext){
digitalWrite(13, HIGH); // sets the LED on
digitalWrite(ext, HIGH); // turn on ext relay
}
else{
digitalWrite(13, LOW); // sets the LED off
digitalWrite(ext, LOW); //turn off ext relay
}
}
}
else if (holdKey == 'B') { //While the retract button is pressed turn on the retract relay
switch (load_man) {//apply the coresponding load 0=Auto load(compression on extend and tension on retract) 1=no load;2=compression;3=tension
case 0:// auto load on extend is compression
if(ret_load == 0){
lcd.setCursor(0, 3);//
lcd.print("ret no Load set ");
break;
}
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, testStandMax_Readout,loadcell_start, testStandMax_Load, startWeight);
outputValue = abs(outputValue);
digitalWrite(13, HIGH);
digitalWrite(ten, HIGH);
while(outputValue < ret_load){
mVolts += 1;
DAC();
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, testStandMax_Readout,loadcell_start, testStandMax_Load, startWeight);
outputValue = abs(outputValue);
}
lcd.setCursor(0, 3);//
lcd.print("ret Tension ");
break;
case 1:// No Load
lcd.setCursor(0, 3);//
lcd.print("ret no Load ");
break;
case 2:// compression load
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, loadcell_start, testStandMax_Readout,startWeight, testStandMax_Load);
digitalWrite(13, HIGH);
digitalWrite(com, HIGH);
while(outputValue < ret_load){
mVolts += 1;
DAC();
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, loadcell_start, testStandMax_Readout,startWeight, testStandMax_Load);
}
lcd.setCursor(0, 3);//
lcd.print("ret Compression ");
break;
case 3:// Tension load
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, testStandMax_Readout,loadcell_start, testStandMax_Load, startWeight);
digitalWrite(13, HIGH);
digitalWrite(ten, HIGH);
outputValue = abs(outputValue);
while(outputValue < ret_load){
mVolts += 1;
DAC();
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, testStandMax_Readout,loadcell_start, testStandMax_Load, startWeight);
outputValue = abs(outputValue);
}
lcd.setCursor(0, 3);//
lcd.print("ret Tension ");
break;
}
key = kp.getKey();
pot = analogRead(A0);
pot = map(pot,0,1023,0,10000);
limitRstatus = digitalRead(limitR);
switch (limitSwitchFlagI) {//1=No limits///0=Limit switches///2=pot limits
case 0:
if(limitRstatus == HIGH){
digitalWrite(13, HIGH); // sets the LED on
digitalWrite(ret, HIGH); // turn on ret relay
}
else{
digitalWrite(13, LOW); // sets the LED off
digitalWrite(ret, LOW); //turn off ext relay
}
break;
case 1:// //if no limts is selected then just retract
digitalWrite(13, HIGH); // sets the LED on
digitalWrite(ret, HIGH); // turn on ret relay
break;
case 2:
if ( pot > pot_ret){
digitalWrite(13, HIGH); // sets the LED on
digitalWrite(ret, HIGH); // turn on ret relay
}
else{
digitalWrite(13, LOW); // sets the LED off
digitalWrite(ret, LOW); //turn off ret relay
}
}
}
else
{
break;
}
}
//////////////////////////End of extend/retract sub routine////////////////////////////////////////////////////////
if (key == '5'){//if select button is pressed
if (limitSwitchFlag==2){// if pot switches is selected then goto teach mode
teach_mode();
}
limitSwitchFlagI = limitSwitchFlag; // load limitSwitchFlagI with limitSwitchFlag
load_man = load;
}
if (key == '*'){
main_menu(); //if back switch is pressed then go back to the main menu
return;
}
digitalWrite(13, LOW); // sets the LED off
digitalWrite(ext, LOW); //turn off ext relay
digitalWrite(ret, LOW); //turn off ret relay
digitalWrite(com, LOW);
digitalWrite(ten, LOW);
mVolts = 0;
DAC();
lcd.setCursor(0, 3);//
lcd.print(" ");
lcd.setCursor(17, 1);//
lcd.print(load);
lcd.print(":");
lcd.print(load_man);
lcd.setCursor(17, 2);//
lcd.print(limitSwitchFlag);
lcd.print(":");
lcd.print(limitSwitchFlagI);
manual();
}
///////////////////////////////////////////////////////////////////////////
////////////////////////Auto MODE/////////////////////////////////////////////////////////////////////////////////////
//.................................................................
void auto_mode() {
cycleTime = 0;
timeoutTimer = 0;
key = kp.getKey();
if (key == '*'){
main_menu();
return;
}
if (key == '5'){
run_mode();
}
auto_mode();
}
//..................................................................
//////////////////////////////Run mode routine/////////////////////////////////////////////////////////
void run_mode(){//start auto run mode
lcd.clear();
lcd.print(" Run Mode");
// full retract
limitRstatus = digitalRead(limitR); //Checks the pin of the retract limit switch
if(auto_limitSwitchFlag == 0){
while (limitRstatus == HIGH) {
digitalWrite(13, HIGH); // sets the LED on
digitalWrite(ret, HIGH); // turn on ret relay
limitRstatus = digitalRead(limitR);
}
}
if(auto_limitSwitchFlag == 1){
while (pot > pot_ret) {
digitalWrite(13, HIGH); // sets the LED on
digitalWrite(ret, HIGH); // turn on ret relay
pot = analogRead(A0);
pot = map(pot,0,1023,0,10000);
}
}
digitalWrite(13, LOW); // sets the LED off
digitalWrite(ext, LOW); //turn off ext relay
digitalWrite(ret, LOW); //turn off ret relay
run0:
///////////////////////Setting Extend Load///////////////////////////////
mVolts = 0;
DAC();
switch (extLoadDirection) {//apply the corresponding load 0=Auto load(compression on extend and tension on retract) 1=no load;2=compression;3=tension
case 0:// auto load on extend is compression
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, loadcell_start, testStandMax_Readout,startWeight, testStandMax_Load);
digitalWrite(13, HIGH);
digitalWrite(com, HIGH);
while(outputValue < ext_load){
mVolts += 1;
DAC();
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, loadcell_start, testStandMax_Readout,startWeight, testStandMax_Load);
}
break;
case 1:// No Load
break;
case 2:// compression load
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, loadcell_start, testStandMax_Readout,startWeight, testStandMax_Load);
digitalWrite(13, HIGH);
digitalWrite(com, HIGH);
while(outputValue < ext_load){
mVolts += 1;
DAC();
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, loadcell_start, testStandMax_Readout,startWeight, testStandMax_Load);
}
break;
case 3:// Tension load
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, testStandMax_Readout,loadcell_start, testStandMax_Load, startWeight);
outputValue = abs(outputValue);
digitalWrite(13, HIGH);
digitalWrite(ten, HIGH);
while(outputValue < ext_load){
mVolts += 1;
DAC();
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, testStandMax_Readout,loadcell_start, testStandMax_Load, startWeight);
outputValue = abs(outputValue);
}
break;
}
//....................Run mode Extend cycle................................
lcd.setCursor(0, 1);
lcd.print(" Extending ");
cycleTime = 0;
timeoutTimer = 0;
limitEstatus = digitalRead(limitE); //Checks the pin of the extend limit switch
//pot switches
if(auto_limitSwitchFlag == 1){
while (pot < pot_ext) {
digitalWrite(13, HIGH); // sets the LED on
digitalWrite(ext, HIGH); // turn on ext relay
pot = analogRead(A0);
pot = map(pot,0,1023,0,10000);
//TIMEOUT SEQUENCE
actualTimeout = timeoutTimer/1000.00; //converts milliseconds to seconds
key = kp.getKey();
if (key == '*')
{
digitalWrite(13, LOW);
digitalWrite(ext,LOW);
digitalWrite(com, LOW);
digitalWrite(ten, LOW);
mVolts = 0;
DAC();
noTone(44);
cycles = 0;
return;
}
if (actualTimeout >= timeout) //if timer is greater than timeout value, produce a timeout error
{
digitalWrite(13, LOW);
digitalWrite(ext,LOW);
digitalWrite(ret, LOW);
digitalWrite(com, LOW);
digitalWrite(ten, LOW);
mVolts = 0;
DAC();
tone(44,1000);
lcd.clear();
lcd.print("ERROR:TIMEOUT");
lcd.setCursor(0,1);
lcd.print(cycles);
lcd.print(" Cycles Completed");
lcd.setCursor(0,2);
lcd.print("Press B to return");
cycles = 0;
key = kp.getKey();
if (key == '*')
{
return;
}
return;
}
}
}
//Limit switches, will continue to run until the Extend limit switch is pulled low
if(auto_limitSwitchFlag == 0){
while (limitEstatus == HIGH) {
digitalWrite(13, HIGH); // sets the LED on
digitalWrite(ext, HIGH); // turn on ext relay
//TIMEOUT SEQUENCE
actualTimeout = timeoutTimer/1000.000; //converts milliseconds to seconds
key = kp.getKey();
if (key == '*')
{
digitalWrite(13, LOW);
digitalWrite(ext,LOW);
digitalWrite(ret, LOW);
digitalWrite(com, LOW);
digitalWrite(ten, LOW);
mVolts = 0;
DAC();
cycles = 0;
return;
}
if (actualTimeout >= timeout) //if timer is greater than timeout value, produce a timeout error
{
digitalWrite(13, LOW);
digitalWrite(ext,LOW);
digitalWrite(ret, LOW);
digitalWrite(com, LOW);
digitalWrite(ten, LOW);
mVolts = 0;
DAC();
tone(44,1000);
lcd.clear();
lcd.print("ERROR:TIMEOUT");
lcd.setCursor(0,1);
lcd.print(cycles);
lcd.print(" Cycles Completed");
lcd.setCursor(0,2);
lcd.print("Press B to return");
cycles = 0;
key = kp.getKey();
if (key == '*')
{
return;
}
return;
}
limitEstatus = digitalRead(limitE);
}
}
digitalWrite(13, LOW); // sets the LED off
digitalWrite(ext, LOW); //turn off ext relay
digitalWrite(ret, LOW); //turn off ret relay
digitalWrite(com, LOW);
digitalWrite(ten, LOW);
mVolts = 0;
DAC();
// check on after extend if ext_clutch > 0 then delay that number of seconds
if(ext_clutch >0)
{
delay(ext_clutch*1000);
}
ext_cycleTime = cycleTime;
lcd.setCursor(0, 1);
lcd.print(" ");
if (dutyCycleSelect==0){
dutyCyclePause = (100/ dutyCycle) * ext_cycleTime;
lcd.setCursor(0, 2);
lcd.print("PAUSE:");
while (dutyCyclePause > 0) {
key = kp.getKey();
if (key == '*'){
cycles = 0;
return;
}
delay(10);
dutyCyclePause = dutyCyclePause -10;
dutyCycleTimer = (dutyCyclePause/1000) + 1;
lcd.setCursor(6, 2);
lcd.print(dutyCycleTimer);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(" ");
}
//.....................End of Run extend cycle................................
///////////////////////Setting Retract Load///////////////////////////////
mVolts = 0;
DAC();
switch (retLoadDirection) {//apply the coresponding load 0=Auto load(compression on extend and tension on retract) 1=no load;2=compression;3=tension
case 0:// auto load on retract is tension
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, testStandMax_Readout,loadcell_start, testStandMax_Load, startWeight);
outputValue = abs(outputValue);
digitalWrite(13, HIGH);
digitalWrite(ten, HIGH);
while(outputValue < ret_load){
mVolts += 1;
DAC();
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, testStandMax_Readout,loadcell_start, testStandMax_Load, startWeight);
outputValue = abs(outputValue);
}
break;
case 1:// No Load
break;
case 2:// compression load
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, loadcell_start, testStandMax_Readout,startWeight, testStandMax_Load);
digitalWrite(13, HIGH);
digitalWrite(com, HIGH);
while(outputValue < ret_load){
mVolts += 1;
DAC();
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, loadcell_start, testStandMax_Readout,startWeight, testStandMax_Load);
}
break;
case 3:// Tension load
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, testStandMax_Readout,loadcell_start, testStandMax_Load, startWeight);
outputValue = abs(outputValue);
digitalWrite(13, HIGH);
digitalWrite(ten, HIGH);
while(outputValue < ret_load){
mVolts += 1;
DAC();
loadcell_value = analogRead(A1);
outputValue = map(loadcell_value, testStandMax_Readout,loadcell_start, testStandMax_Load, startWeight);
outputValue = abs(outputValue);
}
break;
}
//......................Run mode retract cycle...............................
lcd.setCursor(0, 1);
lcd.print(" Retracting ");
cycleTime = 0;
timeoutTimer = 0;
limitRstatus = digitalRead(limitR); //Checks the pin of the retract limit switch