planktoscope/scripts/pump.py

47 lines
1.1 KiB
Python
Raw Normal View History

2019-12-13 19:39:50 +01:00
#!/usr/bin/env python
2019-12-13 21:30:03 +01:00
#Strating pumping foward a vol of 24ml with a flowrate of 3.2ml/min, use this command line :
#python3.7 path/to/file/pump.py 24 3.2 foward
2019-12-13 19:39:50 +01:00
from adafruit_motor import stepper
from adafruit_motorkit import MotorKit
from time import sleep
import sys
2019-12-13 23:11:55 +01:00
volume = int(sys.argv[1])
2019-12-13 19:39:50 +01:00
flowrate = float(sys.argv[2])
2019-12-13 23:11:55 +01:00
action = str(sys.argv[3])
2019-12-13 19:39:50 +01:00
kit = MotorKit()
2019-12-13 23:40:20 +01:00
pump_stepper = kit.stepper1
2019-12-13 19:39:50 +01:00
pump_stepper.release()
2019-12-13 23:11:55 +01:00
def pump(volume, flowrate, action):
2019-12-13 19:39:50 +01:00
2019-12-13 23:11:55 +01:00
if action == "foward":
action=stepper.BACKWARD
2019-12-15 05:40:50 +01:00
if action == "backward":
action=stepper.FORWARD
2019-12-13 19:39:50 +01:00
2019-12-13 23:11:55 +01:00
nb_step=volume*507 #if sleep(0.05) in between 2 steps
2019-12-13 19:39:50 +01:00
#35000steps for 69g
#nb_step=vol*460 if sleep(0) in between 2 steps
2019-12-13 23:11:55 +01:00
duration=(volume*60)/flowrate
2019-12-13 19:39:50 +01:00
delay=(duration/nb_step)-0.005
for i in range(nb_step):
2019-12-13 23:11:55 +01:00
pump_stepper.onestep(direction=action, style=stepper.DOUBLE)
2019-12-13 19:39:50 +01:00
sleep(delay)
sleep(1)
pump_stepper.release()
#volume, flowrate (from 0 to 20), direction (foward or backward)
2019-12-13 23:11:55 +01:00
pump(volume, flowrate, action)