--************************************************ --*** Set these values up to suit your machine *** --************************************************ --rotary axis. Normally this would be "A" rotaryAxis = "A" --Number of units for one full revolution of the rotary axis --Note: In Mach3 the axis should be defined as linear, not rotary! unitsPerRev=360 --************************************************ --*** End of settings *** --************************************************ function OnAbout(event) ctrl = event:GetTextCtrl() ctrl:AppendText("Post for rotary-plasma plugin and Pumotix\n") ctrl:AppendText("\n") ctrl:AppendText("Modal G-codes and coordinates\n") ctrl:AppendText("Comments enclosed with ( and )\n") ctrl:AppendText("M03/M05 turn the torch on/off\n") ctrl:AppendText("Incremental IJ - set in mach2\n") end function OnInit() offX = 0 offY = 0 offZ = 0 post.SetCommentChars ("()", "[]") --make sure ( and ) characters do not appear in system text post.Text (" (Post processor: ", postName, ")\n") post.Text (" (Date: ", date, ")\n") if(scale == metric) then post.Text (" G21 (Units: Metric)\n") --metric mode else post.Text (" G20 (Units: Inches)\n") --inch mode end post.Text (" G90 G91.1 G40\n F1\n M90\n M92\n") post.Text (" M101\n") --post.Text (" G00") --post.ModalNumber (" Z", safeZ * scale, "0.0000") post.Eol() bigarcs = 1 --stitch arc segments together minArcSize = 0.05 --arcs smaller than this are converted to moves currentZAxis = "Z" dist = 9999999 lastz = 0 curr_x = 0 curr_y = 0 end function OnNewLine() post.Text ("N") post.Number (lineNumber, "0000") lineNumber = lineNumber + 10 end function OnFinish() endZ = safeZ OnRapid() endX = 0 endY = 0 offX = 0 offY = 0 offZ = 0 OnRapid() post.Text (" M05\n M30\n") end function OnRapid() local len = math.hypot((endX + offX)-curr_x , (endY + offY)-curr_y) dist = dist + len post.ModalText (" G00") post.ModalNumber (" X", (endX + offX) * scale, "0.0000") post.ModalNumber (" Y", (endY + offY) * scale, "0.0000") post.ModalNumber (" " .. currentZAxis, (endZ + offZ) * scale, "0.0000") post.ModalNumber (" " .. rotaryAxis, endA, "0.0000") post.Eol() curr_x = endX curr_y = endY end function OnMove() local len = math.hypot(endX - curr_x , endY - curr_y) dist = dist + len post.ModalText (" G01") post.ModalNumber (" X", (endX + offX) * scale, "0.0000") post.ModalNumber (" Y", (endY + offY) * scale, "0.0000") post.ModalNumber (" " .. currentZAxis, (endZ + offZ) * scale, "0.0000") post.ModalNumber (" " .. rotaryAxis, endA, "0.0000") post.ModalNumber (" F", feedRate * scale, "0.0###") post.Eol() curr_x = endX curr_y = endY end function OnArc() --local radius = math.hypot(curr_x - arcCentreX, curr_y - arcCentreY) local radius = math.hypot(endX - arcCentreX, endY - arcCentreY) dist = dist + radius * math.abs(arcAngle) if(arcAngle <0) then post.ModalText (" G03") else post.ModalText (" G02") end post.ModalNumber (" X", (endX + offX) * scale, "0.0000") post.ModalNumber (" Y", (endY + offY) * scale, "0.0000") if(offZ) then post.ModalNumber (" " .. currentZAxis, (endZ + offZ) * scale, "0.0000") end post.Text (" I") post.Number ((arcCentreX - curr_x) * scale, "0.0000") post.Text (" J") post.Number ((arcCentreY - curr_y) * scale, "0.0000") -- post.Text (" R") -- post.Number (radius * scale, "0.0000") post.ModalNumber (" " .. rotaryAxis, endA, "0.0000") post.ModalNumber (" F", feedRate * scale, "0.0###") post.Eol() curr_x = endX curr_y = endY end function norma(x, y) return math.sqrt(x*x+y*y) end function dot_product(x1, y1, x2, y2) return x1*x2+y1*y2 end function OnPenDown() sc.QueryDll(qryRAPIDY, endY, dllId) local matZ = sc.QueryDll(qryCHKEND, endY, dllId) post.Text(" M100 P") post.Number (matZ * scale, "0.0000") post.Eol() post.Text (" G00 Z") post.Number ((matZ + pierceHeight) * scale, "0.0000") post.Eol() post.Text(" M03\n") if (pierceDelay > 0.001) then post.Text (" G04 P") post.Number (pierceDelay,"0.###") post.Eol() end post.Text (" G00 Z") post.Number ((matZ + cutHeight) * scale, "0.0000") post.Text (" F") post.Number (feedRate * scale, "0.###") post.Eol() post.CancelModalNumbers() post.ModalText ("") end function OnPenUp() post.Text (" M05\n") --post.Text (" G00") --post.ModalNumber (" Z", safeZ * scale, "0.0000") post.Eol() post.CancelModalNumbers() post.ModalText ("") end function OnNewOperation() post.Text (" (Operation: ", operationName, ")\n") end function OnNewPart() post.Text(" (Part: ",partName,")\n"); end package.path = sc.Globals:Get().thisDir .. "/plugins/RotaryPlasma/?.lua" require("rotaryhelper")