-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathliquid_handling_methods.py
More file actions
331 lines (269 loc) · 10.7 KB
/
Copy pathliquid_handling_methods.py
File metadata and controls
331 lines (269 loc) · 10.7 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import os
import sys
sys.path.append('pyuf/')
from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *
from time import sleep
# TODO: reduce code duplication
def robot_move(swift: SwiftAPI, position: dict):
dict_args = position
dict_args['wait'] = True
swift.set_position(**dict_args)
def robot_move_relative(swift: SwiftAPI, position: dict):
dict_args = position
dict_args['wait'] = True
dict_args['relative'] = True
swift.set_position(**dict_args)
dict_args['relative'] = False
def pick_pipette(swift: SwiftAPI, position: dict):
# Hovering above pipette
dict_args = position
dict_args['wait'] = True
dict_args['change_z_by'] = 50
swift.set_position(**dict_args)
# Acquiring pipette
dict_args['wait'] = True
dict_args['change_z_by'] = 0
swift.set_position(**dict_args)
sleep(1)
# Hovering above pipette
dict_args['wait'] = True
dict_args['change_z_by'] = 90
swift.set_position(**dict_args)
dict_args['change_z_by'] = 0
def drop_pipette(swift: SwiftAPI, position: dict):
# Hovering above trash
dict_args = position
dict_args['change_z_by'] = 70
dict_args['wait'] = True
swift.set_position(**dict_args)
# back to normal location (relevant in case of using variables)
dict_args['change_z_by'] = 0
swift.set_position(**dict_args)
current_position = swift.get_position()
robot_move(swift=swift, position=
{'x': current_position[0], 'y': current_position[1], 'z': position['z'], 'e': None, 'speed': None})
dict_args = position
dict_args['wait'] = True
swift.set_position(**dict_args)
swift.set_wrist(270)
sleep(1)
swift.set_wrist(90)
# Hovering above trash
dict_args = position
dict_args['change_z_by'] = 70
dict_args['wait'] = True
swift.set_position(**dict_args)
dict_args['change_z_by'] = 0 # back to normal location(relevant in case of using variables)
def load_material(swift: SwiftAPI, position: dict, amount: int):
amount *= -1
dict_args = position
dict_args['change_z_by'] = 70
dict_args['wait'] = True
swift.set_position(**dict_args)
# back to normal location (relevant in case of using variables)
dict_args['change_z_by'] = 0
swift.set_position(**dict_args)
# loading material
dict_args = ({'e': amount})
dict_args['wait'] = True
dict_args['relative'] = True
swift.set_position(**dict_args)
dict_args['relative'] = False # default is not relative
# Hovering above
dict_args = position
dict_args['change_z_by'] = 70
dict_args['wait'] = True
swift.set_position(**dict_args)
dict_args['change_z_by'] = 0 # back to normal location(relevant in case of using variables)
def eject_material(swift: SwiftAPI, position: dict, amount: int):
# Hovering above
dict_args = position
dict_args['change_z_by'] = 70
dict_args['wait'] = True
swift.set_position(**dict_args)
# moving to ejecting location
dict_args = position
dict_args['change_z_by'] = 0
dict_args['wait'] = True
swift.set_position(**dict_args)
# ejecting material
dict_args = ({'e': amount})
dict_args['wait'] = True
dict_args['relative'] = True
swift.set_position(**dict_args)
dict_args['relative'] = False # default is not relative
# Hovering above
dict_args = position
dict_args['change_z_by'] = 70
dict_args['wait'] = True
swift.set_position(**dict_args)
dict_args['change_z_by'] = 0 # back to normal location(relevant in case of using variables)
def mix_material(swift: SwiftAPI, position: dict, amount: int, iterations: int, ejecting_delta: int, position_for_delta_injection: dict):
# Hovering above
dict_args = position
dict_args['change_z_by'] = 70
dict_args['wait'] = True
swift.set_position(**dict_args)
# back to normal location (relevant in case of using variables)
dict_args['change_z_by'] = 0
swift.set_position(**dict_args)
for i in range(iterations):
sleep(1)
# loading material
dict_args = {'e': amount * (-1)}
dict_args['wait'] = True
dict_args['relative'] = True
swift.set_position(**dict_args)
# ejecting material
dict_args = {'e': amount + ejecting_delta}
dict_args['wait'] = True
dict_args['relative'] = True
swift.set_position(**dict_args)
dict_args['relative'] = False # default is not relative
# Hovering above
dict_args = position
dict_args['change_z_by'] = 70
dict_args['wait'] = True
swift.set_position(**dict_args)
dict_args['change_z_by'] = 0 # back to normal location(relevant in case of using variables)
# delta injection
load_material(swift=swift, amount=iterations*ejecting_delta,
position=position_for_delta_injection)
def robot_wrist(swift: SwiftAPI, angle: float):
swift.set_wrist(angle=angle)
sleep(1)
def robot_sleep(duration: float):
sleep(duration)
def set_speed(swift: SwiftAPI, speed: float):
swift.set_speed(speed=speed)
def shaker_module(swift: SwiftAPI, speed: int, duration: int):
swift.shaker_module_init(time=duration, speed=speed)
# TODO: check and unite with mini function (most of it is copy paste)
def print_pattern(swift: SwiftAPI, pattern_format: str, pipette_position: dict, starting_position: dict,
liquid_position: dict,
disposal_position: dict):
# Reading the coords file into a list
print(f'retrieveing coords from {pattern_format}')
coords = []
with open(os.path.join('uploads\coords', pattern_format), 'r') as f:
for line in f:
x, y = line.strip().split("\,")
coords.append((float(x), float(y)))
# Initializing required variables
current_liquid = 0
release_step = -0.070
total_liquid = release_step * (len(coords) + 100) * 1.75
step_proportional = 2
protection_sip = -1.5
# Resetting arm position to home
swift.set_wrist(90)
swift.set_position(120, 0, 50, speed=15000, wait=True)
# Initializing required positions
pip_args = pipette_position
pip_args['wait'] = True
start_args = starting_position
start_args['wait'] = True
starting_x = start_args['x']
starting_y = start_args['y']
printing_z = start_args['z']
liquid_args = liquid_position
liquid_args['wait'] = True
disposal_args = disposal_position
disposal_args['wait'] = True
# Moving to pipette pick up location, while preserving arm's height
temp_z = pip_args['z']
pip_args['z'] = 60
swift.set_position(**pip_args)
pip_args['z'] = temp_z
swift.set_position(**pip_args)
sleep(1)
swift.set_position(z=105, speed=1500, timeout=30, wait=True)
# Moving to liquid location, while preserving arm's height
temp_z = liquid_args['z']
liquid_args['z'] = 105
swift.set_position(**liquid_args)
liquid_args['z'] = temp_z
swift.set_position(**liquid_args)
# Extrude the liquid according to the amount of coords
swift.set_position(e=total_liquid, speed=1500, timeout=30, wait=True)
current_liquid = total_liquid
swift.set_position(z=90, speed=30000, timeout=30, wait=True)
# Moves to printing starting point
swift.set_position(x=(step_proportional * coords[0][0]) + starting_x,
y=(step_proportional * coords[0][1]) + starting_y, z=60, speed=30000, timeout=30, wait=True)
# Printing image's coords
picture = coords
total_len = len(picture)
current_step = 0
for x, y in picture:
current_step += 1
print("{c_step}/{total}".format(c_step=current_step, total=total_len))
current_liquid -= release_step
print(x, y)
swift.set_position(x=starting_x + (step_proportional * x), y=starting_y + (step_proportional * y), wait=True,
speed=1500)
sleep(0.3)
swift.set_position(z=printing_z, wait=True)
swift.set_position(e=current_liquid, wait=True, speed=500)
swift.set_position(z=printing_z + 5, wait=True)
# Printing last step
current_liquid += release_step
swift.set_position(z=printing_z, wait=True)
swift.set_position(e=current_liquid, wait=True, speed=300)
swift.set_position(z=printing_z + 3, wait=True)
# Releasing the rest of the liquid
# Dropping off the pipette at disposal area
swift.set_position(e=current_liquid, z=155, speed=30000, wait=True)
temp_z = disposal_args['z']
disposal_args['z'] = 155
swift.set_position(x=269, y=-90, z=155, e=current_liquid, speed=30000, wait=True)
swift.set_position(z=155, speed=30000, timeout=20, wait=True)
swift.set_position(e=0, speed=30000, timeout=20, wait=True)
swift.set_wrist(0)
swift.set_wrist(90)
swift.set_position(z=150, speed=30000, wait=True)
# TODO: check and unite with function above (most of it is copy paste)
def print_pattern_mini(swift: SwiftAPI, pattern_format, starting_position):
# Reading the coords file into a list
print(f'retrieveing coords from {pattern_format}')
coords = []
with open(os.path.join('uploads\coords', pattern_format), 'r') as f:
for line in f:
x, y = line.strip().split("\,")
coords.append((float(x), float(y)))
# Initializing required variables
release_step = -0.070
step_proportional = 2
# Initializing required positions
start_args = starting_position # Starting Point
start_args['wait'] = True
starting_x = start_args['x']
starting_y = start_args['y']
printing_z = start_args['z']
# Moves to printing starting point
swift.set_position(x=(step_proportional * coords[0][0]) + starting_x,
y=(step_proportional * coords[0][1]) + starting_y, z=60, speed=1500, timeout=30, wait=True)
# Printing image's coords
picture = coords
total_len = len(picture)
current_step = 0
for x, y in picture:
current_step += 1
print("{c_step}/{total}".format(c_step=current_step, total=total_len))
print(x, y)
swift.set_position(x=starting_x + (step_proportional * x), y=starting_y + (step_proportional * y), wait=True,
speed=1500)
sleep(0.3)
swift.set_position(z=printing_z, wait=True)
swift.set_position(e=-release_step, wait=True, speed=500, relative=True)
swift.set_position(z=printing_z + 5, wait=True)
# Printing last step
swift.set_position(z=printing_z, wait=True)
swift.set_position(e=release_step, wait=True, speed=300, relative=True)
swift.set_position(z=printing_z + 3, wait=True)
def robot_pump(swift: SwiftAPI, pump_state):
swift.set_pump(on=pump_state)
def move_to_starting_position(swift: SwiftAPI):
swift.set_position(e=0, speed=1500, timeout=30, wait=True)
swift.set_position(120, 0, 50, speed=1500, timeout=30, wait=True)