-
Notifications
You must be signed in to change notification settings - Fork 3
/
droplet_gui.py
143 lines (118 loc) · 3.89 KB
/
droplet_gui.py
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
'''
Puts droplets on a grid on the coverslip
'''
from Tkinter import *
from time import sleep
from numpy import pi, sin, cos
from serial import SerialException
from AutomaticPatch.Pressure_controller.pump_devices.OB1 import *
from devices import *
class ManipulatorApplication(Frame):
'''
The main application.
'''
def __init__(self, master, stage, unit):
'''
Parameters
----------
master : parent window
stage : the stage/microscope unit
units : a list of XYZ virtual units (manipulators)
names : names of the units
'''
Frame.__init__(self, master)
self.stage = stage
self.unit = unit
# angle of the manipulator
self.angle = 35./180*pi
self.pump = OB1()
Button(self, text="Reference", command=self.reference).pack()
Button(self, text="Go", command=self.go).pack()
Button(self, text="Droplet", command=self.droplet).pack()
self.pump.set_pressure(30)
def droplet(self):
self.pump.set_pressure(100)
sleep(.05)
self.pump.set_pressure(30)
def reference(self):
'''
Sets the reference point
'''
self.refx = self.unit.position(0)
self.refz = self.unit.position(2)
def go(self):
'''
Assumes the pipette is in place on the coverslip
'''
# Go up, move stage, go down
x = self.unit.position(0)
z = self.unit.position(2)
# We calculate dx and dz for a 1 mm move on the coverslip
'''
dx = x-self.refx
dz = z-self.refz
'''
dx = -1000/cos(self.angle)
dz = dx*sin(self.angle)
self.unit.set_single_step_distance(0, dx/8)
self.unit.set_single_step_distance(1, 250)
self.unit.set_single_step_distance(2, dz/8)
#self.unit.absolute_move(z-1000,axis = 2) # I should put a flag until_still = True
sign = 1
for j in range(4):
for i in range(4):
if sign == 1:
self.unit.single_step(2, 8)
self.unit.wait_motor_stop(2)
self.droplet()
self.unit.single_step(0, 8)
#self.stage.absolute_move(x+2000, axis = 0)
self.unit.wait_motor_stop(0)
else:
self.unit.single_step(0, -8)
self.unit.wait_motor_stop(0)
self.droplet()
self.unit.single_step(2, -8)
sleep(1)
self.unit.wait_motor_stop(2)
sign=-sign
self.unit.single_step(2, 8)
self.unit.wait_motor_stop(2)
self.droplet()
self.unit.single_step(1, 4)
self.unit.wait_motor_stop(1)
self.unit.single_step(2, -8)
self.unit.wait_motor_stop(2)
sleep(1)
self.unit.single_step(2, 8)
sleep(3)
print "done"
self.pump.set_pressure(0)
if __name__ == '__main__':
root = Tk()
root.title('Droplet generator')
SM5 = False
try:
if SM5:
dev = LuigsNeumann_SM5('COM3')
else:
dev = LuigsNeumann_SM10()
except SerialException:
print "L&N not found. Falling back on fake device."
dev = FakeDevice()
if SM5:
microscope_Z = Leica('COM1')
microscope = XYMicUnit(dev, microscope_Z, [7, 8])
unit = XYZUnit(dev, [4, 5, 6])
else:
microscope = XYZUnit(dev, [7, 8, 9])
unit = XYZUnit(dev, [1, 2, 3])
dev.set_single_step_velocity(2, 15)
dev.set_single_step_velocity(3, 15)
dev.set_single_step_velocity(1, 15)
print "Device initialized"
app = ManipulatorApplication(root, microscope, unit).pack(side="top", fill="both", expand=True)
try:
root.mainloop()
except SerialException:
del(dev)