

Kod: Zaznacz cały
'sub Main()
Option Explicit
dim units, toolPath, toolDirection,toolEntryMode
dim xyFeedRate,zFeedRate,toolDiameter,maxDepthPerPass,TotalDepthOfCut
dim finishCutDepth, finishCutWidth,zRapidClearanceHeight, zInitialStartHeight
dim spindleSpeed, slotOrientation, coolant
dim xStart,slotLength,yStart,slotWidth
dim roughSlotLength,roughSlotWidth, radius
dim beginX, beginY
dim nextX, nextY
dim i, numberOfPasses,calculatedToolDiameter,entry
dim pi,slotAngle
dim finishSlotLength,finishSlotWidth
dim startAngle,endAngle, arcCenterPointX,arcCenterPointY, arcRadius
dim arcStartX,arcStartY,arcEndX,arcEndY,centerPointY,centerPointX
dim arcStartX1,arcStartY1,arcEndX1,arcEndY1
dim arcStartX2,arcStartY2,arcEndX2,arcEndY2
dim arcStartX3,arcStartY3,arcEndX3,arcEndY3
dim arcCalcRadius
dim roughArcArray(5)
dim outterArcStart,outterArcEnd,innerArcStart,innerArcEnd
dim outterArc, innerArc, centerArcG3, centerArcG2, outterArcG3, innerArcG2
dim inputStatus,maxDepthPerPassDRO,finishStop
dim finishFlag
dim IJState
pi = 3.1415926535897932384626433832795
finishFlag = 0
'setTicker 1, GetUserLed (1200)
'------------------------------
' Get unit selection
'
if getUserLed (1200) = 1 then
units = "G20"
else
units = "G21"
end if
'-------------------------------
' Get tool entry mode selection
'
if getUserLed (1206) = 1 then
toolEntryMode = "plunge"
else
toolEntryMode = "ramp"
end if
'debug
'setUserLabel 1, "ToolEntryMode " & toolEntryMode
'-------------------------------
' Get slot orientation selection
'
if getUserLed (1208) = 1 then
slotOrientation = "straight"
else
slotOrientation = "arc"
end if
'debug
'setUserLabel 1, "slotOrientation " & slotOrientation
'-------------------------------
' Get collant selection
'
if getUserLed (1210) = 1 then
coolant = "M7"
else
coolant = "M9"
end if
'-------------------------------
' Get M1 selection
'
if getUserLed (1215) = 1 then
finishStop = "on"
else
finishStop = "off"
end if
'check IJ Mode - set it to IJ and restore it upon exit
'IJState = GetParam ("IJMode")
'Call SetParam("IJMode", 1)
'IJState = GetIJMode()
'Call SetIJMode(1)'force to incremental
IJState = GetOEMLED (73) 'incremental = 1, ABS = 0
'-------------------------------
' Get dro values
'
xyFeedRate = getOEMDRO (1100)
zFeedRate = getOEMDRO (1101)
toolDiameter = getOEMDRO (1102)
maxDepthPerPass = getOEMDRO (1103)
maxDepthPerPassDRO = getOEMDRO (1103)
TotalDepthOfCut = getOEMDRO (1104)
finishCutDepth = getOEMDRO (1105)
finishCutWidth = getOEMDRO (1107)
zRapidClearanceHeight = getOEMDRO (1108)
zInitialStartHeight = getOEMDRO (1109)
xStart = getOEMDRO (1110)
slotLength = getOEMDRO (1111)
yStart = getOEMDRO (1112)
slotWidth = getOEMDRO (1113)
spindleSpeed = getOEMDRO (1114)
slotAngle = (pi/180) * getOEMDRO (1115)
startAngle = (pi/180) * getOEMDRO (1116)
endAngle = (pi/180) * getOEMDRO (1117)
arcCenterPointX = getOEMDRO (1118)
arcCenterPointY = getOEMDRO (1119)
arcRadius = getOEMDRO (1120)
beginX = xStart
beginY = yStart
nextX = beginX + (slotLength-slotWidth)*(cos (slotAngle))
nextY = beginY + (slotLength-slotWidth)*(sin (slotAngle))
roughSlotLength = slotLength
roughslotWidth = (slotWidth - (2*finishCutWidth)) - (toolDiameter)
finishSlotLength = slotLength
finishSlotWidth = slotWidth - toolDiameter
'====================================================
'calculate number of passes required
'adjust max depth per pass to match
'
numberOfPasses = (TotalDepthOfCut-finishCutDepth)/maxDepthPerPass
if numberOfPasses - int(numberOfPasses) <> 0 then
numberOfPasses = Int(numberOfPasses)+1
maxDepthPerPass = (TotalDepthOfCut-finishCutDepth)/numberOfPasses
end if
calculatedToolDiameter = (toolDiameter/2)+(2*finishCutWidth)
radius = roughslotWidth/2
entry = radius * .9
OpenTeachFile "slot.tap"
if slotOrientation = "arc" then
setUserLabel 2, nFmt(((endAngle-startAngle)*arcRadius)+slotWidth,4)
setUserLabel 1, nFmt((sin((endAngle-startAngle)/2))*arcRadius*2,4)
else
setUserLabel 2, "---"
setUserLabel 1, "---"
end if
if slotOrientation = "arc" then
code units
code "G17 G40 G80"
code "G00 Z"& zRapidClearanceHeight
code "G90 G54"
code "S" & spindleSpeed & " M03"
code "(insure IJ mode is incremental)"
code "G91.1"
code "G00 Z" & zRapidClearanceHeight
call arcSlot(numberOfPasses,maxDepthPerPass,radius,roughSlotWidth)
else
code units
code "G17 G40 G80"
code "G00 Z"& zRapidClearanceHeight
code "G90 G54"
code "S" & spindleSpeed & " M03"
code "(insure IJ mode is incremental)"
code "G91.1"
code "G00 Z" & zRapidClearanceHeight
code "G00 X" & beginX & " Y" & beginY
code coolant
code "G00 Z" & zInitialStartHeight
code "G01 Z0 F" & zFeedRate
call straightSlot(numberOfPasses,maxDepthPerPass,calculatedToolDiameter,entry,radius,roughSlotLength,roughSlotWidth)
end if
'====================================================
'finish pass
'
if finishCutDepth >0 or finishCutWidth >0 then
finishFlag = 1
if slotOrientation = "arc" then
numberOfPasses = 1
maxDepthPerPass = TotalDepthOfCut
radius = finishSlotWidth/2
if finishStop = "on" then
if coolant = "M7" then
code "M9"
end if
code "G01 Z" & zRapidClearanceHeight
code "(M1 stop)"
code "M1"
end if
code "(finish cut)"
code coolant
code "G00 Z"& ((TotalDepthOfCut-finishCutDepth)*-1)
call arcSlot(numberOfPasses,maxDepthPerPass,radius,finishSlotWidth)
else
numberOfPasses = 1
maxDepthPerPass = TotalDepthOfCut
calculatedToolDiameter = toolDiameter/2
radius = finishSlotWidth/2
if finishStop = "on" then
if coolant = "M7" then
code "M9"
end if
code "G01 Z" & zRapidClearanceHeight
code "(M1 stop)"
code "M1"
end if
entry = radius * .9
code "(finish cut)"
code coolant
code "G00 Z"& ((TotalDepthOfCut-finishCutDepth)*-1)
call straightSlot(numberOfPasses,maxDepthPerPass,calculatedToolDiameter,entry,radius,finishSlotLength,finishSlotWidth)
end if
end if
'---
'program end
'
code "G00 Z" & zRapidClearanceHeight
if coolant = "M7" then
code "M9"
end if
if IJState = 0 then
code "(return IJ mode to absolute)"
code "G90.1"
end if
code "M30"
closeTeachFile
call loadTeachFile
'==============================================================
'
'end sub 'main
'main
'******************* ARCSLOT *****************
'
sub arcSlot(passCount,depthPerPass,calcRadius,arcSlotWidth)
arcStartX1 = (arcCenterPointX + arcRadius) *(cos(startAngle))
arcStartX1 = nFmt(arcStartX1,4)
arcStartY1 = (arcCenterPointY + arcRadius) *(sin(startAngle))
arcStartY1 = nFmt(arcStartY1,4)
arcEndX1 = arcRadius*(cos (endAngle))
arcEndX1 = nFmt(arcEndX1,4)
arcEndY1 = arcRadius*(sin (endAngle))
arcEndY1 = nFmt(arcEndY1,4)
centerPointX= arcCenterPointX - (arcCenterPointX + arcStartX1)
centerPointY = arcCenterPointY - (arcCenterPointY + arcStartY1)
centerArcG3 = "G03 X" & nFmt(arcEndX1,4) & " Y" & nFmt(arcEndY1,4) & " I" & nFmt(centerPointX,4) & " J" & nFmt(centerPointY,4) & " F" & xyFeedRate
centerPointX= arcCenterPointX - (arcCenterPointX + arcEndX1)
centerPointY = arcCenterPointY - (arcCenterPointY + arcEndY1)
centerArcG2 = "G02 X" & nFmt(arcStartX1,4) & " Y" & nFmt(arcStartY1,4) & " I" & nFmt(centerPointX,4) & " J" & nFmt(centerPointY,4) & " F" & xyFeedRate
'******************* define slot outter contour *****************
'
arcStartX2 = (arcRadius + arcSlotWidth/2 + arcCenterPointX ) *(Cos (startAngle))
arcStartY2 = (arcRadius + arcSlotWidth/2 + arcCenterPointY) *(sin (startAngle))
arcEndX2 = (arcRadius + arcSlotWidth/2)*(Cos (endAngle))
arcEndY2 = (arcRadius + arcSlotWidth/2)*(sin (endAngle))
centerPointX= arcCenterPointX - (arcCenterPointX + arcStartX2)
centerPointY = arcCenterPointY - (arcCenterPointY + arcStartY2)
outterArcG3 = "G03 X" & nFmt(arcEndX2,4) & " Y" & nFmt(arcEndY2,4) & " I" & nFmt(centerPointX,4) & " J" & nFmt(centerPointY,4) & " F" & xyFeedRate
outterArcStart = "X" & nFmt(arcStartX2,4) & " Y" & nFmt(arcStartY2,4)
outterArcEnd = "X" & nFmt(arcEndX2,4) & " Y" & nFmt(arcEndY2,4)
'******************* define slot inner contour *****************
'
arcStartX3 = (arcRadius - arcSlotWidth/2 + arcCenterPointX ) *(Cos (startAngle))
arcStartY3 = (arcRadius - arcSlotWidth/2 + arcCenterPointY) *(sin (startAngle))
arcEndX3 = (arcRadius - arcSlotWidth/2)*(Cos (endAngle))
arcEndY3 = (arcRadius - arcSlotWidth/2)*(sin (endAngle))
centerPointX= arcCenterPointX - (arcCenterPointX + arcEndX3)
centerPointY = arcCenterPointY - (arcCenterPointY + arcEndY3)
innerArcG2 = "G02 X" & nFmt(arcStartX3,4) & " Y" & nFmt(arcStartY3,4) & " I" & nFmt(centerPointX,4) & " J" & nFmt(centerPointY,4) & " F" & xyFeedRate
'flipped end start for G2
innerArcEnd = "X" & nFmt(arcStartX3,4) & " Y" & nFmt(arcStartY3,4)
innerArcStart = "X" & nFmt(arcEndX3,4) & " Y" & nFmt(arcEndY3,4)
'******************* set up *****************
'
'numberOfPasses = (totalDepthOfCut-finishCutDepth)/maxDepthPerPass
'if numberOfPasses - int(numberOfPasses) <> 0 then
'numberOfPasses = int(numberOfPasses)+1
'maxDepthPerPass = (totalDepthOfCut-finishCutDepth)/numberOfPasses
'end if
'******************* Start code *****************
'
inputStatus = verifyInput()
if inputStatus = "failed" then
exit sub
end if
if finishFlag = 0 then
code "G00 X" & nFmt(arcStartX1,4) & " Y" & nFmt(arcStartY1,4)
code coolant
code "G00 Z" & zInitialStartHeight
code "G01 Z0 F" & zFeedRate
code "(zig-zag - center cut)"
end if
if toolEntryMode = "ramp" then
for i = 1 to passCount
code centerArcG3 &" Z" & nFmt(((depthPerPass*-1)*i),4)
code centerArcG2
next
code "(clean up last slope)"
code centerArcG3
code centerArcG2
else
code "(plunge - center cut)"
for i = 1 to passCount
code "G01 Z" & nFmt(((depthPerPass*-1)*i),4) & " F" & zFeedRate
'if odd
'
if i mod 2 >0 then
code centerArcG3
else
code centerArcG2
end if
next
' position to correct end
if i mod 2 >0 then
else
code centerArcG2
end if
end if
code "G00 Z0"
code "(lead in)"
code "G03 " & outterArcStart & "R"&calcRadius/2
if toolEntryMode = "ramp" then
for i = 1 to passCount
code "(outter arc)"
code "G01 X" & nFmt(arcStartX2,4) & " Y" & nFmt(arcStartY2,4)
code outterArcG3 &" Z" & nFmt(((depthPerPass*-1)*i),4)
code "G03 " & innerArcStart & "R"&calcRadius
code "(inner arc)"
code innerArcG2
code "G03 " & outterArcStart & "R"&calcRadius
next
code "(smooth last ramp)"
code "G01 X" & nFmt(arcStartX2,4) & " Y" & nFmt(arcStartY2,4)
code outterArcG3
code "G03 " & innerArcStart & "R"&calcRadius
code "(inner arc)"
code innerArcG2
code "G03 " & outterArcStart & "R"&calcRadius
else
for i = 1 to passCount
code "G01 Z" & nFmt(((depthPerPass*-1)*i),4)
code "(outter arc)"
code "G01 X" & nFmt(arcStartX2,4) & " Y" & nFmt(arcStartY2,4)
code outterArcG3
code "G03 " & innerArcStart & "R"&calcRadius
code "(inner arc)"
code innerArcG2
code "G03 " & outterArcStart & "R"&calcRadius
next
end if
code "(lead out)"
code "G03 X" & nFmt(arcStartX1,4) & " Y" & nFmt(arcStartY1,4) & "R"&calcRadius/2
end sub
'==============================================================
'
sub straightSlot(passCount,depthPerPass,calcToolDiameter,leadInLength,calcRadius,codeSlotLength,codeSlotWidth)
inputStatus = verifyInput()
if inputStatus = "failed" then
exit sub
end if
if toolEntryMode = "ramp" then
code "(ramp - center cut)"
for i = 1 to passCount
code "G01 X" & nFmt(beginX,4) & " Y" & Roun(beginY) & " F" & xyFeedRate
code "G01 X" & nFmt(nextX,4) & " Y" & nFmt(nextY,4) & " F" & xyFeedRate &" Z" & nFmt(((depthPerPass*-1)*i),4)
next
code "G01 X" & nFmt(beginX,4) & " Y" & nFmt(beginY ,4) & " F" & xyFeedRate
else
code "(plunge - center cut)"
for i = 1 to passCount
code "G01 Z" & nFmt(((depthPerPass*-1)*i)) & " F" & zFeedRate
'if odd
'
if i mod 2 >0 then
code "G01 X" & nFmt(nextX,4) & " Y" & nFmt(nextY,4 ) & " F" & xyFeedRate
else
code "G01 X" & nFmt(beginX,4) & " Y" & nFmt(beginY,4) & " F" & xyFeedRate
end if
Next
' position to correct end
if i mod 2 >0 then
else
code "G01 X" & nFmt(beginX,4) & " Y" & nFmt(beginY,4) & " F" & xyFeedRate
end if
end if
code "G00 Z0"
code "(lead in)"
code "G01 X" & nFmt(nextX + (leadInLength*cos(slotAngle))-(calcRadius*.05*sin(slotAngle)),4) & " Y" & nFmt(nextY+(leadInLength*sin(slotAngle))+(calcRadius*.05*cos(slotAngle)),4) & " F" & xyFeedRate
code "G03 X"& nFmt(nextX -calcRadius*sin(slotAngle),4)& " Y" & nFmt(nextY + calcRadius*cos(slotAngle),4) & " R"& nFmt(calcRadius-(calcRadius*.05) ,4)& " F" & xyFeedRate
if toolEntryMode = "ramp" then
code "(ramp)"
for i = 1 to passCount
code "G01 X" & nFmt(beginX -calcRadius*sin(slotAngle),4)& " Y" & nFmt(beginY + calcRadius*cos(slotAngle),4)&" Z" & nFmt(((depthPerPass*-1)*i),4) & " F" & xyFeedRate
code "G03 X" & nFmt(beginX +calcRadius*sin(slotAngle),4) &" Y" & nFmt(beginY - calcRadius*cos(slotAngle),4) & " R"& calcRadius
code "G01 X" & nFmt(nextX +calcRadius*sin(slotAngle),4) &" Y" & nFmt(nextY - calcRadius*cos(slotAngle),4)
code "G03 X" & nFmt(nextX -calcRadius*sin(slotAngle),4)& " Y" & nFmt(nextY + calcRadius*cos(slotAngle),4)& " R"& calcRadius
next
'----
'clean last sloped path so bottom is smooth and flat
code "(smooth last ramp)"
code "G01 X" & nFmt(beginX -calcRadius*sin(slotAngle),4)& " Y" & nFmt(beginY + calcRadius*cos(slotAngle),4)& " F" & xyFeedRate
code "G03 X" & nFmt(beginX +calcRadius*sin(slotAngle),4) &" Y" & nFmt(beginY - calcRadius*cos(slotAngle),4) & " R"& calcRadius
code "G01 X" & nFmt(nextX +calcRadius*sin(slotAngle),4) &" Y" & nFmt(nextY - calcRadius*cos(slotAngle),4)
code "G03 X" & nFmt(nextX -calcRadius*sin(slotAngle),4) & " Y" & nFmt(nextY + calcRadius*cos(slotAngle),4)& " R"& calcRadius
else
code "(plunge)"
for i = 1 to passCount
code "G01 Z" & nFmt(((depthPerPass*-1)*i),4) & " F" & zFeedRate
code "G01 X" & nFmt(beginX -calcRadius*sin(slotAngle),4)& " Y" & nFmt(beginY + calcRadius*cos(slotAngle),4)&" F" & xyFeedRate
code "G03 X" & nFmt(beginX +calcRadius*sin(slotAngle),4) &" Y" & nFmt(beginY - calcRadius*cos(slotAngle),4) & " R"& calcRadius
code "G01 X" & nFmt(nextX +calcRadius*sin(slotAngle),4) &" Y" & nFmt(nextY - calcRadius*cos(slotAngle),4)
code "G03 X" & nFmt(nextX -calcRadius*sin(slotAngle),4)& " Y" & nFmt(nextY + calcRadius*cos(slotAngle),4)& " R"& calcRadius
next
end if
'---
'exit path
'
code "(lead out)"
code "G03 X"& nFmt(nextX- calcRadius*Cos(slotAngle),4) & " Y"& nFmt(nextY-calcRadius*Sin(slotAngle),4) & " R" & calcRadius-(calcRadius*.05)
end sub
'==============================================================
'
function verifyInput()
'-------------------------------
' Verfify input values
'
setTicker 1, ""
'setUserLabel 1, abs(slotLength)-(finishCutWidth*2)
if SlotLength <= toolDiameter then
Call errors("Tool Diameter is larger than slot length")
verifyInput = "failed"
exit function
end if
if toolDiameter >= slotWidth-(finishCutWidth*2)then
Call errors("Tool Diameter is too large for slot and finish pass ")
verifyInput = "failed"
exit function
end if
if (toolDiameter*3)< slotWidth+(finishCutWidth*2) then
Call errors("Tool Diameter is too small to cut slot in 3 passes")
verifyInput = "failed"
exit function
end if
if zRapidClearanceHeight <= 0 then
Call errors("Z rapid clearance height must be greater than 0")
verifyInput = "failed"
exit function
end if
if TotalDepthOfCut <= 0 then
Call errors("Depth of cut is entered as a positive value and must be greater than 0")
verifyInput = "failed"
exit function
end if
if zRapidClearanceHeight < 0 then
Call errors("Z initial move safe height is entered as a positive value and must be 0 or greater")
verifyInput = "failed"
exit function
end if
if zInitialStartHeight < 0 then
Call errors("Z initial start height is entered as a positive value and must be 0 or greater")
verifyInput = "failed"
exit function
end if
if slotWidth > slotLength/2 then
Call errors("Slot length must be twice as long as slot width")
verifyInput = "failed"
exit function
end if
if finishCutWidth > toolDiameter*.1 then
Call errors("Finsh cut with must <= 10% of tool diameter")
verifyInput = "failed"
exit function
end if
if finishCutDepth > maxDepthPerPassDRO then
Call errors("Finsh cut depth must <= maxium depth per pass")
verifyInput = "failed"
exit function
end if
verifyInput = "passed"
end function