-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBenchtop.cpp
More file actions
494 lines (413 loc) · 12.3 KB
/
Copy pathBenchtop.cpp
File metadata and controls
494 lines (413 loc) · 12.3 KB
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
#include "Arduino.h"
#include "Benchtop.h"
/********** PUBLIC FUNCTIONS **********/
/*
* Constructor for pump object. Then initializes the pins and initial pin states
*
* @param step_mtr_drv stepper motor driver/actuator/control pin
* @param step_mtr_dir stepper motor direction pin
* @param valve_input_drv input valve driver/control pin (valve1)
* @param valve_output_drv output valve driver/control pin (valve2)
*/
Benchtop::Benchtop() {
syringe_rinse_speed = 3000.0;
rinse_volume = 750.0;
rinse_time = 5.0*1000;
acid_volume = 20.0;
acid_wait_time = 40.0*1000;
sample_volume = 750.0;
syringe_sample_speed= 500.0;
sample_wait_time = 10.0*1000;
//integration_time = 145.0*1000;
integration_time = 30.0*1000;
// syringe_rinse_speed= 10.0;
// rinse_volume= 10.0;
// rinse_time= 10.0*1000;
// acid_volume= 10.0;
// acid_wait_time= 10.0*1000;
// sample_volume= 10.0;
// syringe_sample_speed= 10.0;
// sample_wait_time= 10.0*1000;
// integration_time= 10.0*1000;
}
/*
* Sets the syringe rinse speed
*
* @param syringe_rinse_speed to set
*/
void Benchtop::set_syringe_rinse_speed(float syringe_rinse_speed) {
this->syringe_rinse_speed=syringe_rinse_speed;
}
/*
* Gets the syringe rinse speed
*/
float Benchtop::get_syringe_rinse_speed() {
return this->syringe_rinse_speed;
}
/*
* Sets the rinse volume
*
* @param rinse_volume to set
*/
void Benchtop::set_rinse_volume(float rinse_volume) {
this->rinse_volume=rinse_volume;
}
/*
* Gets the rinse volume
*/
float Benchtop::get_rinse_volume() {
return this->rinse_volume;
}
/*
* Sets the rinse time
*
* @param rinse_time to set
*/
void Benchtop::set_rinse_time(float rinse_time) {
this->rinse_time=rinse_time;
}
/*
* Gets the rinse time
*/
float Benchtop::get_rinse_time() {
return this->rinse_time;
}
/*
* Sets the acid volume
*
* @param acid_volume to set
*/
void Benchtop::set_acid_volume(float acid_volume) {
this->acid_volume=acid_volume;
}
/*
* Gets the acid volume
*/
float Benchtop::get_acid_volume() {
return this->acid_volume;
}
/*
* Sets the acid wait time
*
* @param acid_wait_time to set
*/
void Benchtop::set_acid_wait_time(float acid_wait_time) {
this->acid_wait_time=acid_wait_time;
}
/*
* Gets the acid wait time
*/
float Benchtop::get_acid_wait_time() {
return this->acid_wait_time;
}
/*
* Sets the sample volume
*
* @param sample_volume to set
*/
void Benchtop::set_sample_volume(float sample_volume) {
this->sample_volume=sample_volume;
}
/*
* Gets the sample volume
*/
float Benchtop::get_sample_volume() {
return this->sample_volume;
}
/*
* Sets the syringe sample speed
*
* @param syringe_sample_speed to set
*/
void Benchtop::set_syringe_sample_speed(float syringe_sample_speed) {
this->syringe_sample_speed=syringe_sample_speed;
}
/*
* Gets the syringe sample speed
*/
float Benchtop::get_syringe_sample_speed() {
return this->syringe_sample_speed;
}
/*
* Sets the sample wait time
*
* @param sample_wait_time to set
*/
void Benchtop::set_sample_wait_time(float sample_wait_time) {
this->sample_wait_time=sample_wait_time;
}
/*
* Gets the sample wait time
*/
float Benchtop::get_sample_wait_time() {
return this->sample_wait_time;
}
/*
* Sets the total sample integration time
*
* @param total_sample_integration_time to set
*/
void Benchtop::set_integration_time(float integration_time) {
this->integration_time=integration_time;
}
/*
* Gets the total sample integration time
*/
float Benchtop::get_integration_time() {
return this->integration_time;
}
/********** PUBLIC FUNCTIONS **********/
void Benchtop::flush(Pump & syringe) {
syringe.set_valve_dirs(LOW,LOW); // Open both input valve and output valve
syringe.pump(500,11,OUT); //Drain the pump and plumbing
}
/*
* Rinse state
*/
void Benchtop::rinse(Pinch & strip,Pump & syringe) {
if (debug) Serial.println("\rControl syringe open to SAMPLE");
control_syringe(syringe,OPEN,CLOSE);
//strip_chamber(strip,OPEN,CLOSE);
if (debug) Serial.println("\rStrip chamber open to WASTE");
strip.open();
if (debug) Serial.println("\rFilling control syringe with rinse");
fill_rinse(syringe);
// Rinse into stripping chamber
// control_syringe(strip,CLOSE,OPEN);
if (debug) Serial.println("\rStrip chamber open to SAMPLE");
strip.close();
//strip_chamber(syringe,CLOSE,OPEN);
if (debug) Serial.println("\rFilling strip chamber with sample");
rinse_stripping_chamber(syringe);
if (debug) Serial.println("\rWaiting for rinse time to elapse");
delay(this->rinse_time);
// TODO: Empty rinse
//strip_chamber(strip,OPEN,CLOSE);
if (debug) Serial.println("\rStrip chamber open to WASTE");
strip.open();
}
/*
* Waste ***** probably wants IO arguments
*/
void Benchtop::control_syringe(Pump & pump,bool waste,bool sample) {
pump.set_valve_dirs(waste,sample);
}
/*
* Sample ***** probably wants IO arguments
*/
void Benchtop::strip_chamber(Pump & pump,bool sample,bool strip) {
pump.set_valve_dirs(sample,strip);
}
/*
* Fill Rinse w/ Syringe Pump?
*/
void Benchtop::fill_rinse(Pump & pump) {
if (debug) Serial.println("\r\t\tPumping In");
pump.pump(vol_2_steps(rinse_volume),BASE_DELAY,IN);
}
/*
* Rinse into Stripping Chamber
*/
void Benchtop::rinse_stripping_chamber(Pump & pump) {
if (debug) Serial.println("\r\t\tPumping Out");
pump.pump(vol_2_steps(rinse_volume),BASE_DELAY,OUT);
}
/*
* Empty Rinse
*/
void Benchtop::empty_rinse() {
}
/*
* Start analysis
*/
void Benchtop::analysis(Pinch & strip,Pump & syringe,K30 & k30,Pinch & acid_pump, File & myFile) {
unsigned int start_time=millis();
int check_time=start_time;
int last_time=start_time;
unsigned int _2seconds=2000;
unsigned int acid_start_time=0;
unsigned int integration_start_time=0;
unsigned int sample_wait_start_time=0;
int reading;
if (debug) Serial.println("Initial detection");
if (debug) Serial.print("\tDETECTING...");
reading = detect_co2(k30);
result_vec.push_back(reading);
if (debug) Serial.println(reading);
if (debug) Serial.println("End of detection");
// strip_chamber(strip,CLOSE,OPEN);
if (debug) Serial.println("Strip chamber open to SAMPLE");
strip.close();
// TODO: actuate acid pump; push acid_volume into stripping chamber; has delay
if (debug) Serial.println("Pumping acid into strip chamber");
// digitalWrite(acid_pump, HIGH);
acid_pump.open();
delay(2000);
// digitalWrite(acid_pump, LOW);
acid_pump.close();
// END ACID PUMP - ASK ABOUT THIS
if (debug) Serial.println("Waiting to detect");
check_time=millis()-start_time;
while(check_time < _2seconds)
;
if (debug) Serial.print("\tDETECTING...");
reading = detect_co2(k30);
result_vec.push_back(reading);
if (debug) Serial.println(reading);
acid_start_time=millis();
if (debug) Serial.println("Filling control syringe with sample");
fill_sample(syringe);
if (debug) Serial.println("Waiting to detect");
last_time=millis()-check_time;
while(last_time < _2seconds)
;
if (debug) Serial.print("\tDETECTING...");
reading = detect_co2(k30);
result_vec.push_back(reading);
if (debug) Serial.println(reading);
check_time=last_time;
if (debug) Serial.println("Waiting for acid_wait_time to elapse");
while(millis()-acid_start_time < acid_wait_time) {
// Making sure we waiting the entired acid wait time
// while(last_time=millis()-check_time < _2seconds) // Might be too long, might not matter tho
// ;
//
// if (debug) {
// Serial.print("millis(): ");
// Serial.println(millis());
// Serial.print("last_time: ");
// Serial.println(last_time);
// Serial.print("check_time: ");
// Serial.println(check_time);
// Serial.print("_2seconds: ");
// Serial.println(_2seconds);
// Serial.print("over 2 seconds?: ");
// Serial.println(last_time > _2seconds);
// }
last_time=millis()-check_time;
if(last_time > _2seconds) {
if (debug) Serial.print("\tDETECTING...");
reading = detect_co2(k30);
result_vec.push_back(reading);
if (debug) Serial.println(reading);
check_time=millis();
}
// result_vec.push_back(detect_co2(k30));
}
if (debug) Serial.println("CONTROL SYRINGE Pushing into stripping chamber");
control_syringe(syringe,CLOSE,OPEN);
// sample_stripping_chamber(syringe);
integration_start_time=check_time=millis();
if (debug) Serial.println("Pumping sample into stripping chamber");
for(int i=0;i<spd_2_delay(syringe_sample_speed);i++) { //???????????? pump full volume at normal speed
//if (debug) Serial.println("\tSPHECIAL PUMPIN IT...");
syringe.special_pump(spd_2_delay(syringe_sample_speed),OUT);
last_time=millis()-check_time;
if(last_time > _2seconds) {
if (debug) Serial.print("\tDETECTING...");
reading = detect_co2(k30);
result_vec.push_back(reading);
if (debug) Serial.println(reading);
check_time=millis();
}
}
if (debug) Serial.println("Waiting for integration time to elapse");
int temp = millis() - integration_start_time;
while(temp < integration_time) {// Might be too long, might not matter tho
last_time=millis()-check_time;
if(last_time > _2seconds) {
if (debug) Serial.print("\tDETECTING...");
reading = detect_co2(k30);
result_vec.push_back(reading);
if (debug) Serial.println(reading);
check_time=millis();
}
temp = millis() - integration_start_time;
}
//
// if (debug) Serial.println("Waiting for FINAL detection");
// while(last_time=millis()-check_time < _2seconds)
// ;
// if (debug) Serial.println("DETECTING...");
// result_vec.push_back(detect_co2(k30));
sample_wait_start_time=check_time=millis();
if (debug) Serial.println("Waiting for sample_wait_time to elapse");
temp = millis() - sample_wait_start_time;
while(temp < sample_wait_time) {
last_time=millis()-check_time;
if(last_time > _2seconds) {
if (debug) Serial.print("\tDETECTING...");
reading = detect_co2(k30);
result_vec.push_back(reading);
if (debug) Serial.println(reading);
check_time=millis();
}
temp = millis() - sample_wait_start_time;
}
// strip_chamber(strip,OPEN,CLOSE);
Serial.println("Strip chamber open to WASTE");
strip.open();
// write results to file
Serial.println("Write to file");
write_out(myFile);
delay(2000);
}
/*
* Record peak from CO2 Detector (K30)
*/
int Benchtop::detect_co2(K30 & k30) { // TODO: MAKE THIS SMALLER?
k30.sendRequest();
return k30.getValue();
}
/*
* Add acid to stripping chamber
*/
void Benchtop::add_acid_stripping_chamber() {
}
/*
* Record Sample Temperature
*/
void Benchtop::record_sample_temp() {
}
/*
* Fill Sample w/ Syringe Pump? Might want to make one function with one above and and use input argument
*/
void Benchtop::fill_sample(Pump & pump) {
if (debug) Serial.println("\t\tPumping IN");
pump.pump(vol_2_steps(sample_volume),BASE_DELAY,IN);
}
/*
* Start peak integration for user defined length of time
*/
void Benchtop::start_peak_integration() {
}
/*
* Sample stripping chamber during analysis
*/
void Benchtop::sample_stripping_chamber(Pump & pump) {
pump.pump(vol_2_steps(sample_volume),spd_2_delay(syringe_sample_speed),OUT);
}
/*
* Empty stripping chamber
*/
void Benchtop::empty_stripping_chamber() {
}
int Benchtop::vol_2_steps(float volume) { // TODO: CALCULATE THIS SHIT
// return volume;
// return 500;
// Transforming user inputs into usable variables for srynge pump
return round(volume/1.5); // volume should almost always be 750, round is to prevent user error
}
int Benchtop::spd_2_delay(float rate) { // TODO: CALCULATE THIS SHIT
// return spd;
// return 500;
// Transforming user inputs into usable variables for srynge pump
return round((1/(rate/(1.5*60*1000)))-9); // this converts the microL/min into a delay used to control speed of pump
// again, the round is to prevent user error. std input of 500 or 3000 will not utilize round function
}
void Benchtop::write_out(File & myFile) {
for (int i = 0; i < result_vec.size(); i++) {
Serial.println(result_vec[i]);
myFile.println(result_vec[i]);
}
}