Cycle Testing
Dependencies: Stepper mbed HCSR04 millis
main.cpp@9:5263aacbda53, 2019-01-21 (annotated)
- Committer:
- vamgehealthcare11
- Date:
- Mon Jan 21 19:54:15 2019 +0000
- Revision:
- 9:5263aacbda53
- Parent:
- 8:a7b443aee89b
- Child:
- 10:4c3a8f835bef
update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rschimpf78 | 2:e8f8095464cf | 1 | #include "mbed.h" |
rschimpf78 | 2:e8f8095464cf | 2 | #include "Stepper.h" |
rschimpf78 | 2:e8f8095464cf | 3 | #include "string" |
rschimpf78 | 3:fd2ca631ab44 | 4 | #include "hcsr04.h" |
rschimpf78 | 5:e958d61e0564 | 5 | #include "millis.h" |
rschimpf78 | 6:6ca8a0ef7d4a | 6 | |
rschimpf78 | 3:fd2ca631ab44 | 7 | Serial pc(USBTX, USBRX); |
vamgehealthcare11 | 9:5263aacbda53 | 8 | HCSR04 heightsensor(PTD2,PTD3); |
rschimpf78 | 6:6ca8a0ef7d4a | 9 | HCSR04 pathsensor(PTC2,PTA2); //(trig,echo) |
rschimpf78 | 3:fd2ca631ab44 | 10 | DigitalOut in1(PTC12); |
rschimpf78 | 3:fd2ca631ab44 | 11 | DigitalOut in2(D7); |
rschimpf78 | 6:6ca8a0ef7d4a | 12 | DigitalIn magnetSwitch(D10); |
vamgehealthcare11 | 9:5263aacbda53 | 13 | DigitalIn homeSwitch(D9); |
vamgehealthcare11 | 9:5263aacbda53 | 14 | Stepper mot(D3,D4); |
rschimpf78 | 2:e8f8095464cf | 15 | DigitalOut en(D2); |
rschimpf78 | 0:88834eed3de0 | 16 | |
vamgehealthcare11 | 9:5263aacbda53 | 17 | int main(){ |
vamgehealthcare11 | 9:5263aacbda53 | 18 | LOOPY: |
vamgehealthcare11 | 9:5263aacbda53 | 19 | en = 1; |
vamgehealthcare11 | 9:5263aacbda53 | 20 | in1 = 1; |
vamgehealthcare11 | 9:5263aacbda53 | 21 | in2 = 1; |
vamgehealthcare11 | 9:5263aacbda53 | 22 | magnetSwitch.mode(PullUp); |
vamgehealthcare11 | 9:5263aacbda53 | 23 | wait (.01); |
vamgehealthcare11 | 9:5263aacbda53 | 24 | homeSwitch.mode(PullUp); |
vamgehealthcare11 | 9:5263aacbda53 | 25 | wait (0.01); |
vamgehealthcare11 | 9:5263aacbda53 | 26 | int command; |
vamgehealthcare11 | 9:5263aacbda53 | 27 | |
vamgehealthcare11 | 9:5263aacbda53 | 28 | while(1){ |
vamgehealthcare11 | 9:5263aacbda53 | 29 | |
vamgehealthcare11 | 9:5263aacbda53 | 30 | pc.printf("\nCommand:\n\n\t1\tSend Plates\n\t2\tDetect Active Plates\n\t3\tRetract All Active Plates\n\t4\tSelect Plates\n\n"); |
vamgehealthcare11 | 9:5263aacbda53 | 31 | pc.printf("\nRequest: "); |
vamgehealthcare11 | 9:5263aacbda53 | 32 | pc.scanf("%d",&command); |
rschimpf78 | 0:88834eed3de0 | 33 | |
vamgehealthcare11 | 9:5263aacbda53 | 34 | if (command==1){ |
rschimpf78 | 3:fd2ca631ab44 | 35 | |
vamgehealthcare11 | 9:5263aacbda53 | 36 | int plates = 0; |
vamgehealthcare11 | 9:5263aacbda53 | 37 | unsigned int dist; |
vamgehealthcare11 | 9:5263aacbda53 | 38 | int platedist; |
rschimpf78 | 3:fd2ca631ab44 | 39 | |
vamgehealthcare11 | 9:5263aacbda53 | 40 | while(plates<=0 || plates>16){ |
vamgehealthcare11 | 9:5263aacbda53 | 41 | pc.printf("\nEnter Number of Plates to Send 0-16: "); |
vamgehealthcare11 | 9:5263aacbda53 | 42 | pc.scanf("%d",&plates); |
vamgehealthcare11 | 9:5263aacbda53 | 43 | |
vamgehealthcare11 | 9:5263aacbda53 | 44 | if (plates > 16 || plates < 0 ){ |
vamgehealthcare11 | 9:5263aacbda53 | 45 | pc.printf("\nInvalid Entry"); |
vamgehealthcare11 | 9:5263aacbda53 | 46 | } |
vamgehealthcare11 | 9:5263aacbda53 | 47 | else{ |
vamgehealthcare11 | 9:5263aacbda53 | 48 | pc.printf("\nPlates Requested: %ld", plates); |
vamgehealthcare11 | 9:5263aacbda53 | 49 | } |
rschimpf78 | 3:fd2ca631ab44 | 50 | } |
rschimpf78 | 3:fd2ca631ab44 | 51 | |
vamgehealthcare11 | 9:5263aacbda53 | 52 | if (magnetSwitch == 1){ |
vamgehealthcare11 | 9:5263aacbda53 | 53 | pc.printf("\nNot in Home Position"); |
vamgehealthcare11 | 9:5263aacbda53 | 54 | goto LOOPY; |
vamgehealthcare11 | 9:5263aacbda53 | 55 | } |
vamgehealthcare11 | 9:5263aacbda53 | 56 | else{ |
vamgehealthcare11 | 9:5263aacbda53 | 57 | wait(1); |
vamgehealthcare11 | 9:5263aacbda53 | 58 | in1=1; |
vamgehealthcare11 | 9:5263aacbda53 | 59 | in2=0; |
vamgehealthcare11 | 9:5263aacbda53 | 60 | wait_ms(900); |
vamgehealthcare11 | 9:5263aacbda53 | 61 | in1=1; |
vamgehealthcare11 | 9:5263aacbda53 | 62 | in2=1; |
vamgehealthcare11 | 9:5263aacbda53 | 63 | } |
vamgehealthcare11 | 9:5263aacbda53 | 64 | |
vamgehealthcare11 | 9:5263aacbda53 | 65 | platedist = (468-24*plates); |
vamgehealthcare11 | 9:5263aacbda53 | 66 | wait(1); |
vamgehealthcare11 | 9:5263aacbda53 | 67 | heightsensor.start(); |
vamgehealthcare11 | 9:5263aacbda53 | 68 | wait_ms(500); |
vamgehealthcare11 | 9:5263aacbda53 | 69 | dist = heightsensor.get_dist_cm(); |
vamgehealthcare11 | 9:5263aacbda53 | 70 | millisStart(); |
vamgehealthcare11 | 9:5263aacbda53 | 71 | long durationSM = 0; |
vamgehealthcare11 | 9:5263aacbda53 | 72 | long starttimeSM = millis(); |
vamgehealthcare11 | 9:5263aacbda53 | 73 | pc.printf("\nPlate Distance:%ld",platedist); |
vamgehealthcare11 | 9:5263aacbda53 | 74 | pc.printf("\nSelector Height:%ld",dist); |
vamgehealthcare11 | 9:5263aacbda53 | 75 | |
vamgehealthcare11 | 9:5263aacbda53 | 76 | while(dist < platedist-2 || dist > platedist+2 && dist < 480 && durationSM <56000){ |
vamgehealthcare11 | 9:5263aacbda53 | 77 | |
vamgehealthcare11 | 9:5263aacbda53 | 78 | heightsensor.start(); |
vamgehealthcare11 | 9:5263aacbda53 | 79 | dist = heightsensor.get_dist_cm(); |
vamgehealthcare11 | 9:5263aacbda53 | 80 | long currenttimeSM = millis(); |
vamgehealthcare11 | 9:5263aacbda53 | 81 | durationSM = currenttimeSM-starttimeSM; |
vamgehealthcare11 | 9:5263aacbda53 | 82 | pc.printf("\nSelector Height:%ld",dist); |
vamgehealthcare11 | 9:5263aacbda53 | 83 | en = 0; |
vamgehealthcare11 | 9:5263aacbda53 | 84 | mot.setSpeed(500); |
vamgehealthcare11 | 9:5263aacbda53 | 85 | |
vamgehealthcare11 | 9:5263aacbda53 | 86 | if(dist<platedist-2){ |
vamgehealthcare11 | 9:5263aacbda53 | 87 | mot.rotate(1); |
vamgehealthcare11 | 9:5263aacbda53 | 88 | wait(0.5); |
vamgehealthcare11 | 9:5263aacbda53 | 89 | } |
vamgehealthcare11 | 9:5263aacbda53 | 90 | if(dist>platedist+2){ |
vamgehealthcare11 | 9:5263aacbda53 | 91 | mot.rotate(0); |
vamgehealthcare11 | 9:5263aacbda53 | 92 | wait(0.5); |
vamgehealthcare11 | 9:5263aacbda53 | 93 | } |
vamgehealthcare11 | 9:5263aacbda53 | 94 | mot.stop(); |
rschimpf78 | 3:fd2ca631ab44 | 95 | } |
vamgehealthcare11 | 9:5263aacbda53 | 96 | |
vamgehealthcare11 | 9:5263aacbda53 | 97 | mot.stop(); |
vamgehealthcare11 | 9:5263aacbda53 | 98 | en = 1; |
vamgehealthcare11 | 9:5263aacbda53 | 99 | wait(1); |
rschimpf78 | 3:fd2ca631ab44 | 100 | |
vamgehealthcare11 | 9:5263aacbda53 | 101 | if (dist >=480){ |
vamgehealthcare11 | 9:5263aacbda53 | 102 | pc.printf("\nSelector Distance out of Range:%ld",dist); |
vamgehealthcare11 | 9:5263aacbda53 | 103 | goto LOOPY; |
rschimpf78 | 3:fd2ca631ab44 | 104 | } |
vamgehealthcare11 | 9:5263aacbda53 | 105 | else if (durationSM >= 56000){ |
vamgehealthcare11 | 9:5263aacbda53 | 106 | pc.printf("\nSelector Motor Time Out"); |
vamgehealthcare11 | 9:5263aacbda53 | 107 | goto LOOPY; |
rschimpf78 | 3:fd2ca631ab44 | 108 | } |
vamgehealthcare11 | 9:5263aacbda53 | 109 | else{ |
vamgehealthcare11 | 9:5263aacbda53 | 110 | pc.printf("\nPlates Selected: %ld", plates); |
vamgehealthcare11 | 9:5263aacbda53 | 111 | in1=1; |
vamgehealthcare11 | 9:5263aacbda53 | 112 | in2=0; |
vamgehealthcare11 | 9:5263aacbda53 | 113 | wait(58); |
vamgehealthcare11 | 9:5263aacbda53 | 114 | in1=1; |
vamgehealthcare11 | 9:5263aacbda53 | 115 | in2=1; |
vamgehealthcare11 | 9:5263aacbda53 | 116 | } |
vamgehealthcare11 | 9:5263aacbda53 | 117 | } |
vamgehealthcare11 | 9:5263aacbda53 | 118 | |
vamgehealthcare11 | 9:5263aacbda53 | 119 | else if (command==2){ |
vamgehealthcare11 | 9:5263aacbda53 | 120 | |
vamgehealthcare11 | 9:5263aacbda53 | 121 | unsigned int pathdist; |
vamgehealthcare11 | 9:5263aacbda53 | 122 | int path_sheets; |
vamgehealthcare11 | 9:5263aacbda53 | 123 | int detectionTOL = 12; |
vamgehealthcare11 | 9:5263aacbda53 | 124 | int sens_pos = 131; |
vamgehealthcare11 | 9:5263aacbda53 | 125 | int sheet_th = 25; |
vamgehealthcare11 | 9:5263aacbda53 | 126 | pathsensor.start(); |
vamgehealthcare11 | 9:5263aacbda53 | 127 | wait_ms(500); |
vamgehealthcare11 | 9:5263aacbda53 | 128 | pathdist=pathsensor.get_dist_cm(); |
rschimpf78 | 3:fd2ca631ab44 | 129 | |
vamgehealthcare11 | 9:5263aacbda53 | 130 | if (pathdist >= sens_pos-detectionTOL && pathdist <= sens_pos+detectionTOL){ //110,130 |
vamgehealthcare11 | 9:5263aacbda53 | 131 | path_sheets = 16; |
vamgehealthcare11 | 9:5263aacbda53 | 132 | } |
vamgehealthcare11 | 9:5263aacbda53 | 133 | else if (pathdist >= sens_pos-detectionTOL+sheet_th && pathdist <= sens_pos+detectionTOL+sheet_th){ //152,168 a: |
vamgehealthcare11 | 9:5263aacbda53 | 134 | path_sheets = 15; |
vamgehealthcare11 | 9:5263aacbda53 | 135 | } |
vamgehealthcare11 | 9:5263aacbda53 | 136 | else if (pathdist >= sens_pos-detectionTOL+2*sheet_th && pathdist <= sens_pos+detectionTOL+2*sheet_th){ //179-191 |
vamgehealthcare11 | 9:5263aacbda53 | 137 | path_sheets = 14; |
vamgehealthcare11 | 9:5263aacbda53 | 138 | } |
vamgehealthcare11 | 9:5263aacbda53 | 139 | else if (pathdist >= sens_pos-detectionTOL+3*sheet_th && pathdist <= sens_pos+detectionTOL+3*sheet_th){ //205-217 |
vamgehealthcare11 | 9:5263aacbda53 | 140 | path_sheets = 13; |
vamgehealthcare11 | 9:5263aacbda53 | 141 | } |
vamgehealthcare11 | 9:5263aacbda53 | 142 | else if (pathdist >= sens_pos-detectionTOL+4*sheet_th && pathdist <= sens_pos+detectionTOL+4*sheet_th){ //231-243 |
vamgehealthcare11 | 9:5263aacbda53 | 143 | path_sheets = 12; |
vamgehealthcare11 | 9:5263aacbda53 | 144 | } |
vamgehealthcare11 | 9:5263aacbda53 | 145 | else if (pathdist >= sens_pos-detectionTOL+5*sheet_th && pathdist <= sens_pos+detectionTOL+5*sheet_th){ //257-269 |
vamgehealthcare11 | 9:5263aacbda53 | 146 | path_sheets = 11; |
vamgehealthcare11 | 9:5263aacbda53 | 147 | } |
vamgehealthcare11 | 9:5263aacbda53 | 148 | else if (pathdist >= sens_pos-detectionTOL+6*sheet_th && pathdist <= sens_pos+detectionTOL+6*sheet_th){ //283-295 |
rschimpf78 | 3:fd2ca631ab44 | 149 | path_sheets = 10; |
rschimpf78 | 3:fd2ca631ab44 | 150 | |
rschimpf78 | 3:fd2ca631ab44 | 151 | } |
vamgehealthcare11 | 9:5263aacbda53 | 152 | else if (pathdist >= sens_pos-detectionTOL+7*sheet_th && pathdist <= sens_pos+detectionTOL+7*sheet_th){ //309-321 |
rschimpf78 | 3:fd2ca631ab44 | 153 | path_sheets = 9; |
rschimpf78 | 3:fd2ca631ab44 | 154 | |
rschimpf78 | 3:fd2ca631ab44 | 155 | } |
vamgehealthcare11 | 9:5263aacbda53 | 156 | else if (pathdist >= sens_pos-detectionTOL+8*sheet_th && pathdist <= sens_pos+detectionTOL+8*sheet_th){ //323-333 |
rschimpf78 | 3:fd2ca631ab44 | 157 | path_sheets = 8; |
rschimpf78 | 3:fd2ca631ab44 | 158 | |
rschimpf78 | 3:fd2ca631ab44 | 159 | } |
vamgehealthcare11 | 9:5263aacbda53 | 160 | else if (pathdist >= sens_pos-detectionTOL+9*sheet_th && pathdist <= sens_pos+detectionTOL+9*sheet_th){ //349-359 |
rschimpf78 | 3:fd2ca631ab44 | 161 | path_sheets = 7; |
rschimpf78 | 3:fd2ca631ab44 | 162 | |
rschimpf78 | 3:fd2ca631ab44 | 163 | } |
vamgehealthcare11 | 9:5263aacbda53 | 164 | else if (pathdist >= sens_pos-detectionTOL+10*sheet_th && pathdist <= sens_pos+detectionTOL+10*sheet_th){ |
rschimpf78 | 3:fd2ca631ab44 | 165 | path_sheets = 6; |
rschimpf78 | 3:fd2ca631ab44 | 166 | |
rschimpf78 | 3:fd2ca631ab44 | 167 | } |
vamgehealthcare11 | 9:5263aacbda53 | 168 | else if (pathdist >= sens_pos-detectionTOL+11*sheet_th && pathdist <= sens_pos+detectionTOL+11*sheet_th){ |
rschimpf78 | 3:fd2ca631ab44 | 169 | path_sheets = 5; |
rschimpf78 | 3:fd2ca631ab44 | 170 | |
rschimpf78 | 3:fd2ca631ab44 | 171 | } |
vamgehealthcare11 | 9:5263aacbda53 | 172 | else if (pathdist >= sens_pos-detectionTOL+12*sheet_th && pathdist <= sens_pos+detectionTOL+12*sheet_th){ |
rschimpf78 | 3:fd2ca631ab44 | 173 | path_sheets = 4; |
rschimpf78 | 3:fd2ca631ab44 | 174 | |
rschimpf78 | 3:fd2ca631ab44 | 175 | } |
vamgehealthcare11 | 9:5263aacbda53 | 176 | else if (pathdist >= sens_pos-detectionTOL+13*sheet_th && pathdist <= sens_pos+detectionTOL+13*sheet_th){ //468,478 |
rschimpf78 | 3:fd2ca631ab44 | 177 | path_sheets = 3; |
rschimpf78 | 3:fd2ca631ab44 | 178 | |
rschimpf78 | 3:fd2ca631ab44 | 179 | } |
vamgehealthcare11 | 9:5263aacbda53 | 180 | else if (pathdist >= sens_pos-detectionTOL+14*sheet_th && pathdist <= sens_pos+detectionTOL+14*sheet_th){ //494,504 |
rschimpf78 | 3:fd2ca631ab44 | 181 | path_sheets = 2; |
rschimpf78 | 3:fd2ca631ab44 | 182 | |
rschimpf78 | 3:fd2ca631ab44 | 183 | } |
vamgehealthcare11 | 9:5263aacbda53 | 184 | else if (pathdist >= sens_pos-10-detectionTOL+15*sheet_th && pathdist <= sens_pos-10+detectionTOL+15*sheet_th){//greater than 509 less 517 |
rschimpf78 | 3:fd2ca631ab44 | 185 | path_sheets = 1; |
rschimpf78 | 3:fd2ca631ab44 | 186 | |
rschimpf78 | 3:fd2ca631ab44 | 187 | } |
vamgehealthcare11 | 9:5263aacbda53 | 188 | else if (pathdist > sens_pos-detectionTOL+16*sheet_th){ //greater than 534 |
rschimpf78 | 3:fd2ca631ab44 | 189 | path_sheets = 0; |
vamgehealthcare11 | 9:5263aacbda53 | 190 | } |
vamgehealthcare11 | 9:5263aacbda53 | 191 | else { |
vamgehealthcare11 | 9:5263aacbda53 | 192 | pc.printf("\nBeam Path Detector distance out of range : %ld", pathdist); |
vamgehealthcare11 | 9:5263aacbda53 | 193 | wait(2); |
vamgehealthcare11 | 9:5263aacbda53 | 194 | goto LOOPY; |
vamgehealthcare11 | 9:5263aacbda53 | 195 | } |
vamgehealthcare11 | 9:5263aacbda53 | 196 | pc.printf("\nPlates Detected in Beam Path: %ld", path_sheets); |
vamgehealthcare11 | 9:5263aacbda53 | 197 | wait(2); |
rschimpf78 | 3:fd2ca631ab44 | 198 | } |
vamgehealthcare11 | 9:5263aacbda53 | 199 | |
vamgehealthcare11 | 9:5263aacbda53 | 200 | else if (command==3){ |
vamgehealthcare11 | 9:5263aacbda53 | 201 | |
vamgehealthcare11 | 9:5263aacbda53 | 202 | millisStart(); |
vamgehealthcare11 | 9:5263aacbda53 | 203 | long Duration = 0; |
vamgehealthcare11 | 9:5263aacbda53 | 204 | long StartTime = millis(); |
rschimpf78 | 5:e958d61e0564 | 205 | |
vamgehealthcare11 | 9:5263aacbda53 | 206 | while(magnetSwitch == 1 && homeSwitch == 1 && Duration <= 58000 ){ |
vamgehealthcare11 | 9:5263aacbda53 | 207 | in1=0; |
vamgehealthcare11 | 9:5263aacbda53 | 208 | in2=1; |
vamgehealthcare11 | 9:5263aacbda53 | 209 | long CurrentTime = millis(); |
vamgehealthcare11 | 9:5263aacbda53 | 210 | Duration = CurrentTime-StartTime; |
vamgehealthcare11 | 9:5263aacbda53 | 211 | pc.printf("\nDuration: %d\r\n", Duration); |
vamgehealthcare11 | 9:5263aacbda53 | 212 | } |
vamgehealthcare11 | 9:5263aacbda53 | 213 | |
vamgehealthcare11 | 9:5263aacbda53 | 214 | in1=1; |
vamgehealthcare11 | 9:5263aacbda53 | 215 | in2=1; |
vamgehealthcare11 | 9:5263aacbda53 | 216 | |
vamgehealthcare11 | 9:5263aacbda53 | 217 | if (Duration > 58000){ |
vamgehealthcare11 | 9:5263aacbda53 | 218 | pc.printf("\nRetraction Time Out Error"); |
vamgehealthcare11 | 9:5263aacbda53 | 219 | goto LOOPY; |
vamgehealthcare11 | 9:5263aacbda53 | 220 | } |
vamgehealthcare11 | 9:5263aacbda53 | 221 | else if (homeSwitch == 0){ |
vamgehealthcare11 | 9:5263aacbda53 | 222 | pc.printf("\nMagnet Switch Broken"); |
vamgehealthcare11 | 9:5263aacbda53 | 223 | goto LOOPY; |
vamgehealthcare11 | 9:5263aacbda53 | 224 | } |
vamgehealthcare11 | 9:5263aacbda53 | 225 | else{ |
vamgehealthcare11 | 9:5263aacbda53 | 226 | pc.printf("\nPlate Retraction Complete"); |
vamgehealthcare11 | 9:5263aacbda53 | 227 | } |
vamgehealthcare11 | 9:5263aacbda53 | 228 | } |
vamgehealthcare11 | 9:5263aacbda53 | 229 | |
vamgehealthcare11 | 9:5263aacbda53 | 230 | else if (command==4){ |
vamgehealthcare11 | 9:5263aacbda53 | 231 | |
vamgehealthcare11 | 9:5263aacbda53 | 232 | int plates = 0; |
vamgehealthcare11 | 9:5263aacbda53 | 233 | unsigned int dist; |
vamgehealthcare11 | 9:5263aacbda53 | 234 | int platedist; |
vamgehealthcare11 | 9:5263aacbda53 | 235 | |
vamgehealthcare11 | 9:5263aacbda53 | 236 | while(plates<=0 || plates>16){ |
vamgehealthcare11 | 9:5263aacbda53 | 237 | |
vamgehealthcare11 | 9:5263aacbda53 | 238 | pc.printf("\nEnter Number of Plates to Select 0-16: "); |
vamgehealthcare11 | 9:5263aacbda53 | 239 | pc.scanf("%d",&plates); |
vamgehealthcare11 | 9:5263aacbda53 | 240 | |
vamgehealthcare11 | 9:5263aacbda53 | 241 | if (plates > 16 || plates < 0 ){ |
vamgehealthcare11 | 9:5263aacbda53 | 242 | pc.printf("\nInvalid Entry"); |
vamgehealthcare11 | 9:5263aacbda53 | 243 | } |
vamgehealthcare11 | 9:5263aacbda53 | 244 | else{ |
vamgehealthcare11 | 9:5263aacbda53 | 245 | pc.printf("\nPlates Requested: %ld", plates); |
vamgehealthcare11 | 9:5263aacbda53 | 246 | } |
vamgehealthcare11 | 9:5263aacbda53 | 247 | } |
vamgehealthcare11 | 9:5263aacbda53 | 248 | |
vamgehealthcare11 | 9:5263aacbda53 | 249 | if (magnetSwitch == 1){ |
vamgehealthcare11 | 9:5263aacbda53 | 250 | pc.printf("\nNot in Home Position"); |
vamgehealthcare11 | 9:5263aacbda53 | 251 | goto LOOPY; |
vamgehealthcare11 | 9:5263aacbda53 | 252 | } |
vamgehealthcare11 | 9:5263aacbda53 | 253 | else{ |
vamgehealthcare11 | 9:5263aacbda53 | 254 | wait(1); |
vamgehealthcare11 | 9:5263aacbda53 | 255 | in1=1; |
vamgehealthcare11 | 9:5263aacbda53 | 256 | in2=0; |
vamgehealthcare11 | 9:5263aacbda53 | 257 | wait_ms(900); |
vamgehealthcare11 | 9:5263aacbda53 | 258 | in1=1; |
vamgehealthcare11 | 9:5263aacbda53 | 259 | in2=1; |
vamgehealthcare11 | 9:5263aacbda53 | 260 | } |
vamgehealthcare11 | 9:5263aacbda53 | 261 | |
vamgehealthcare11 | 9:5263aacbda53 | 262 | platedist = (468-24*plates); |
vamgehealthcare11 | 9:5263aacbda53 | 263 | wait(1); |
vamgehealthcare11 | 9:5263aacbda53 | 264 | heightsensor.start(); |
vamgehealthcare11 | 9:5263aacbda53 | 265 | wait_ms(500); |
vamgehealthcare11 | 9:5263aacbda53 | 266 | dist = heightsensor.get_dist_cm(); |
vamgehealthcare11 | 9:5263aacbda53 | 267 | millisStart(); |
vamgehealthcare11 | 9:5263aacbda53 | 268 | long durationSM = 0; |
vamgehealthcare11 | 9:5263aacbda53 | 269 | long starttimeSM = millis(); |
vamgehealthcare11 | 9:5263aacbda53 | 270 | pc.printf("\nPlate Distance:%ld",platedist); |
vamgehealthcare11 | 9:5263aacbda53 | 271 | pc.printf("\nSelector Height:%ld",dist); |
vamgehealthcare11 | 9:5263aacbda53 | 272 | |
vamgehealthcare11 | 9:5263aacbda53 | 273 | while(dist < platedist-2 || dist > platedist+2 && dist < 480 && durationSM <56000){ |
vamgehealthcare11 | 9:5263aacbda53 | 274 | |
vamgehealthcare11 | 9:5263aacbda53 | 275 | heightsensor.start(); |
vamgehealthcare11 | 9:5263aacbda53 | 276 | dist = heightsensor.get_dist_cm(); |
vamgehealthcare11 | 9:5263aacbda53 | 277 | long currenttimeSM = millis(); |
vamgehealthcare11 | 9:5263aacbda53 | 278 | durationSM = currenttimeSM-starttimeSM; |
vamgehealthcare11 | 9:5263aacbda53 | 279 | pc.printf("\nSelector Height:%ld",dist); |
vamgehealthcare11 | 9:5263aacbda53 | 280 | en = 0; |
vamgehealthcare11 | 9:5263aacbda53 | 281 | mot.setSpeed(500); |
vamgehealthcare11 | 9:5263aacbda53 | 282 | |
vamgehealthcare11 | 9:5263aacbda53 | 283 | if(dist<platedist-2){ |
vamgehealthcare11 | 9:5263aacbda53 | 284 | mot.rotate(1); |
vamgehealthcare11 | 9:5263aacbda53 | 285 | wait(0.5); |
vamgehealthcare11 | 9:5263aacbda53 | 286 | } |
vamgehealthcare11 | 9:5263aacbda53 | 287 | if(dist>platedist+2){ |
vamgehealthcare11 | 9:5263aacbda53 | 288 | mot.rotate(0); |
vamgehealthcare11 | 9:5263aacbda53 | 289 | wait(0.5); |
vamgehealthcare11 | 9:5263aacbda53 | 290 | } |
vamgehealthcare11 | 9:5263aacbda53 | 291 | mot.stop(); |
vamgehealthcare11 | 9:5263aacbda53 | 292 | } |
vamgehealthcare11 | 9:5263aacbda53 | 293 | |
vamgehealthcare11 | 9:5263aacbda53 | 294 | mot.stop(); |
vamgehealthcare11 | 9:5263aacbda53 | 295 | en = 1; |
vamgehealthcare11 | 9:5263aacbda53 | 296 | wait(1); |
vamgehealthcare11 | 9:5263aacbda53 | 297 | |
vamgehealthcare11 | 9:5263aacbda53 | 298 | if (dist >=480){ |
vamgehealthcare11 | 9:5263aacbda53 | 299 | pc.printf("\nSelector Distance out of Range:%ld",dist); |
vamgehealthcare11 | 9:5263aacbda53 | 300 | goto LOOPY; |
vamgehealthcare11 | 9:5263aacbda53 | 301 | } |
vamgehealthcare11 | 9:5263aacbda53 | 302 | else if (durationSM >= 56000){ |
vamgehealthcare11 | 9:5263aacbda53 | 303 | pc.printf("\nSelector Motor Time Out"); |
vamgehealthcare11 | 9:5263aacbda53 | 304 | goto LOOPY; |
vamgehealthcare11 | 9:5263aacbda53 | 305 | } |
vamgehealthcare11 | 9:5263aacbda53 | 306 | else{ |
vamgehealthcare11 | 9:5263aacbda53 | 307 | pc.printf("\nSelection Finished"); |
vamgehealthcare11 | 9:5263aacbda53 | 308 | } |
rschimpf78 | 3:fd2ca631ab44 | 309 | } |
vamgehealthcare11 | 9:5263aacbda53 | 310 | else { |
vamgehealthcare11 | 9:5263aacbda53 | 311 | pc.printf("\nInvalid Command"); |
rschimpf78 | 3:fd2ca631ab44 | 312 | } |
rschimpf78 | 3:fd2ca631ab44 | 313 | } |
rschimpf78 | 2:e8f8095464cf | 314 | } |