Add files via upload

This commit is contained in:
tpollina 2019-12-10 21:51:01 -08:00 committed by GitHub
parent a8062b75d1
commit a8ca22f392
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 192 additions and 16 deletions

8
pipeline/focus.php Normal file
View file

@ -0,0 +1,8 @@
<?php
$nb_step = $_REQUEST["nb_step"];
$orientation = $_REQUEST["orientation"];
$toggler = $_REQUEST["toggler"];
$output = shell_exec('/usr/bin/python3 focus.py '.$nb_step.' '.$orientation.' '.$toggler);
?>

54
pipeline/focus.py Normal file
View file

@ -0,0 +1,54 @@
#!/usr/bin/env python
from adafruit_motor import stepper
from adafruit_motorkit import MotorKit
from time import sleep
from thread2 import Thread
import sys
nb_step = int(sys.argv[1])
orientation = str(sys.argv[2])
toogler = str(sys.argv[3])
#Execute a python cmd with the previous defined variables from php
kit = MotorKit()
stage = kit.stepper1
stage.release()
def focus(steps,orientation):
#0.25mm/step
#31um/microsteps
stage.release()
if orientation == 'up':
for i in range(steps):
stage.onestep(direction=stepper.FORWARD, style=stepper.MICROSTEP)
sleep(0.001)
if orientation == 'down':
for i in range(steps):
stage.onestep(direction=stepper.BACKWARD, style=stepper.MICROSTEP)
sleep(0.001)
stage.release()
focus_thread = Thread(target = focus, name = 'focus_thread', args =(nb_step, orientation) )
if toogler == "ON":
focus_thread.start()
focus_thread.isAlive()
if toogler == "OFF":
focus_thread.terminate()
focus_thread.join()
focus_thread.isAlive()
stage.release()

View file

@ -14,13 +14,23 @@
</head>
<body>
nb_step
<input type="text" id="nb_step"/>
orientation
<input type="text" id="orientation"/>
<button type="button" class="btn btn-primary" id="send_nb_step">Send</button>
<div>
nb_step
<input type="text" id="nb_step" value="1000"/>
orientation
<input type="text" id="orientation" value="up"/>
<button type="button" class="btn btn-primary" id="focus">Send</button>
</div>
volume(ml)
<input type="text" id="volume" value="1"/>
flowrate (ml/min) (from 0 to 20)
<input type="text" id="flowrate" value="3"/>
direction (foward or backward)
<input type="text" id="direction" value="foward"/>
<button type="button" class="btn btn-primary" id="pump">Send</button>
<div>
</div>
</body>
</html>

View file

@ -1,21 +1,31 @@
$(document).ready(function(){
$( "#send_nb_step" ).click(function() {
pipeline()
$( "#focus" ).click(function() {
focus("ON")
});
$( "#pump" ).click(function() {
pump()
});
function pipeline() {
var value = $("#nb_step").val();
var orientation = $("#orientation").val();
console.log("pipeline.php?nb_step="+value+"&orientation="+orientation);
function focus(toggler) {
var value = $("#nb_step").val();
var orientation = $("#orientation").val();
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "pipeline.php?nb_step="+value+"&orientation="+orientation, true);
xmlhttp.open("GET", "focus.php?nb_step="+value+"&orientation="+orientation+"&toggler="+toggler, true);
xmlhttp.send();
}
function pump() {
var volume = $("#volume").val();
var flowrate = $("#flowrate").val();
var direction = $("#direction").val();
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "pump.php?volume="+volume+"&flowrate="+flowrate+"&direction="+direction, true);
xmlhttp.send();
}
});

8
pipeline/pump.php Normal file
View file

@ -0,0 +1,8 @@
<?php
$volume = $_REQUEST["volume"];
$flowrate = $_REQUEST["flowrate"];
$direction = $_REQUEST["direction"];
$output = shell_exec('/usr/bin/python3 pump.py '.$volume.' '.$flowrate.' '.$direction);
?>

41
pipeline/pump.py Normal file
View file

@ -0,0 +1,41 @@
from adafruit_motor import stepper
from adafruit_motorkit import MotorKit
from time import sleep
import sys
vol = int(sys.argv[1])
flowrate = int(sys.argv[2])
dir = str(sys.argv[3])
kit = MotorKit()
pump_stepper = kit.stepper2
pump_stepper.release()
def pump(vol, flowrate, dir):
if dir == "foward":
dir=stepper.FORWARD
if dir == "backward":
dir=stepper.BACKWARD
nb_step=vol*507 #if sleep(0.05) in between 2 steps
#35000steps for 69g
#nb_step=vol*460 if sleep(0) in between 2 steps
duration=(vol*60)/flowrate
delay=(duration/nb_step)-0.005
for i in range(nb_step):
pump_stepper.onestep(direction=dir, style=stepper.DOUBLE)
sleep(delay)
sleep(1)
pump_stepper.release()
#volume, flowrate (from 0 to 20), direction (foward or backward)
pump(vol, flowrate, dir)

45
pipeline/thread2.py Normal file
View file

@ -0,0 +1,45 @@
import threading
import inspect
import ctypes
def _async_raise(tid, exctype):
"""raises the exception, performs cleanup if needed"""
if not inspect.isclass(exctype):
raise TypeError("Only types can be raised (not instances)")
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
if res == 0:
raise ValueError("invalid thread id")
elif res != 1:
# """if it returns a number greater than one, you're in trouble,
# and you should call it again with exc=NULL to revert the effect"""
ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0)
raise SystemError("PyThreadState_SetAsyncExc failed")
class Thread(threading.Thread):
def _get_my_tid(self):
"""determines this (self's) thread id"""
if not self.isAlive():
raise threading.ThreadError("the thread is not active")
# do we have it cached?
if hasattr(self, "_thread_id"):
return self._thread_id
# no, look for it in the _active dict
for tid, tobj in threading._active.items():
if tobj is self:
self._thread_id = tid
return tid
raise AssertionError("could not determine the thread's id")
def raise_exc(self, exctype):
"""raises the given exception type in the context of this thread"""
_async_raise(self._get_my_tid(), exctype)
def terminate(self):
"""raises SystemExit in the context of the given thread, which should
cause the thread to exit silently (unless caught)"""
self.raise_exc(SystemExit)