VAM
Dependencies: Stepper mbed HCSR04 millis
main.cpp@5:e958d61e0564, 2018-12-19 (annotated)
- Committer:
- rschimpf78
- Date:
- Wed Dec 19 19:39:25 2018 +0000
- Revision:
- 5:e958d61e0564
- Parent:
- 4:1a4022b21dae
- Child:
- 6:6ca8a0ef7d4a
version4;
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 | 3:fd2ca631ab44 | 6 | Serial pc(USBTX, USBRX); |
rschimpf78 | 3:fd2ca631ab44 | 7 | HCSR04 heightsensor(PTA2,PTC2); //(trig,echo) |
rschimpf78 | 3:fd2ca631ab44 | 8 | HCSR04 pathsensor(PTD3,PTD2); |
rschimpf78 | 3:fd2ca631ab44 | 9 | DigitalOut in1(PTC12); |
rschimpf78 | 3:fd2ca631ab44 | 10 | DigitalOut in2(D7); |
rschimpf78 | 3:fd2ca631ab44 | 11 | DigitalIn homeSwitch(D9); |
rschimpf78 | 3:fd2ca631ab44 | 12 | Stepper mot(D3,D4); //(D3 to PUL+, D4 to DIR+) |
rschimpf78 | 2:e8f8095464cf | 13 | DigitalOut en(D2); |
rschimpf78 | 0:88834eed3de0 | 14 | |
rschimpf78 | 3:fd2ca631ab44 | 15 | volatile int plates=0; |
rschimpf78 | 3:fd2ca631ab44 | 16 | volatile unsigned int sheets=0; |
rschimpf78 | 3:fd2ca631ab44 | 17 | volatile unsigned int path_sheets=0; |
rschimpf78 | 0:88834eed3de0 | 18 | |
rschimpf78 | 3:fd2ca631ab44 | 19 | void plate_selection() |
rschimpf78 | 0:88834eed3de0 | 20 | { |
rschimpf78 | 3:fd2ca631ab44 | 21 | unsigned int dist; |
rschimpf78 | 3:fd2ca631ab44 | 22 | int er = 5; |
rschimpf78 | 4:1a4022b21dae | 23 | int fp = 457; //adjust if needed |
rschimpf78 | 3:fd2ca631ab44 | 24 | int lp = 64; //adjust if needed |
rschimpf78 | 3:fd2ca631ab44 | 25 | int tp = 25; |
rschimpf78 | 5:e958d61e0564 | 26 | wait(1); |
rschimpf78 | 5:e958d61e0564 | 27 | in1=1; |
rschimpf78 | 5:e958d61e0564 | 28 | in2=0; |
rschimpf78 | 5:e958d61e0564 | 29 | wait_ms(600); |
rschimpf78 | 5:e958d61e0564 | 30 | in1=1; |
rschimpf78 | 5:e958d61e0564 | 31 | in2=1; |
rschimpf78 | 5:e958d61e0564 | 32 | wait(1); |
rschimpf78 | 3:fd2ca631ab44 | 33 | while (plates!=sheets) { |
rschimpf78 | 3:fd2ca631ab44 | 34 | heightsensor.start(); |
rschimpf78 | 3:fd2ca631ab44 | 35 | wait_ms(500); |
rschimpf78 | 3:fd2ca631ab44 | 36 | dist=heightsensor.get_dist_cm(); |
rschimpf78 | 3:fd2ca631ab44 | 37 | pc.printf("\nmm:%ld",dist); |
rschimpf78 | 3:fd2ca631ab44 | 38 | |
rschimpf78 | 3:fd2ca631ab44 | 39 | if (dist<=lp-10 || dist >= fp+10){ |
rschimpf78 | 3:fd2ca631ab44 | 40 | mot.stop(); |
rschimpf78 | 3:fd2ca631ab44 | 41 | en = 1; |
rschimpf78 | 3:fd2ca631ab44 | 42 | sheets = plates; |
rschimpf78 | 3:fd2ca631ab44 | 43 | pc.printf("\nERROR: Selector is outside of plate range\nRestart/Reset Program"); |
rschimpf78 | 3:fd2ca631ab44 | 44 | } |
rschimpf78 | 3:fd2ca631ab44 | 45 | else if (plates<sheets){ |
rschimpf78 | 3:fd2ca631ab44 | 46 | en = 0; |
rschimpf78 | 3:fd2ca631ab44 | 47 | mot.setSpeed(600); |
rschimpf78 | 3:fd2ca631ab44 | 48 | mot.rotate(1); |
rschimpf78 | 3:fd2ca631ab44 | 49 | } |
rschimpf78 | 3:fd2ca631ab44 | 50 | else{ |
rschimpf78 | 3:fd2ca631ab44 | 51 | en = 0; |
rschimpf78 | 3:fd2ca631ab44 | 52 | mot.setSpeed(600); |
rschimpf78 | 3:fd2ca631ab44 | 53 | mot.rotate(0); |
rschimpf78 | 3:fd2ca631ab44 | 54 | } |
rschimpf78 | 3:fd2ca631ab44 | 55 | |
rschimpf78 | 3:fd2ca631ab44 | 56 | if (dist<=fp+er && dist>=fp-er){ //450,440 |
rschimpf78 | 3:fd2ca631ab44 | 57 | sheets = 1; |
rschimpf78 | 3:fd2ca631ab44 | 58 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 59 | } |
rschimpf78 | 3:fd2ca631ab44 | 60 | |
rschimpf78 | 3:fd2ca631ab44 | 61 | if (dist<= fp-tp+er && dist>=fp-tp-er){ //424,414 |
rschimpf78 | 3:fd2ca631ab44 | 62 | sheets = 2; |
rschimpf78 | 3:fd2ca631ab44 | 63 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 64 | } |
rschimpf78 | 3:fd2ca631ab44 | 65 | |
rschimpf78 | 3:fd2ca631ab44 | 66 | if (dist<= fp-2*tp+er && dist>=fp-2*tp-er){ |
rschimpf78 | 3:fd2ca631ab44 | 67 | sheets = 3; |
rschimpf78 | 3:fd2ca631ab44 | 68 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 69 | } |
rschimpf78 | 3:fd2ca631ab44 | 70 | |
rschimpf78 | 3:fd2ca631ab44 | 71 | if (dist<= fp-3*tp+er && dist>=fp-3*tp-er){ |
rschimpf78 | 3:fd2ca631ab44 | 72 | sheets = 4; |
rschimpf78 | 3:fd2ca631ab44 | 73 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 74 | } |
rschimpf78 | 3:fd2ca631ab44 | 75 | if (dist<= fp-4*tp+er && dist>=fp-4*tp-er){ |
rschimpf78 | 3:fd2ca631ab44 | 76 | sheets = 5; |
rschimpf78 | 3:fd2ca631ab44 | 77 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 78 | } |
rschimpf78 | 3:fd2ca631ab44 | 79 | if (dist<= fp-5*tp+er && dist>=fp-5*tp-er){ |
rschimpf78 | 3:fd2ca631ab44 | 80 | sheets = 6; |
rschimpf78 | 3:fd2ca631ab44 | 81 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 82 | } |
rschimpf78 | 3:fd2ca631ab44 | 83 | if (dist<= fp-6*tp+er && dist>=fp-6*tp-er){ |
rschimpf78 | 3:fd2ca631ab44 | 84 | sheets = 7; |
rschimpf78 | 3:fd2ca631ab44 | 85 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 86 | } |
rschimpf78 | 3:fd2ca631ab44 | 87 | if (dist<= fp-7*tp+er && dist>=fp-7*tp-er){ |
rschimpf78 | 3:fd2ca631ab44 | 88 | sheets = 8; |
rschimpf78 | 3:fd2ca631ab44 | 89 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 90 | } |
rschimpf78 | 3:fd2ca631ab44 | 91 | if (dist<= fp-8*tp+er && dist>=fp-8*tp-er){ |
rschimpf78 | 3:fd2ca631ab44 | 92 | sheets = 9; |
rschimpf78 | 3:fd2ca631ab44 | 93 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 94 | } |
rschimpf78 | 3:fd2ca631ab44 | 95 | if (dist<= fp-9*tp+er && dist>=fp-9*tp-er){ |
rschimpf78 | 3:fd2ca631ab44 | 96 | sheets = 10; |
rschimpf78 | 3:fd2ca631ab44 | 97 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 98 | } |
rschimpf78 | 3:fd2ca631ab44 | 99 | if (dist<= fp-10*tp+er && dist>=fp-10*tp-er){ |
rschimpf78 | 3:fd2ca631ab44 | 100 | sheets = 11; |
rschimpf78 | 3:fd2ca631ab44 | 101 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 102 | } |
rschimpf78 | 3:fd2ca631ab44 | 103 | if (dist<= fp-11*tp+er && dist>=fp-11*tp-er){ |
rschimpf78 | 3:fd2ca631ab44 | 104 | sheets = 12; |
rschimpf78 | 3:fd2ca631ab44 | 105 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 106 | } |
rschimpf78 | 3:fd2ca631ab44 | 107 | if (dist<= fp-12*tp+er && dist>=fp-12*tp-er){ |
rschimpf78 | 3:fd2ca631ab44 | 108 | sheets = 13; |
rschimpf78 | 3:fd2ca631ab44 | 109 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 110 | } |
rschimpf78 | 3:fd2ca631ab44 | 111 | if (dist<= fp-13*tp+er && dist>=fp-13*tp-er){ |
rschimpf78 | 3:fd2ca631ab44 | 112 | sheets = 14; |
rschimpf78 | 3:fd2ca631ab44 | 113 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 114 | } |
rschimpf78 | 3:fd2ca631ab44 | 115 | if (dist<= fp-14*tp+er && dist>=fp-14*tp-er){ |
rschimpf78 | 3:fd2ca631ab44 | 116 | sheets = 15; |
rschimpf78 | 3:fd2ca631ab44 | 117 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 118 | } |
rschimpf78 | 3:fd2ca631ab44 | 119 | if (dist<= fp-15*tp+er && dist>=fp-15*tp-er){ // 75, 65 |
rschimpf78 | 3:fd2ca631ab44 | 120 | sheets = 16; |
rschimpf78 | 3:fd2ca631ab44 | 121 | pc.printf("\nSheets selected:%ld",sheets); |
rschimpf78 | 3:fd2ca631ab44 | 122 | } |
rschimpf78 | 3:fd2ca631ab44 | 123 | } |
rschimpf78 | 3:fd2ca631ab44 | 124 | mot.stop(); |
rschimpf78 | 3:fd2ca631ab44 | 125 | en = 1; |
rschimpf78 | 3:fd2ca631ab44 | 126 | wait(1); |
rschimpf78 | 3:fd2ca631ab44 | 127 | } |
rschimpf78 | 3:fd2ca631ab44 | 128 | |
rschimpf78 | 3:fd2ca631ab44 | 129 | void beam() |
rschimpf78 | 3:fd2ca631ab44 | 130 | { |
rschimpf78 | 3:fd2ca631ab44 | 131 | |
rschimpf78 | 3:fd2ca631ab44 | 132 | unsigned int path_dist; |
rschimpf78 | 4:1a4022b21dae | 133 | int err = 11; |
rschimpf78 | 4:1a4022b21dae | 134 | int sens_pos = 126; //adjust if needed //535 0 plates |
rschimpf78 | 3:fd2ca631ab44 | 135 | int sheet_th = 25; |
rschimpf78 | 3:fd2ca631ab44 | 136 | pathsensor.start(); |
rschimpf78 | 3:fd2ca631ab44 | 137 | wait_ms(500); |
rschimpf78 | 3:fd2ca631ab44 | 138 | path_dist=pathsensor.get_dist_cm(); |
rschimpf78 | 3:fd2ca631ab44 | 139 | pc.printf("\nBeam Path Sensor : %ld",path_dist); |
rschimpf78 | 3:fd2ca631ab44 | 140 | path_sheets = 17; |
rschimpf78 | 3:fd2ca631ab44 | 141 | |
rschimpf78 | 4:1a4022b21dae | 142 | if (path_dist >= sens_pos-err && path_dist <= sens_pos+err){ //110,130 |
rschimpf78 | 3:fd2ca631ab44 | 143 | path_sheets = 16; |
rschimpf78 | 3:fd2ca631ab44 | 144 | |
rschimpf78 | 3:fd2ca631ab44 | 145 | } |
rschimpf78 | 3:fd2ca631ab44 | 146 | if (path_dist >= sens_pos-err+sheet_th && path_dist <= sens_pos+err+sheet_th){ //152,168 a: |
rschimpf78 | 3:fd2ca631ab44 | 147 | path_sheets = 15; |
rschimpf78 | 3:fd2ca631ab44 | 148 | |
rschimpf78 | 3:fd2ca631ab44 | 149 | } |
rschimpf78 | 3:fd2ca631ab44 | 150 | if (path_dist >= sens_pos-err+2*sheet_th && path_dist <= sens_pos+err+2*sheet_th){ //179-191 |
rschimpf78 | 3:fd2ca631ab44 | 151 | path_sheets = 14; |
rschimpf78 | 3:fd2ca631ab44 | 152 | |
rschimpf78 | 3:fd2ca631ab44 | 153 | } |
rschimpf78 | 3:fd2ca631ab44 | 154 | if (path_dist >= sens_pos-err+3*sheet_th && path_dist <= sens_pos+err+3*sheet_th){ //205-217 |
rschimpf78 | 3:fd2ca631ab44 | 155 | path_sheets = 13; |
rschimpf78 | 3:fd2ca631ab44 | 156 | |
rschimpf78 | 3:fd2ca631ab44 | 157 | } |
rschimpf78 | 3:fd2ca631ab44 | 158 | if (path_dist >= sens_pos-err+4*sheet_th && path_dist <= sens_pos+err+4*sheet_th){ //231-243 |
rschimpf78 | 3:fd2ca631ab44 | 159 | path_sheets = 12; |
rschimpf78 | 3:fd2ca631ab44 | 160 | |
rschimpf78 | 3:fd2ca631ab44 | 161 | } |
rschimpf78 | 3:fd2ca631ab44 | 162 | if (path_dist >= sens_pos-err+5*sheet_th && path_dist <= sens_pos+err+5*sheet_th){ //257-269 |
rschimpf78 | 3:fd2ca631ab44 | 163 | path_sheets = 11; |
rschimpf78 | 3:fd2ca631ab44 | 164 | |
rschimpf78 | 3:fd2ca631ab44 | 165 | } |
rschimpf78 | 3:fd2ca631ab44 | 166 | if (path_dist >= sens_pos-err+6*sheet_th && path_dist <= sens_pos+err+6*sheet_th){ //283-295 |
rschimpf78 | 3:fd2ca631ab44 | 167 | path_sheets = 10; |
rschimpf78 | 3:fd2ca631ab44 | 168 | |
rschimpf78 | 3:fd2ca631ab44 | 169 | } |
rschimpf78 | 3:fd2ca631ab44 | 170 | if (path_dist >= sens_pos-err+7*sheet_th && path_dist <= sens_pos+err+7*sheet_th){ //309-321 |
rschimpf78 | 3:fd2ca631ab44 | 171 | path_sheets = 9; |
rschimpf78 | 3:fd2ca631ab44 | 172 | |
rschimpf78 | 3:fd2ca631ab44 | 173 | } |
rschimpf78 | 3:fd2ca631ab44 | 174 | if (path_dist >= sens_pos-err+8*sheet_th && path_dist <= sens_pos+err+8*sheet_th){ //323-333 |
rschimpf78 | 3:fd2ca631ab44 | 175 | path_sheets = 8; |
rschimpf78 | 3:fd2ca631ab44 | 176 | |
rschimpf78 | 3:fd2ca631ab44 | 177 | } |
rschimpf78 | 3:fd2ca631ab44 | 178 | if (path_dist >= sens_pos-err+9*sheet_th && path_dist <= sens_pos+err+9*sheet_th){ //349-359 |
rschimpf78 | 3:fd2ca631ab44 | 179 | path_sheets = 7; |
rschimpf78 | 3:fd2ca631ab44 | 180 | |
rschimpf78 | 3:fd2ca631ab44 | 181 | } |
rschimpf78 | 3:fd2ca631ab44 | 182 | if (path_dist >= sens_pos-err+10*sheet_th && path_dist <= sens_pos+err+10*sheet_th){ |
rschimpf78 | 3:fd2ca631ab44 | 183 | path_sheets = 6; |
rschimpf78 | 3:fd2ca631ab44 | 184 | |
rschimpf78 | 3:fd2ca631ab44 | 185 | } |
rschimpf78 | 3:fd2ca631ab44 | 186 | if (path_dist >= sens_pos-err+11*sheet_th && path_dist <= sens_pos+err+11*sheet_th){ |
rschimpf78 | 3:fd2ca631ab44 | 187 | path_sheets = 5; |
rschimpf78 | 3:fd2ca631ab44 | 188 | |
rschimpf78 | 3:fd2ca631ab44 | 189 | } |
rschimpf78 | 3:fd2ca631ab44 | 190 | if (path_dist >= sens_pos-err+12*sheet_th && path_dist <= sens_pos+err+12*sheet_th){ |
rschimpf78 | 3:fd2ca631ab44 | 191 | path_sheets = 4; |
rschimpf78 | 3:fd2ca631ab44 | 192 | |
rschimpf78 | 3:fd2ca631ab44 | 193 | } |
rschimpf78 | 3:fd2ca631ab44 | 194 | if (path_dist >= sens_pos-err+13*sheet_th && path_dist <= sens_pos+err+13*sheet_th){ //468,478 |
rschimpf78 | 3:fd2ca631ab44 | 195 | path_sheets = 3; |
rschimpf78 | 3:fd2ca631ab44 | 196 | |
rschimpf78 | 3:fd2ca631ab44 | 197 | } |
rschimpf78 | 3:fd2ca631ab44 | 198 | if (path_dist >= sens_pos-err+14*sheet_th && path_dist <= sens_pos+err+14*sheet_th){ //494,504 |
rschimpf78 | 3:fd2ca631ab44 | 199 | path_sheets = 2; |
rschimpf78 | 3:fd2ca631ab44 | 200 | |
rschimpf78 | 3:fd2ca631ab44 | 201 | } |
rschimpf78 | 4:1a4022b21dae | 202 | if (path_dist >= sens_pos-10-err+15*sheet_th && path_dist <= sens_pos-10+err+15*sheet_th){//greater than 509 less 517 |
rschimpf78 | 3:fd2ca631ab44 | 203 | path_sheets = 1; |
rschimpf78 | 3:fd2ca631ab44 | 204 | |
rschimpf78 | 3:fd2ca631ab44 | 205 | } |
rschimpf78 | 4:1a4022b21dae | 206 | if (path_dist > sens_pos-err+16*sheet_th){ //greater than 534 |
rschimpf78 | 3:fd2ca631ab44 | 207 | path_sheets = 0; |
rschimpf78 | 3:fd2ca631ab44 | 208 | } |
rschimpf78 | 3:fd2ca631ab44 | 209 | } |
rschimpf78 | 3:fd2ca631ab44 | 210 | |
rschimpf78 | 3:fd2ca631ab44 | 211 | void platedetect() |
rschimpf78 | 3:fd2ca631ab44 | 212 | { |
rschimpf78 | 3:fd2ca631ab44 | 213 | if(homeSwitch==0 && path_sheets==0) |
rschimpf78 | 2:e8f8095464cf | 214 | { |
rschimpf78 | 3:fd2ca631ab44 | 215 | pc.printf("\nAll plates are in the start position"); |
rschimpf78 | 2:e8f8095464cf | 216 | } |
rschimpf78 | 3:fd2ca631ab44 | 217 | else if (homeSwitch==1 && path_sheets==0) |
rschimpf78 | 2:e8f8095464cf | 218 | { |
rschimpf78 | 3:fd2ca631ab44 | 219 | pc.printf("\nError-Plates are not fully extended"); |
rschimpf78 | 2:e8f8095464cf | 220 | } |
rschimpf78 | 2:e8f8095464cf | 221 | else |
rschimpf78 | 2:e8f8095464cf | 222 | { |
rschimpf78 | 3:fd2ca631ab44 | 223 | if (plates==path_sheets) |
rschimpf78 | 3:fd2ca631ab44 | 224 | { |
rschimpf78 | 3:fd2ca631ab44 | 225 | pc.printf("\nPlates in beam path:%ld",path_sheets); |
rschimpf78 | 3:fd2ca631ab44 | 226 | } |
rschimpf78 | 3:fd2ca631ab44 | 227 | else if (plates != path_sheets && path_sheets <= 16) |
rschimpf78 | 3:fd2ca631ab44 | 228 | { |
rschimpf78 | 3:fd2ca631ab44 | 229 | pc.printf("\nError: %ld",path_sheets); |
rschimpf78 | 3:fd2ca631ab44 | 230 | pc.printf(" Plates in beam path, but user sent %ld",plates); |
rschimpf78 | 3:fd2ca631ab44 | 231 | pc.printf(" Plates"); |
rschimpf78 | 3:fd2ca631ab44 | 232 | } |
rschimpf78 | 3:fd2ca631ab44 | 233 | else{ |
rschimpf78 | 3:fd2ca631ab44 | 234 | pc.printf("\nERROR: Additional objects detected in beam path"); |
rschimpf78 | 3:fd2ca631ab44 | 235 | } |
rschimpf78 | 3:fd2ca631ab44 | 236 | } |
rschimpf78 | 3:fd2ca631ab44 | 237 | } |
rschimpf78 | 3:fd2ca631ab44 | 238 | void retract() |
rschimpf78 | 0:88834eed3de0 | 239 | { |
rschimpf78 | 5:e958d61e0564 | 240 | millisStart(); |
rschimpf78 | 5:e958d61e0564 | 241 | long Duration = 0; |
rschimpf78 | 5:e958d61e0564 | 242 | long StartTime = millis(); |
rschimpf78 | 5:e958d61e0564 | 243 | |
rschimpf78 | 5:e958d61e0564 | 244 | while(homeSwitch == 1 && Duration <= 48000 ) |
rschimpf78 | 2:e8f8095464cf | 245 | { |
rschimpf78 | 0:88834eed3de0 | 246 | in1=0; |
rschimpf78 | 2:e8f8095464cf | 247 | in2=1; |
rschimpf78 | 5:e958d61e0564 | 248 | long CurrentTime = millis(); |
rschimpf78 | 5:e958d61e0564 | 249 | Duration = CurrentTime-StartTime; |
rschimpf78 | 5:e958d61e0564 | 250 | pc.printf("Duration = %d\r\n", Duration); |
rschimpf78 | 3:fd2ca631ab44 | 251 | } |
rschimpf78 | 2:e8f8095464cf | 252 | in1=1; |
rschimpf78 | 2:e8f8095464cf | 253 | in2=1; |
rschimpf78 | 0:88834eed3de0 | 254 | } |
rschimpf78 | 0:88834eed3de0 | 255 | |
rschimpf78 | 3:fd2ca631ab44 | 256 | void send() |
rschimpf78 | 3:fd2ca631ab44 | 257 | { |
rschimpf78 | 3:fd2ca631ab44 | 258 | in1=1; |
rschimpf78 | 3:fd2ca631ab44 | 259 | in2=0; |
rschimpf78 | 5:e958d61e0564 | 260 | wait(48); |
rschimpf78 | 0:88834eed3de0 | 261 | in1=1; |
rschimpf78 | 2:e8f8095464cf | 262 | in2=1; |
rschimpf78 | 0:88834eed3de0 | 263 | } |
rschimpf78 | 3:fd2ca631ab44 | 264 | |
rschimpf78 | 0:88834eed3de0 | 265 | void internalpullups() |
rschimpf78 | 0:88834eed3de0 | 266 | { |
rschimpf78 | 2:e8f8095464cf | 267 | homeSwitch.mode(PullUp); |
rschimpf78 | 0:88834eed3de0 | 268 | wait (.01); |
rschimpf78 | 0:88834eed3de0 | 269 | } |
rschimpf78 | 3:fd2ca631ab44 | 270 | |
rschimpf78 | 3:fd2ca631ab44 | 271 | void send_error_check() |
rschimpf78 | 3:fd2ca631ab44 | 272 | { |
rschimpf78 | 3:fd2ca631ab44 | 273 | if (plates <= 0 || plates >= 17) |
rschimpf78 | 2:e8f8095464cf | 274 | { |
rschimpf78 | 3:fd2ca631ab44 | 275 | pc.printf("\nERROR: Invalid Range |"); |
rschimpf78 | 2:e8f8095464cf | 276 | } |
rschimpf78 | 3:fd2ca631ab44 | 277 | else if(homeSwitch == 1) |
rschimpf78 | 3:fd2ca631ab44 | 278 | { |
rschimpf78 | 3:fd2ca631ab44 | 279 | pc.printf("\nERROR: Not at Home Position |"); |
rschimpf78 | 3:fd2ca631ab44 | 280 | } |
rschimpf78 | 3:fd2ca631ab44 | 281 | else |
rschimpf78 | 3:fd2ca631ab44 | 282 | { |
rschimpf78 | 3:fd2ca631ab44 | 283 | plate_selection(); |
rschimpf78 | 3:fd2ca631ab44 | 284 | send(); |
rschimpf78 | 3:fd2ca631ab44 | 285 | } |
rschimpf78 | 3:fd2ca631ab44 | 286 | } |
rschimpf78 | 3:fd2ca631ab44 | 287 | void select_error_check() |
rschimpf78 | 3:fd2ca631ab44 | 288 | { |
rschimpf78 | 3:fd2ca631ab44 | 289 | if (homeSwitch == 1) |
rschimpf78 | 3:fd2ca631ab44 | 290 | { |
rschimpf78 | 3:fd2ca631ab44 | 291 | pc.printf("\nERROR: Not at Home Position |"); |
rschimpf78 | 3:fd2ca631ab44 | 292 | } |
rschimpf78 | 3:fd2ca631ab44 | 293 | else |
rschimpf78 | 3:fd2ca631ab44 | 294 | { |
rschimpf78 | 3:fd2ca631ab44 | 295 | plate_selection(); |
rschimpf78 | 3:fd2ca631ab44 | 296 | } |
rschimpf78 | 3:fd2ca631ab44 | 297 | } |
rschimpf78 | 3:fd2ca631ab44 | 298 | void retract_error_check() |
rschimpf78 | 3:fd2ca631ab44 | 299 | { |
rschimpf78 | 3:fd2ca631ab44 | 300 | if (homeSwitch == 0) |
rschimpf78 | 3:fd2ca631ab44 | 301 | { |
rschimpf78 | 3:fd2ca631ab44 | 302 | pc.printf("\nERROR: Already at Home Position |"); |
rschimpf78 | 0:88834eed3de0 | 303 | } |
rschimpf78 | 2:e8f8095464cf | 304 | else |
rschimpf78 | 2:e8f8095464cf | 305 | { |
rschimpf78 | 3:fd2ca631ab44 | 306 | retract(); |
rschimpf78 | 2:e8f8095464cf | 307 | } |
rschimpf78 | 2:e8f8095464cf | 308 | } |
rschimpf78 | 0:88834eed3de0 | 309 | |
rschimpf78 | 0:88834eed3de0 | 310 | int main() |
rschimpf78 | 2:e8f8095464cf | 311 | { |
rschimpf78 | 2:e8f8095464cf | 312 | in1=1; |
rschimpf78 | 2:e8f8095464cf | 313 | in2=1; |
rschimpf78 | 2:e8f8095464cf | 314 | en = 1; |
rschimpf78 | 2:e8f8095464cf | 315 | wait(0.1); |
rschimpf78 | 0:88834eed3de0 | 316 | internalpullups(); |
rschimpf78 | 3:fd2ca631ab44 | 317 | wait(0.1); |
rschimpf78 | 2:e8f8095464cf | 318 | char command[15] = {0}; |
rschimpf78 | 3:fd2ca631ab44 | 319 | pc.printf("\nCommands:\n\n\ts [N]\t**moves N PMMA sheets in beam path\n\tr\t\t**removes all PMMA from beam path\n\tc [N]\t**raises bar to \n\tb\t\t**reports number of plates in beam path\n\n"); |
rschimpf78 | 2:e8f8095464cf | 320 | |
rschimpf78 | 2:e8f8095464cf | 321 | while(1) |
rschimpf78 | 0:88834eed3de0 | 322 | { |
rschimpf78 | 2:e8f8095464cf | 323 | pc.printf("\nRequests: "); |
rschimpf78 | 2:e8f8095464cf | 324 | pc.scanf("%s",&command); |
rschimpf78 | 2:e8f8095464cf | 325 | |
rschimpf78 | 3:fd2ca631ab44 | 326 | if (strcmp (command, "s") == 0) |
rschimpf78 | 2:e8f8095464cf | 327 | { |
rschimpf78 | 2:e8f8095464cf | 328 | pc.scanf(" %d",&plates); |
rschimpf78 | 2:e8f8095464cf | 329 | pc.printf("\nresponse recieved |"); |
rschimpf78 | 3:fd2ca631ab44 | 330 | send_error_check(); |
rschimpf78 | 3:fd2ca631ab44 | 331 | beam(); |
rschimpf78 | 3:fd2ca631ab44 | 332 | platedetect(); |
rschimpf78 | 0:88834eed3de0 | 333 | } |
rschimpf78 | 3:fd2ca631ab44 | 334 | else if (strcmp (command, "r") == 0) |
rschimpf78 | 2:e8f8095464cf | 335 | { |
rschimpf78 | 2:e8f8095464cf | 336 | pc.printf("\nresponse recieved |"); |
rschimpf78 | 3:fd2ca631ab44 | 337 | retract_error_check(); |
rschimpf78 | 2:e8f8095464cf | 338 | } |
rschimpf78 | 3:fd2ca631ab44 | 339 | else if (strcmp (command, "c") == 0) |
rschimpf78 | 3:fd2ca631ab44 | 340 | { |
rschimpf78 | 3:fd2ca631ab44 | 341 | pc.scanf(" %d",&plates); |
rschimpf78 | 2:e8f8095464cf | 342 | pc.printf("\nresponse recieved |"); |
rschimpf78 | 3:fd2ca631ab44 | 343 | select_error_check(); |
rschimpf78 | 0:88834eed3de0 | 344 | } |
rschimpf78 | 3:fd2ca631ab44 | 345 | else if (strcmp (command, "b") == 0) |
rschimpf78 | 3:fd2ca631ab44 | 346 | { |
rschimpf78 | 2:e8f8095464cf | 347 | pc.printf("\nresponse recieved |"); |
rschimpf78 | 3:fd2ca631ab44 | 348 | beam(); |
rschimpf78 | 3:fd2ca631ab44 | 349 | platedetect(); |
rschimpf78 | 0:88834eed3de0 | 350 | } |
rschimpf78 | 2:e8f8095464cf | 351 | else |
rschimpf78 | 2:e8f8095464cf | 352 | { |
rschimpf78 | 3:fd2ca631ab44 | 353 | pc.printf("\nERROR: Invalid Command"); |
rschimpf78 | 2:e8f8095464cf | 354 | } |
rschimpf78 | 0:88834eed3de0 | 355 | } |
rschimpf78 | 2:e8f8095464cf | 356 | } |