Update pump_volume_flowrate.py

This commit is contained in:
tpollina 2019-12-10 15:14:36 -08:00 committed by GitHub
parent 580a3f0df2
commit 8e9bd56584
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,43 +1,34 @@
from adafruit_motor import stepper from adafruit_motor import stepper
from adafruit_motorkit import MotorKit from adafruit_motorkit import MotorKit
from time import sleep from time import sleep
from datetime import datetime
import time
kit = MotorKit() kit = MotorKit()
pump = kit.stepper2 pump_stepper = kit.stepper2
pump.release() pump_stepper.release()
def pump(vol, flowrate, dir):
def pump_volume(vol, flowrate): if dir == "foward":
dir=stepper.FORWARD
if dir == "backward":
dir=stepper.BACKWARD
nb_step=vol*507 #if sleep(0.05) in between 2 steps nb_step=vol*507 #if sleep(0.05) in between 2 steps
#35000steps for 69g #35000steps for 69g
#nb_step=vol*460 if sleep(0) in between 2 steps #nb_step=vol*460 if sleep(0) in between 2 steps
duration=(vol*60)/flowrate duration=(vol*60)/flowrate
delay=(duration/nb_step)-0.005
#flowrate is about 2.2ml/min
for i in range(nb_step):
pump.onestep(direction=stepper.FORWARD, style=stepper.DOUBLE)
sleep(delay)
print(delay)
sleep(1)
pump.release()
volume=1 delay=(duration/nb_step)-0.005
flowrate=1 #20 is the max for i in range(nb_step):
pump_stepper.onestep(direction=dir, style=stepper.DOUBLE)
start = time.time() sleep(delay)
pump_volume(volume, flowrate) sleep(1)
pump_stepper.release()
end = time.time()
#volume, flowrate (from 0 to 20), direction (foward or backward)
duration = end-start pump(1, 10, 'foward')
print(duration)