-
Notifications
You must be signed in to change notification settings - Fork 2
/
4th-axis-measurement-with-touch-probe-and-test-bar.py
executable file
·78 lines (72 loc) · 2.89 KB
/
4th-axis-measurement-with-touch-probe-and-test-bar.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
#!/usr/bin/env python2
import mdiCodeExec
import safeMove
import logging
import linuxcnc
import math
import time
probeToolNumber = 6
pointsInHalfCircle = 10
numAPos = 8
numXPos = 5
xStart = 105.0
xEnd = 225.0
testBarDia = 17.2
probeDia = 2.0
prepareDist = 3.0
latchDist = 0.5
travZCleariance = 5
testFeed = 200.0
probeFeed = 50.0
latchFeed = 600.0
zSafe = travZCleariance + (testBarDia + probeDia) / 2.0
prepareRad = testBarDia / 2.0 + prepareDist
angAcrossHalfCircle = math.pi / (pointsInHalfCircle - 1)
tangentRad = ((testBarDia + probeDia) / 2.0 + latchDist) / \
math.cos(angAcrossHalfCircle/2.0)
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
s = linuxcnc.stat()
with mdiCodeExec.mdiCodeExec() as mdi:
with open('result.txt', 'w') as f:
move = safeMove.safeMove(mdi)
mdi.exe("G17 G8 G21 G40 G49 G64 P0.001 G80 G90 G91.1 G92.2 G94 G97 G98")
# Make sure current CS coincident to G53
mdi.exe("G10 L2 P0 X0 Y0 Z0 R0")
# May timeout
assert mdi.exe("T{} M6".format(probeToolNumber)) != -1
mdi.exe("G43")
move.move(z=zSafe)
for a in [360.0 / numAPos * x for x in range(0, numAPos)]:
move.rapid(a=a)
for xx in [xStart + (xEnd - xStart) / (numXPos - 1) * x
for x in range(0, numXPos)]:
move.move(x=xx, y=prepareRad)
for ang in [angAcrossHalfCircle * x
for x in range(0, pointsInHalfCircle)]:
mdi.exe("G1 Y{:.3f} Z{:.3f} F1000".format(prepareRad * math.cos(ang),
prepareRad * math.sin(ang)))
#move.move(y=prepareRad * math.cos(ang),
# z=prepareRad * math.sin(ang))
#time.sleep(0.1)
#mdi.exe("G38.2 Y0 Z0 F{}".format(testFeed))
#mdi.exe("G91")
#time.sleep(0.1)
#mdi.exe("G1 Y{:.3f} Z{:.3f} F{}".format(latchDist * math.cos(ang),
# latchDist * math.sin(ang), latchFeed))
#mdi.exe("G90")
mdi.exe("G38.2 Y0 Z0 F{}".format(probeFeed))
s.poll()
pr = s.probed_position
f.write("{}\t{}\t{}\t{}\t{}\n".format(pr[0], pr[1], pr[2], a, xx))
mdi.exe("G91")
mdi.exe("G1 Y{:.3f} Z{:.3f} F{}".format(latchDist * math.cos(ang),
latchDist * math.sin(ang), latchFeed))
mdi.exe("G90")
pass
move.move(y=-prepareRad)
move.move(z=zSafe)
pass
pass
pass