I've solved my problems by rewriting the M1077 and M1078 macros. I use them quite often, because it's the simplest way to machine standard parts on the lathe - by combining G77 / G78 words. It first does roughing with the values in the general options when no h word is given and makes a sizing move with 40% feed and 40% of the roughing amount. Also, it evens the roughing passes out so that they are all the same amount. So, here is my code, without warranty of course:
M0177:
' G77
'(Xx.*********x XDia NEEDED)
'(Zx.*********x End Z NEEDED)
'(Fx.*********x Feedrate)
'(can be Set In the settings page: 'Hx.*********x Depth of cut)
'(Cx.*********x Clearance In the X)
'(Qx.*********x Clearance In the Z)
'(Kx.*********x ZStartpoint)
'(Rx.*********x XStartpoint)
'(Tx.*********x Taper In Deg)
Sub Main()
ZClearance = Abs(tZClear()) 'This one it not avalable
XClearance = Abs(tClearX())
StartX = tXStart()
StartZ = tZStart()
EndX = tEndX()
EndZ = tEndZ()
Taper = tTaper()
FirstPassDepth = tFirstPass()
RoughAmount = abs(tCutDepth())
Feed = Feedrate()
SizingAmount = RoughAmount * 0.4
SizeFeed = Feed * 0.4
PI = 3.1415926
If StartZ > EndZ Then
RightLeft = 1
Else
RightLeft = -1
ZClearance = ZClearance * -1
End If
If StartX < EndX Then 'Inside Turning
IDOD = -1
XClearance = XClearance * -1
Else
IDOD = 1 'Outside
End If
'Calc the distance X needed to make the taper angle
TaperX = Abs(StartZ - EndZ)* Tan((Taper * PI)/180)
If TaperX > Abs(StartX - EndX) Then
EndZ = StartZ - Abs(StartZ - EndZ) * RightLeft * ( Abs(StartX-EndX) / TaperX )
TaperX = Abs(StartX - EndX)
End If
code "G0 X" & StartX + XClearance & " Z" & StartZ + ZClearance
code "F" & Feed
PassNum = 1
LastPassDia = StartX
'optimize roughing value
Passes = (Abs(StartX - EndX) - SizingAmount) / RoughAmount
If CInt(Passes) <> Passes Then
passes = CInt(Passes) + 1
RoughAmount = (Abs(StartX - EndX) - SizingAmount) / Passes
End If
Do 'Roughing Loop
PassDia = StartX - (RoughAmount * IDOD * PassNum)
code "G0 X" & PassDia
If TaperX <> 0 And Abs(PassDia-EndX) < TaperX + SizingAmount Then
'Taper turn section
ZCalc = StartZ - RightLeft * Abs(( (StartZ - EndZ) * (Abs(PassDia - EndX) - SizingAmount)) / TaperX )
code "G1 Z" & nFmt(ZCalc,4)
If (Abs(PassDia-EndX) < TaperX + SizingAmount) And (Abs(LastPassDia-EndX) > TaperX + SizingAmount) Then
code "X" & EndX + (TaperX + SizingAmount) * IDOD & " Z" & EndZ + SizingAmount * RightLeft
code "X" & LastPassDia
PosZ = EndZ + SizingAmount * RightLeft
Else
ZCalc = StartZ - RightLeft * Abs(( (StartZ - EndZ) * (Abs(LastPassDia - EndX) - SizingAmount)) / TaperX )
code "X" & LastPassDia & " Z" & nFmt(ZCalc,4)
PosZ = nFmt(ZCalc,4)
End If
If PassNum = Passes Then Exit Do
code "G0 X" & LastPassDia + XClearance & " Z" & PosZ + ZClearance
Else
'Straight turn section
code "G1 Z" & EndZ + SizingAmount * RightLeft
PosZ = EndZ + SizingAmount * RightLeft
code "X" & LastPassDia
If PassNum = Passes Then Exit Do
If Abs(LastPassDia - PassDia) < Abs(XClearance) Then
code "G0 X" & PassDia + XClearance & " Z" & PosZ + ZClearance
End If
End If
code "G0 Z" & StartZ + ZClearance
LastPassDia = PassDia
PassNum = PassNum + 1
Loop
'sizing
code "F" & SizeFeed
If Abs(EndX - StartX) > TaperX Then
If TaperX = 0 Then
code "G0 X" & PassDia + XClearance & " Z" & PosZ + ZClearance
End If
code "X" & StartX + XClearance
code "Z" & EndZ
If TaperX <> 0 Then
code "G1 X" & EndX + (TaperX + SizingAmount) * IDOD
code "G0 X" & EndX + XClearance + (TaperX + SizingAmount) * IDOD & " Z" & EndZ + ZClearance
Else
code "G1 X" & PassDia
code "G0 X" & PassDia + XClearance & " Z" & EndZ + ZClearance
End If
End If
code "Z" & StartZ + ZClearance
code "X" & EndX
If TaperX = 0 Then
code "G1 Z" & EndZ
code "X" & PassDia
code "G0 X" & PassDia + XClearance & " Z" & EndZ + ZClearance
Else
code "G1 Z" & StartZ
If Abs(StartX-EndX) > TaperX Then
code "G1 Z" & EndZ & " X" & EndX + TaperX * IDOD
code "X" & EndX + (TaperX + SizingAmount) * IDOD
code "G0 X" & EndX + (TaperX + SizingAmount) * IDOD + XClearance & " Z" & EndZ + ZClearance
code "X" & StartX + XClearance & " Z" & EndZ + ZClearance
Else
code "G1 Z" & EndZ & " X" & EndX + TaperX * IDOD
code "G0 X" & StartX + XClearance & " Z" & EndZ + ZClearance
End If
End If
code "G0 X" & StartX & " Z" & StartZ
code "F" & Feed
End Sub
Main
=================================================================================
M0178:
'G78
'(Xx.*********x XDia NEEDED)
'(Zx.*********x End Z NEEDED)
'(Fx.*********x Feedrate)
'(can be Set In the settings page: 'Hx.*********x Depth of cut)
'(Cx.*********x Clearance In the X)
'(Qx.*********x Clearance In the Z)
'(Kx.*********x ZStartpoint)
'(Rx.*********x XStartpoint)
'(Tx.*********x Taper In Deg)
Sub Main()
ZClearance = Abs(tZClear()) 'This one it not avalable
XClearance = Abs(tClearX())
StartX = tXStart()
StartZ = tZStart()
EndX = tEndX()
EndZ = tEndZ()
Taper = tTaper()
FirstPassDepth = tFirstPass()
RoughAmount = tCutDepth()
Feed = FeedRate()
SizingAmount = RoughAmount * 0.4
SizeFeed = Feed * 0.4
PI = 3.1415926
If StartX < EndX Then
IDOD = -1
XClearance = XClearance * -1
Else
IDOD = 1
End If
If StartZ > EndZ Then
RightLeft = 1
Else
RightLeft = -1
ZClearance = ZClearance * -1
End If
If Taper <> 0 Then
TaperZ = Abs(StartX - EndX) / Tan((Taper * PI)/180)
If TaperZ < Abs(StartZ - EndZ) Then
TaperX = Abs(StartX - EndX)
EndZ = StartZ - TaperZ * RightLeft
Else
TaperX = Abs(StartZ - EndZ) * Tan((Taper * PI)/180)
End If
End If
code "G0 X" & StartX + XClearance & " Z" & StartZ + ZClearance
code "F" & Feed
PassNum = 1
LastPassDepth = StartZ
'optimize roughing value
Passes = (Abs(StartZ - EndZ) - SizingAmount) / RoughAmount
If CInt(Passes) <> Passes Then
Passes = CInt(Passes) + 1
RoughAmount = (Abs(StartZ - EndZ) - SizingAmount) / Passes
End If
Do
PassDepth = StartZ - (RoughAmount * PassNum * RightLeft)
code "G0 Z" & PassDepth
If taper <> 0 Then
XCalc = EndX + IDOD * Abs((StartX - EndX) * (Abs(StartZ - PassDepth) + SizingAmount) / TaperZ )
code "G01 X" & XCalc
XCalc = EndX + IDOD * Abs((StartX - EndX) * (Abs(StartZ - LastPassDepth) + SizingAmount) / TaperZ )
code "X" & XCalc & " Z" & LastPassDepth
PosX = XCalc
If PassNum = Passes Then Exit Do
code "G0 X" & PosX + XClearance & " Z" & LastPassDepth + ZClearance
Else
code "G1 X" & EndX + SizingAmount * IDOD
PosX = EndX + SizingAmount * IDOD
code "G1 Z" & LastPassDepth
If PassNum = Passes Then Exit Do
If Abs(LastPassDepth - PassDepth) < Abs(ZClearance) Then
code "G0 X" & PosX + XClearance & " Z" & PassDepth + ZClearance
End If
End If
code "G0 X" & StartX + XClearance
LastPassDepth = PassDepth
PassNum = PassNum + 1
Loop
'sizing
code "F" & SizeFeed
If Taper = 0 Then
code "G0 X" & EndX + SizingAmount * IDOD + XClearance & " Z" & EndZ + SizingAmount * RightLeft + ZClearance
code "Z" & StartZ + ZClearance
code "X" & EndX
code "G1 Z" & EndZ + SizingAmount * RightLeft
code "G0 X" & EndX + XClearance & " Z" & EndZ + SizingAmount * RightLeft + ZClearance
Else
code "G0 X" & PosX + XClearance & " Z" & EndZ + SizingAmount * RightLeft + ZClearance
End If
code "X" & StartX + XClearance
code "Z" & EndZ
code "G1 X" & StartX
If taper = 0 Then
code "X" & EndX
code "Z" & EndZ + SizingAmount * RightLeft
code "G0 X" & EndX + XClearance & " Z" & EndZ + ZClearance
Else
If Abs(StartX - EndX) > TaperX Then
code "X" & EndX + IDOD * TaperX
End If
code "X" & EndX & " Z" & StartZ
code "G0 X" & EndX + XClearance & " Z" & StartZ + ZClearance
End If
code "G0 X" & StartX & " Z" & StartZ
code "F" & Feed
End Sub
Main