-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.py
executable file
·99 lines (81 loc) · 2.32 KB
/
scan.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
#!/usr/bin/python
import serial
import time
port = "/dev/ttyUSB0"
baudrate = 250000
ser = serial.Serial(port, baudrate, timeout=5)
X_max = 320 # X dimension in mm
X_min = 0
Y_max = 308 # Y dimension in mm
Y_min = 0
X_res = 100 # X resolution
Y_res = 100 # Y resolution
G38_F = 1000 # G38 feedrate (probe)
G1_F = 6000 # G1 feedrate (move)
Z_max = 1 # Z maximum position
Z_min = -1 # Z minimum position
G38 = "G38.3" # G38 command
zigzag_order = True
output_file = "points.txt"
def send(s, comment = ''):
ser.write(s+"\n")
if comment != '': print s, "\t# ", comment
else: print s
def read_init():
r = ''
s = False
while r != 'ok':
r = ser.readline().strip()
if r == '' and not s:
send("M400")
s = True
print r
def wait_for(w):
r = ''
result = []
while r != w:
r = ser.readline().strip()
print r
result.append(r)
if r[0:5] == "Error": raise AssertionError("got an error: " + r)
return result
def run(c, comment = ''):
send(c, comment)
return wait_for('ok')
def c_add(c, vs, v):
if v is not None: c+= ' ' + vs + str(v)
return c
def c_add_xyz(c, x, y, z, f):
c = c_add(c, "F", f)
c = c_add(c, "X", x)
c = c_add(c, "Y", y)
c = c_add(c, "Z", z)
return c
def G1(x = None, y = None, z = None):
run(c_add_xyz("G1", x, y, z, G1_F))
def d(s):
print "DEBUG: ", s
def get_point(x,y):
G1(x, y, Z_max)
#run("M211 S0", "Disable Software Endstops")
run(G38 + " F" + str(G38_F) + " Z" + str(Z_min))
w = run("M114")
G1(x, y, Z_max)
#run("M211 S1", "Enable Software Endstops")
return w[0]
def main():
out = open(output_file,"w")
read_init()
d("init command")
run("G90", "Set to Absolute Positioning")
run("G28", "Move to Origin (Home)")
run("M211 S0", "Disable Software Endstops")
for j in range(0, Y_res):
for i in range(0, X_res):
if (j % 2) == 1 and zigzag_order: ii = X_res-i-1
else: ii = i
x = X_min + (X_max-X_min) * ii/(X_res-1)
y = Y_min + (Y_max-Y_min) * j/(Y_res-1)
r = get_point(x, y)
out.write(r+"\n")
main()