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