-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmagician_copy1.py
461 lines (374 loc) · 16.8 KB
/
magician_copy1.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
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
#! /usr/bin/env python
from glob import glob
import time
import sys
import serial
import math
#from Tkinter import *
from tkinter import *
from tkinter import ttk
#import ttk
import _thread
from DigitalVoltControl import DigitalVoltControl
from Relay import Relay
from ServoGripper import ServoGripper
from pydobot import Dobot
global_status = "Running";
process_running = False;
R_OFFSET = 20;
PROCESS_RH_PD = 'PD_Rh_Silver';
PROCESS_RH_20 = 'Rh_Redip';
PROCESS_RH_60 = 'Rh_White_Gold';
#x,y,z,r,duration
Beakers = [ [0, 0, 0, 0, 0], #0 dummy beaker for numbering
[-16.3, -214.8, 0, -197.2+R_OFFSET - 20, 60], #1 # -135deg
[39.67, -290.2, 0, -185.15+R_OFFSET -10, 5], #2 # -112.6deg
[119.48, -173.56, 0, -158.4+R_OFFSET- 10, 5], #3 # -90deg
[185.99, -193, 0, -122+R_OFFSET-10, 10], #4 # -67.6deg
[187.12, -66.2, 0, -96.4+R_OFFSET-10, 5], #5 # -45deg
[272.41, -13.6, 0, -79.9+R_OFFSET-10, 5], #6 # -22.6deg
[211, -74.7, 0, 30.3+R_OFFSET-5, 5], #7 # 0deg
[271.42, 34.54, 0, 32.1+R_OFFSET, 60], #8 # 22.4deg
[198.72, 70.09, 0, 65+R_OFFSET, 5], #9 # 45deg
[193.53, 206.47, 0, 92.4+R_OFFSET-2, 5], #10 # 67.4deg
[-75.58, 242.89, 0, 152.8+R_OFFSET-5, 60], #11 # 130deg
[75.54, 183.83, 0, 113.22+R_OFFSET+5, 5]]; #12 #97deg
class DobotPlating():
def __init__(self, dobotPort='/dev/ttyUSB0'):
available_ports = glob('/dev/tty*USB*') # mask for OSX Dobot port
if len(available_ports) == 0:
print('no port /dev/tty*USB* found for Dobot Magician')
exit(1)
else:
dobotPort = available_ports[0];
#self.DobotPort = 'COM4'
self.DobotPort = dobotPort;
self.ecRelay = Relay(18);#bcm pin for physical pin 12
self.pdRelay = Relay(24);#bcm for physical 18
self.rhRelay = Relay(23);#bcm for physical 16
self.gripper = ServoGripper(2);
self.dvc = DigitalVoltControl();
self.RH_Duration = 60;
self.lastCmd = [0,0,0,0]; #x, y, z, r
print("Setting Port to " + self.DobotPort);
self.device = Dobot(port=self.DobotPort)
time.sleep(1)
if self.device is not None:
print("Opened connection")
self.device.speed()
self.z_up = 100
self.z_down = -70
#self.RH_Voltage = 2.5;
#self.PD_Voltage = 1.9;
#self.EC_Voltage = 4.8;
self.home_xyzr = [215, 0, self.z_up, 0];
global global_status
global_status = "Rh Electroplating";
def calibrate(self):
global global_status
response = self.device.setHomeParams(self.home_xyzr[0], self.home_xyzr[1], self.home_xyzr[2], self.home_xyzr[3]);
#if(response):
# global_status = "Error..";
response = self.device.goHome();
# if(response):
# global_status = "Error..";
def isMoveFinished(self):
euDist = math.pow(self.lastCmd[0] - self.device.x,2) + math.pow(self.lastCmd[1] - self.device.y, 2) + math.pow(self.lastCmd[2] - self.device.z, 2) + math.pow(self.lastCmd[3] - self.device.r, 2);
euDist = math.sqrt(euDist);
if(euDist < 2):
return True;
else:
#print("still moving ..");
return False;
def move_home(self):
self.move_xy(self.home_xyzr[0], self.home_xyzr[1], self.home_xyzr[2], self.home_xyzr[3], 0.3);
def move_xy(self, x, y, z, r, duration = 1):
self.lastCmd = [x, y, z, r];
response = self.device.go(x, y, z, r); #MOVJ
# if(response):
# global global_status
# global_status = "Error..";
# time.sleep(duration);
# print("in is move finished..");
print("xyzr position: " + str(self.device.x) + ", " + str(self.device.y) + ", " + str(self.device.z) + ", " + str(self.device.r));
def move_xy_linear(self, x, y, z, r, duration = 1):
self.lastCmd = [x, y, z, r];
response = self.device.goMovL(x, y, z, r); #MOVJ
# if(response):
# global global_status
# global_status = "Error..";
# time.sleep(duration);
# print("in is move finished..");
print("xyzr position: " + str(self.device.x) + ", " + str(self.device.y) + ", " + str(self.device.z) + ", " + str(self.device.r));
def shake(self, x, y, z, r, shakeDuration, dispStr, dontShake=False, doInOut=False):
global global_status;
t_end = time.time() + shakeDuration;
tdiff = t_end - time.time();
while tdiff > 0:
if(dispStr is not None):
global_status = dispStr + " " + str(int(tdiff)) + "s"
if(not dontShake):
self.move_xy(x, y, z + 10, r, 0.1);
self.move_xy(x, y, z - 10, r, 0.1);
tdiff = t_end - time.time();
def up_down_beaker(self,id,dispStr=None):
print ("Doing beaker %d now" % (id));
self.move_xy(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3], 0.3);
self.move_xy(Beakers[id][0], Beakers[id][1], (self.z_up + self.z_down)/2.0 , Beakers[id][3], 0.3); #adding a mid point so that the Joint motion isn't touching th edges of the beakers
self.move_xy(Beakers[id][0], Beakers[id][1], self.z_down, Beakers[id][3], 0.3);
#dispStr = "Step " + str(id) + ": ";
while(not self.isMoveFinished()):
time.sleep(0.01);
if(id == 1):
self.ecRelay.on();
# dispStr = dispStr + "EC "
elif(id == 8):
self.pdRelay.on();
# dispStr = dispStr + "Pd Solution "
elif(id == 11):
self.rhRelay.on();
# dispStr = dispStr + "Rh Solution "
if(id == 1 or id == 8 or id == 11):
if(id == 11):
self.shake(Beakers[id][0], Beakers[id][1], self.z_down - 10, Beakers[id][3], self.RH_Duration, dispStr); #x, y, z and shake_duration
elif(id == 1): #dont' shake
self.shake(Beakers[id][0], Beakers[id][1], self.z_down, Beakers[id][3], self.RH_Duration, dispStr, True); #x, y, z and shake_duration
else:
self.shake(Beakers[id][0], Beakers[id][1], self.z_down, Beakers[id][3], self.RH_Duration, dispStr); #x, y, z and shake_duration
else:
self.shake(Beakers[id][0], Beakers[id][1], self.z_down, Beakers[id][3], Beakers[id][4], None); #x, y, z and shake_duration
self.ecRelay.off();
self.pdRelay.off();
self.rhRelay.off();
#move up
#shake to drop the excess drops
#go half way to adjust for MOVJ
self.move_xy(Beakers[id][0], Beakers[id][1], (self.z_up + self.z_down)/2.0 , Beakers[id][3], 0.3); #adding a mid point so that the Joint motion isn't touching th edges of the beakers
#self.move_xy(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3]);
self.shake(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3], 2, None);
self.move_xy(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3]);
while(not self.isMoveFinished()):
time.sleep(0.01);
def startProcess(self, EC_Voltage, PD_Voltage, RH_Voltage, processType):
global process_running
process_running = True;
global global_status
self.RH_Duration = 60;
if(processType == PROCESS_RH_20):
self.RH_Duration = 20;
global_status = "Step 1: EC"
#1
if(EC_Voltage == 5.6):
self.dvc.setMaxVoltage();
else:
self.dvc.setVoltage(EC_Voltage);
self.up_down_beaker(1, global_status);
#2
global_status = "Step 2: Dragout"
self.up_down_beaker(2);
#3
global_status = "Step 3: Water"
self.up_down_beaker(3);
#4
global_status = "Step 4: Activation"
self.up_down_beaker(4);
#5
global_status = "Step 5: Water"
self.up_down_beaker(5);
#6
global_status = "Step 6: Water"
self.up_down_beaker(6);
#7
global_status = "Step 7: Water"
self.up_down_beaker(7);
#8
if(processType == PROCESS_RH_PD):
global_status = "Step 8: Pd Solution"
self.dvc.setVoltage(PD_Voltage);
self.up_down_beaker(8, global_status);
#9
global_status = "Step 9: Pd Dragout"
self.up_down_beaker(9);
#10
global_status = "Step 10: Water"
self.up_down_beaker(10);
#11
if(processType == PROCESS_RH_PD):
global_status = "Step 11: Rh Solution"
else:
global_status = "Step 8: Rh Solution"
self.dvc.setVoltage(RH_Voltage);
self.up_down_beaker(11, global_status);
#12
if(processType == PROCESS_RH_PD):
global_status = "Step 12: Rh Dragout"
else:
global_status = "Step 9: Rh Dragout"
self.up_down_beaker(12);
#13 #repeat of beaker 10
if(processType == PROCESS_RH_PD):
global_status = "Step 13: Water"
else:
global_status = "Step 10: Water"
self.up_down_beaker(10);
#Home
self.move_home()
global_status = "Done.."
process_running = False;
print("\n DONE \n");
def __del__(self):
self.device.close();
del self.gripper;
del self.dvc;
del self.ecRelay;
del self.pdRelay;
del self.rhRelay;
print("Exiting Cleanly..");
class PlatingGUI():
def __init__(self):
self.root = Tk()
self.root.title("Rh Electroplating")
self.calibrated = False;
framew = 500; # root w
frameh = 300; # root h
screenw = self.root.winfo_screenwidth();
screenh = self.root.winfo_screenheight();
posx = (screenw/2) - (framew/2);
posy = (screenh/2) - (frameh/2);
self.root.geometry( "%dx%d+%d+%d" % (framew,frameh,posx,posy))
self.current_status = StringVar();
self.current_status.set('Rh Electroplating');
self.mainframe = ttk.Frame(self.root, padding="10 10 30 30", height=300, width=500)
self.mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
self.mainframe.columnconfigure(0, weight=50,minsize=50)
self.mainframe.rowconfigure(0, weight=50,minsize=50)
#self.mainframe.grid_propagate(0);
self.buttonStyle = ttk.Style()
self.buttonStyle.configure('my.TButton', font=('Helvetica', 18))
self.l = ttk.Label(self.mainframe, textvariable=self.current_status, font=('Helvetica',18));
#self.l.place(relx=0.35, rely=0.3, anchor='center')
self.l.grid(row=0, column=0, columnspan=2, pady=5)
self.ecvar = StringVar(self.root)
self.pdvar = StringVar(self.root)
self.rhvar = StringVar(self.root)
self.processType = StringVar(self.root)
ecchoices = {'5.6'}
pdchoices = { '1.8','1.9','2.0','2.1'}
rhchoices = { '2.5','2.6','2.75','2.85','3.0'}
processChoices = {PROCESS_RH_PD, PROCESS_RH_60, PROCESS_RH_20};
self.ecvar.set('5.6') # set the default option
self.pdvar.set('1.9')
self.rhvar.set('2.5')
self.processType.set(PROCESS_RH_PD);
self.ecVoltage = float(self.ecvar.get());
self.pdVoltage = float(self.pdvar.get());
self.rhVoltage = float(self.rhvar.get());
self.processToDo = self.processType.get();
processChoicepopupMenu = OptionMenu(self.mainframe, self.processType, *processChoices)
Label(self.mainframe, text="Choose Process", font=("Helvetica", 14)).grid(row = 2, column=1, pady=(15,2))
processChoicepopupMenu.grid(row=3, column=1)
processChoicepopupMenu.bind('<Button-1>', self.dropdownopen)
pdpopupMenu = OptionMenu(self.mainframe, self.pdvar, *pdchoices)
Label(self.mainframe, text="Pd Voltage", font=("Helvetica", 14)).grid(row = 5, column = 0, pady=(15,2))
pdpopupMenu.grid(row = 6, column =0)
pdpopupMenu.bind('<Button-1>', self.dropdownopen)
rhpopupMenu = OptionMenu(self.mainframe, self.rhvar, *rhchoices)
Label(self.mainframe, text="Rh Voltage", font=("Helvetica", 14)).grid(row = 5, column = 1, pady=(15,2))
rhpopupMenu.grid(row = 6, column=1)
rhpopupMenu.bind('<Button-1>', self.dropdownopen)
self.ecvar.trace('w', self.ec_change)
self.pdvar.trace('w', self.pd_change)
self.rhvar.trace('w', self.rh_change)
self.processType.trace('w', self.process_change)
ttk.Button(self.mainframe, text="Calibrate", style='my.TButton', command=self.calibrateDobot, width=16).grid(row=2, rowspan=2, column=0, pady=5)
ttk.Button(self.mainframe, text="Start", style='my.TButton',command=self.popup, width=16).grid(row=8, rowspan=2,column=0, pady=(20,2))
ttk.Button(self.mainframe, text="Exit", style='my.TButton', command=self.stopProcess, width=16).grid(row=8, rowspan=2, column=1, pady=(20,2))
self.root.after(1000, self.updateLabel);
self.dobotPlating = DobotPlating();
def calibrateDobot(self):
global process_running
if(not process_running):
print('Will Calibrate now..');
global global_status;
global_status = "Calibrating.. Please Wait!";
self.dobotPlating.calibrate();
time.sleep(20);
self.calibrated = True;
global_status = "Calibrated";
def dropdownopen(self, event):
global process_running
if(process_running):
self.toplevel = Toplevel()
self.toplevel.wm_attributes("-topmost", 1)
framew = 300; # root w
frameh = 75; # root h
screenw = self.root.winfo_screenwidth();
screenh = self.root.winfo_screenheight();
posx = (screenw/2) - (framew/2);
posy = (screenh/2) - (frameh/2);
self.toplevel.geometry( "%dx%d+%d+%d" % (framew,frameh,posx,posy))
self.label1 = Label(self.toplevel, text="Can't change value when process is running..", height=0, width=100)
self.label1.pack(padx=5)
self.but1 = Button(self.toplevel, text="OK", command=self.dropdownokpressed);
self.but1.pack(pady=5);
def initialPopup(self):
self.toplevel = Toplevel()
self.toplevel.wm_attributes("-topmost", 1)
framew = 300; # root w
frameh = 75; # root h
screenw = self.root.winfo_screenwidth();
screenh = self.root.winfo_screenheight();
posx = (screenw/2) - (framew/2);
posy = (screenh/2) - (frameh/2);
self.toplevel.geometry( "%dx%d+%d+%d" % (framew,frameh,posx,posy))
#self.toplevel.geometry("300x75+500+500");
self.label1 = Label(self.toplevel, text="Please Calibrate First!", font=("Helvetica",14), height=0, width=100)
self.label1.pack(padx=5)
self.but1 = Button(self.toplevel, text="OK", command=self.dropdownokpressed);
self.but1.pack(pady=5);
def dropdownokpressed(self):
self.toplevel.destroy();
def ec_change(self,*args):
self.ecVoltage = float(self.ecvar.get());
print( 'EC Volt set to '),
print (self.ecVoltage)
def process_change(self, *args):
self.processToDo = self.processType.get();
print ('Process changed to: '),
print (self.processToDo);
# on change dropdown value
def pd_change(self,*args):
self.pdVoltage = float(self.pdvar.get());
print( 'Pd Volt set to '),
print (self.pdVoltage)
# on change dropdown value
def rh_change(self,*args):
self.rhVoltage = float(self.rhvar.get());
print( 'Rh Volt set to '),
print (self.rhVoltage)
def updateLabel(self):
global global_status;
self.current_status.set(global_status);
self.l.config(textvariable=self.current_status);
#self.l.place(x=100, y=5)
self.l.grid(row=0)
self.l.update_idletasks();
self.root.update_idletasks();
self.root.after(500, self.updateLabel);
def stopProcess(self):
del self.dobotPlating
self.root.quit();
exit(1);
def popup(self):
global process_running
if(not process_running and self.calibrated):
self.processThread = _thread.start_new_thread(self.dobotPlating.startProcess, (self.ecVoltage, self.pdVoltage, self.rhVoltage, self.processToDo));
else:
self.initialPopup();
def __del__(self):
if self.processThread is not None:
self.processThread.exit();
del self.dobotPlating;
print("GUI Exited Cleanly..");
gui = PlatingGUI();
gui.root.mainloop();