-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
100 lines (83 loc) · 2.42 KB
/
utils.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
import serial, time
from threading import Thread
import sys
class Utils(object):
def __init__(self):
self.ard = serial.Serial('COM3', 115200)
self.snap = serial.Serial('COM10', 115200)
self.actual_z = [ [],
[],
[],
[],
[],
[],
[],
[],
[],
[],
]
def ard_send(self, data):
self.ard.write(str(data).encode('utf-8'))
def ard_read(self):
data = self.ard.read().decode('utf-8')
if data == '8':
self.snap.write("M112\r\n".encode('utf-8'))
sys.exit(0)
else:
return data
def to_right(self):
time.sleep(1)
self.snap.write(('G53 G0 Z60 F1500\r\n').encode("utf-8"))
time.sleep(1)
self.snap.write("G91\r\n".encode('utf-8'))
time.sleep(1)
self.snap.write("G0 X10 F1500\r\n".encode('utf-8'))
time.sleep(1)
self.snap.write("G90\r\n".encode('utf-8'))
time.sleep(1)
def to_left_to_home(self):
time.sleep(1)
self.snap.write(('G53 G0 X25 F1500\r\n').encode("utf-8"))
time.sleep(2)
self.snap.write("G91\r\n".encode('utf-8'))
time.sleep(2)
self.snap.write("G0 Y10 F1500\r\n".encode('utf-8'))
time.sleep(2)
self.snap.write("G90\r\n".encode('utf-8'))
def home(self):
#self.snap.write(('G53\r\n').encode('utf-8'))
#self.snap.write(("G28\r\n").encode("utf-8"))
self.snap.write(('G53 G0 X25 F1500\r\n').encode("utf-8"))
self.snap.readline().decode('utf-8')
time.sleep(5)
self.snap.write(('G53 G0 Y20 F1500\r\n').encode("utf-8"))
self.snap.readline().decode('utf-8')
time.sleep(5)
self.snap.write(('G53 G0 Z60 F1500\r\n').encode("utf-8"))
self.snap.readline().decode('utf-8')
time.sleep(5)
def cord(self):
self.snap.write(('M114\r\n').encode("utf-8"))
a = (self.snap.readline().decode('utf-8'))
b = (self.snap.readline().decode('utf-8'))
if 'X' in a:
return a.replace('\n', '').split()
elif 'X' in b:
return b.replace('\n', '').split()
else:
return self.cord()
def check_Z(self):
self.snap.write(('G53 G0 Z54 F1500\r\n').encode("utf-8"))
while True:
self.ard_send(1)
data = self.ard_read()
if data == '1':
z = self.cord()
return z
time.sleep(0.05)
self.snap.write(('G91\r\n').encode("utf-8"))
self.snap.readline()
self.snap.write(('G0 Z-0.01 F1500\r\n').encode("utf-8"))
self.snap.readline()
self.snap.write(('G90\r\n').encode("utf-8"))
self.snap.readline()