-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcalibrate.py
executable file
·207 lines (182 loc) · 8.14 KB
/
calibrate.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
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
from opentrons import robot, containers, instruments
import opentrons
import curses
import time
from curses import wrapper
from equipment import getEquipment
movementamounts= {1:0.1, 2:0.5, 3:1, 4:5, 5:10,6:20,7:40,8:80}
equipment=getEquipment()
robot.connect(robot.get_serial_ports_list()[0])
if not robot.is_connected():
raise Exception('Did not connect')
input("Robot will now home, press enter to continue.")
robot.home()
placeables = {}
pipettes = {}
for key, value in equipment.items():
if hasattr(value, 'axis'):
pipettes[key]=value
else:
placeables[key]=value
placeableNames=sorted(list(placeables.keys()))
pipetteNames=sorted(list(pipettes.keys()))
def main(stdscr):
currentlyCalibrating=placeableNames[0]
currentPipette=pipetteNames[0]
movementAmount=1
position=list(robot._driver.get_head_position()["current"])
position[0]=0
def chooseWhatToCalibrate():
nonlocal currentlyCalibrating
stdscr.clear()
stdscr.addstr("What should we calibrate?\n")
for i,value in enumerate(placeableNames):
stdscr.addstr(str(i+1)+" - " + value+"\n")
curses.echo() # Enable echoing of characters
s = stdscr.getstr(15,0, 15)
stdscr.addstr(s)
currentlyCalibrating=placeableNames[int(s)-1]
curses.noecho()
def chooseWhatPipetteToCalibrate():
nonlocal currentPipette
stdscr.clear()
stdscr.addstr("What pipette should we calibrate?\n")
for i,value in enumerate(pipetteNames):
stdscr.addstr(str(i+1)+" - " + value+"\n")
curses.echo() # Enable echoing of characters
s = stdscr.getstr(10,0, 15)
stdscr.addstr(s)
currentPipette=pipetteNames[int(s)-1]
curses.noecho()
# This raises ZeroDivisionError when i == 10.
def calibratePlunger():
plungerPos=0
plungerTarget="top"
plungerInc=1
while 1:
stdscr.clear()
stdscr.addstr("PLASMOTRON CALIBRATION MODE - PLUNGER MODE\n\n")
stdscr.addstr("Keyboard shortcuts:\n\n")
stdscr.addstr("T - start calibrating the 'top' position\n")
stdscr.addstr("B - start calibrating the 'bottom' position\n")
stdscr.addstr("O - start calibrating the 'blowout' position\n")
stdscr.addstr("E - start calibrating the 'eject' position\n\n")
stdscr.addstr("Numbers 1-8 - choose how far to move\n")
stdscr.addstr("Arrow keys - move plunger up/down\n")
stdscr.addstr("S - save this position\n")
stdscr.addstr("M - move to this position\n")
stdscr.addstr("\n\n")
stdscr.addstr("V - switch back to container mode\n\n")
stdscr.addstr("Currently calibrating plunger position: ")
stdscr.addstr( str(plungerTarget)+"\n",curses.A_STANDOUT)
stdscr.addstr("with pipette: ")
stdscr.addstr(str(currentPipette)+"\n",curses.A_STANDOUT)
stdscr.addstr("Movement increment: ")
stdscr.addstr(str(plungerInc)+" mm\n",curses.A_STANDOUT)
stdscr.addstr("Current position - X: ")
stdscr.addstr(str(plungerPos),curses.A_STANDOUT)
key=stdscr.getkey()
curses.flushinp()
if key=="t":
plungerTarget="top"
if key=="b":
plungerTarget="bottom"
if key=="o":
plungerTarget="blow_out"
if key=="e":
plungerTarget="drop_tip"
if key=="s":
equipment[currentPipette].calibrate(plungerTarget)
stdscr.clear()
stdscr.addstr("plunger position saved")
stdscr.refresh()
time.sleep(1)
if key=="m":
equipment[currentPipette].motor.move(equipment[currentPipette]._get_plunger_position(plungerTarget))
plungerPos=equipment[currentPipette]._get_plunger_position(plungerTarget)
if key=="h":
equipment[currentPipette].home()
plungerPos=0
if key=="v":
return()
try:
if int(key) in movementamounts:
plungerInc= movementamounts[int(key)]
except ValueError:
pass
if key == "KEY_UP":
plungerPos=plungerPos-plungerInc
if key == "KEY_DOWN":
plungerPos=plungerPos+plungerInc
#stdscr.addstr("Key"+key)
equipment[currentPipette].motor.move(plungerPos)
stdscr.refresh()
while 1:
stdscr.clear()
stdscr.addstr("PLASMOTRON CALIBRATION MODE\n\n")
stdscr.addstr("Keyboard shortcuts:\n")
stdscr.addstr("Control+C - exit\n")
stdscr.addstr("P - choose what pipette to calibrate with\n")
stdscr.addstr("C - choose what container to calibrate\n")
stdscr.addstr("S - save this position\n")
stdscr.addstr("H - home\n")
stdscr.addstr("M - move to the currently saved position\n\n")
stdscr.addstr("Numbers 1-8 - choose how far to move\n")
stdscr.addstr("Arrow keys - move forwards/back/left/right\n")
stdscr.addstr("Control + arrow keys - move up/down\n\n")
stdscr.addstr("V - switch to calibrate this pipettes plunger/volume\n\n")
stdscr.addstr("Currently pipette: ")
stdscr.addstr(str(currentPipette)+"\n",curses.A_STANDOUT)
stdscr.addstr("going to: ")
stdscr.addstr(str(currentlyCalibrating)+"\n",curses.A_STANDOUT)
stdscr.addstr("Movement increment: ")
stdscr.addstr( str(movementAmount)+" mm\n",curses.A_STANDOUT)
stdscr.addstr("Current position - ")
stdscr.addstr("X:"+ str(position[0])+",Y:"+ str(position[1])+",Z:"+ str(position[2]),curses.A_STANDOUT)
key=stdscr.getkey()
curses.flushinp()
if key=="c":
chooseWhatToCalibrate()
if key=="v":
calibratePlunger()
if key=="p":
chooseWhatPipetteToCalibrate()
if key=="s":
well = equipment[currentlyCalibrating][0]
pos = well.from_center(x=0, y=0, z=-1, reference=equipment[currentlyCalibrating])
location = (equipment[currentlyCalibrating], pos)
equipment[currentPipette].calibrate_position(location)
stdscr.clear()
stdscr.addstr("position saved")
stdscr.refresh()
time.sleep(1)
if key=="m":
well = equipment[currentlyCalibrating][0]
pos = well.from_center(x=0, y=0, z=-1, reference=equipment[currentlyCalibrating])
location = (equipment[currentlyCalibrating], pos)
equipment[currentPipette].move_to(location)
position=list(robot._driver.get_head_position()["current"])
if key=="h":
robot.home()
position=list(robot._driver.get_head_position()["current"])
try:
if int(key) in movementamounts:
movementAmount= movementamounts[int(key)]
except ValueError:
pass
if key == "kUP5":
position[2]=position[2]+movementAmount
if key == "kDN5":
position[2]=position[2]-movementAmount
if key == "KEY_LEFT":
position[0]=position[0]-movementAmount
if key == "KEY_RIGHT":
position[0]=position[0]+movementAmount
if key == "KEY_UP":
position[1]=position[1]+movementAmount
if key == "KEY_DOWN":
position[1]=position[1]-movementAmount
#stdscr.addstr("Key"+key)
robot.move_head(x=position[0],y=position[1],z=position[2])
stdscr.refresh()
wrapper(main)