-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathToolOffset.py
executable file
·98 lines (87 loc) · 4.22 KB
/
ToolOffset.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
#!/usr/bin/env python3
# Python script intended to determine tool-to-tool offsets on a tool changing 3D printer
# running a Duet 3 with Pi.
#
# Must run with root priviledge, such as via sudo.
#
# Copyright (C) 2020 Danal Estes all rights reserved.
# Released under The MIT License. Full text available via https://opensource.org/licenses/MIT
#
# Edit these for your printer.
tl = [0,1] # List of tools to be compared
yc = 225 # Y line that will clear parked tools when moving in X
xz = 290 # X coord of flat plate to probe Z. 15x15mm area recommended.
yz = 285 # Y coord of flat plate to probe Z. 15x15mm area recommended.
xh = 290 # X coord of hole in which nozzle is inserted to probe XY. 15mm dia recommended
yh = 272 # Y coord of hole in which nozzle is inserted to probe XY. 15mm dia recommended
hd = 1.1 # Depth to lower nozzle into hole when probing. Depends on shape of nozzle.
# About .9 to 1.1 works for most brass nozzles.
zo = -3.1 # Offset from flat plate area probe Z to actual Z0 on print surface.
# Normally, change nothing below this line.
#
#
#
toffs = [[0] * 3 for i in range(len(tl))]
import pythondcs
dcs = pythondcs.PythonDCS()
def probeTool(tn):
dcs.resetEndstops()
dcs.gCode('M400')
dcs.gCode('T'+str(tn)) # Pick up Tool
dcs.gCode('G10 P'+str(tn)+' Z0 X0 Y0') # Remove all offsets from Tool
# Z Axis
dcs.gCode('M574 Z1 S1 P"!io5.in"')
dcs.gCode('G0 Z10 F1000') # Lower bed to avoid collision with hole plate.
dcs.gCode('G0 Y'+str(yc)+' F10000') # Move nozzle to avoid other tools
dcs.gCode('G0 X'+str(xz)+' F10000') # Move nozzle to axis of flat area
dcs.gCode('G0 X'+str(xz)+' Y'+str(yz)+' F10000') # Move nozzle to spot above flat part of plate
dcs.gCode('G1 H3 Z1 F100')
toffs[tn][2] = dcs.getPos()[2] # Capture the Z position at initial point of contact
dcs.resetAxisLimits()
dcs.gCode('G0 Z'+str(toffs[tn][2]+1)+' F100') # Back off just slightly
dcs.gCode('G1 H3 Z1 F10')
toffs[tn][2] = dcs.getPos()[2] # Capture the Z position at point of contact
dcs.resetAxisLimits()
print(toffs[tn][2])
if (toffs[tn][2] < 1.1):
print('Z less than 1.1, very likely miss on Z probe, stoping script to avoid damange to printer')
dcs.resetEndstops()
exit(8)
dcs.gCode('G0 Z10 F1000') # Lower bed to avoid collision with hole plate.
dcs.gCode('M574 Z1 S1 P"nil"')
# X Axis - First Pass for finding Y center
dcs.gCode('M574 X1 S1 P"!io5.in"')
dcs.gCode('G0 X'+str(xh)+' Y'+str(yh)+' F1000') # Place the nozzle tip in center of hole.
dcs.gCode('G0 Z'+str(toffs[tn][2]-1.1)+' F100') # Place the nozzle tip just below surface.
dcs.gCode('M675 X R1 F100') # Probe both ways, thus creating a chord and leaving nozzle at center X
dcs.gCode('M574 X1 S1 P"nil"')
# Y Axis
dcs.gCode('M574 Y1 S1 P"!io5.in"')
dcs.gCode('M675 Y R1 F100') # Probe both ways for Y while centered on X... now centered on Y
toffs[tn][1] = dcs.getPos()[1] # Capture the Y position
dcs.gCode('M574 Y1 S1 P"nil"')
# X Axis - Second Pass now that Y is centered
dcs.gCode('M574 X1 S1 P"!io5.in"')
dcs.gCode('M675 X R1 F100') # Probe both ways on X while centered on Y... now centered on both X and Y
toffs[tn][0] = dcs.getPos()[0] # Capture the X position
dcs.gCode('M574 X1 S1 P"nil"')
dcs.gCode('T-1')
dcs.gCode('M400')
# End of probeTool function
#
# Main
#
for t in tl:
probeTool(t)
dcs.resetEndstops()
# Display Results
for i in range(len(toffs)):
for j in range(len(toffs[i])):
print('Tool '+str(i)+' Axis '+str(j)+' = '+str(toffs[i][j]))
for j in range(len(toffs[0])):
print('Axis '+str(j)+' difference = '+str(toffs[0][j]-toffs[1][j]))
# Actually set G10 offsets
for i in range(len(toffs)):
tn = tl[i]
dcs.gCode('G10 P'+str(tn)+' Z'+str((-toffs[i][2])-zo))
dcs.gCode('G10 P'+str(tn)+' X'+str(toffs[0][0]-toffs[i][0])+' Y'+str(toffs[0][1]-toffs[i][1]))