Fixed lead in/out with elevator location.
This commit is contained in:
@@ -176,7 +176,7 @@ def threadCommands(center, cmd, zStart, zFinal, pitch, radius, leadInOut, elevat
|
||||
|
||||
if PathGeom.isRoughly(z, thread.zFinal):
|
||||
x = center.x
|
||||
y = yMin if 0 == (i & 0x01) else yMax
|
||||
y = yMin if (i & 0x01) else yMax
|
||||
else:
|
||||
n = math.fabs(thread.zFinal - thread.zStart) / thread.hPitch
|
||||
k = n - int(n)
|
||||
@@ -191,20 +191,26 @@ def threadCommands(center, cmd, zStart, zFinal, pitch, radius, leadInOut, elevat
|
||||
comment(path, 'finish-thread')
|
||||
|
||||
a = math.atan2(y - center.y, x - center.x)
|
||||
dx = math.cos(a) * elevator
|
||||
dy = math.sin(a) * elevator
|
||||
dx = math.cos(a) * (radius - elevator)
|
||||
dy = math.sin(a) * (radius - elevator)
|
||||
PathLog.debug('')
|
||||
PathLog.debug("a={}: dx={:.2f}, dy={:.2f}".format(a / math.pi * 180, dx, dy))
|
||||
|
||||
elevatorX = x - dx
|
||||
elevatorY = y - dy
|
||||
PathLog.debug("({:.2f}, {:.2f}) -> ({:.2f}, {:.2f})".format(x, y, elevatorX, elevatorY))
|
||||
|
||||
if leadInOut:
|
||||
comment(path, 'lead-out')
|
||||
path.append(
|
||||
Path.Command(
|
||||
thread.cmd,
|
||||
{"X": center.x + dx, "Y": center.y + dy, "I": dx / 2, "J": dy / 2},
|
||||
{"X": elevatorX, "Y": elevatorY, "I": -dx / 2, "J": -dy / 2},
|
||||
)
|
||||
)
|
||||
comment(path, 'lead-out')
|
||||
|
||||
path.append(Path.Command("G1", {"X": center.x + dx, "Y": center.y - dy}))
|
||||
else:
|
||||
path.append(Path.Command("G1", {"X": elevatorX, "Y": elevatorY}))
|
||||
|
||||
return path
|
||||
|
||||
|
||||
@@ -206,3 +206,59 @@ class TestPathThreadMilling(PathTestBase):
|
||||
]
|
||||
self.assertEqual([p.toGCode() for p in path], gcode)
|
||||
|
||||
def test50(self):
|
||||
'''Verify lead in/out commands for a single thread'''
|
||||
|
||||
center = FreeCAD.Vector()
|
||||
cmd = 'G2'
|
||||
zStart = 0
|
||||
zFinal = 1
|
||||
pitch = 1
|
||||
radius = 3
|
||||
leadInOut = True
|
||||
elevator = 2
|
||||
|
||||
path = PathThreadMilling.threadCommands(center, cmd, zStart, zFinal, pitch, radius, leadInOut, elevator)
|
||||
|
||||
gcode = [
|
||||
'G0 X0.000000 Y2.000000',
|
||||
'G0 Z0.000000',
|
||||
'(------- lead-in -------)',
|
||||
'G2 J0.500000 Y3.000000',
|
||||
'(------- lead-in -------)',
|
||||
'G2 J-3.000000 Y-3.000000 Z0.500000',
|
||||
'G2 J3.000000 Y3.000000 Z1.000000',
|
||||
'(------- lead-out -------)',
|
||||
'G2 I0.000000 J-0.500000 X0.000000 Y2.000000',
|
||||
'(------- lead-out -------)',
|
||||
]
|
||||
self.assertEqual([p.toGCode() for p in path], gcode)
|
||||
|
||||
def test51(self):
|
||||
'''Verify lead in/out commands for one and a half threads'''
|
||||
|
||||
center = FreeCAD.Vector()
|
||||
cmd = 'G2'
|
||||
zStart = 0
|
||||
zFinal = 1.5
|
||||
pitch = 1
|
||||
radius = 3
|
||||
leadInOut = True
|
||||
elevator = 2
|
||||
|
||||
path = PathThreadMilling.threadCommands(center, cmd, zStart, zFinal, pitch, radius, leadInOut, elevator)
|
||||
|
||||
gcode = [
|
||||
'G0 X0.000000 Y2.000000',
|
||||
'G0 Z0.000000',
|
||||
'(------- lead-in -------)',
|
||||
'G2 J0.500000 Y3.000000',
|
||||
'(------- lead-in -------)',
|
||||
'G2 J-3.000000 Y-3.000000 Z0.500000',
|
||||
'G2 J3.000000 Y3.000000 Z1.000000',
|
||||
'G2 J-3.000000 Y-3.000000 Z1.500000',
|
||||
'(------- lead-out -------)',
|
||||
'G2 I0.000000 J0.500000 X0.000000 Y-2.000000',
|
||||
'(------- lead-out -------)',
|
||||
]
|
||||
self.assertEqual([p.toGCode() for p in path], gcode)
|
||||
|
||||
Reference in New Issue
Block a user