Code:
-- Minimum Post Processor for Bandit COntroller
--
-- Modified 8/19/2007
-- Chris Haugen
function init()
setcommentchars ("()", "[]") --make sure ( and ) characters do not appear in system text
--CH English/metric taken out because scale is a switch on the Front Panel.
text ("N001&nG90n")
bigarcs = 1 --stitch arc segments together
minarcsize = 0.1 --arcs smaller than this are converted to moves
end
function newline()
line = line + 10
end
function finish()
text("n")
modalnumber ("Z", (endz + tooloffset) * scale, "0.0000")
text ("M2n")
endz = safez
rapid()
end
function rapid()
if (feedrate ~= feedrateval) then
text ("F")
number (feedrate * scale, "0")
text (".n")
feedrateval = feedrate
end
modalnumber ("/X", endx * scale, "0.0000")
modalnumber ("/Y", endy * scale, "0.0000")
text("n")
modalnumber ("Z", (endz + tooloffset) * scale, "0.0000")
eol()
end
function move()
if (feedrate ~= feedrateval) then
text ("F")
number (feedrate * scale, "0")
text (".n")
feedrateval = feedrate
end
-- text("n")
modalnumber ("X", endx * scale, "0.0000")
modalnumber ("Y", endy * scale, "0.0000")
modalnumber ("Z", (endz + tooloffset) * scale, "0.0000")
eol()
end
function arc()
--Here is where we need to break an arc into quadrants
--arccenterx & y is it's physical location
--I'm not allowing Z arcs since my machine can't do it
--Quadrants 1(X+Y+),2(X+Y-),3(X-Y-),4(X-Y+)
modalnumber ("Z", (endz + tooloffset) * scale, "0.0000")
text("n")
arc_currentx = round3(currentx - arccentrex,4)
arc_currenty = round3(currenty - arccentrey,4)
arc_endx = round3(endx - arccentrex,4)
arc_endy = round3(endy - arccentrey,4)
arc_distancetocenter = math.sqrt((arc_currentx * arc_currentx) + (arc_currenty * arc_currenty))
current_quadrant = ""
finish_quadrant = ""
if (arc_currentx >= 0 and arc_currenty > 0 and arcangle > 0) then current_quadrant = "1";end
if (arc_currentx > 0 and arc_currenty >= 0 and arcangle < 0) then current_quadrant = "1";end
if (arc_currentx > 0 and arc_currenty <= 0 and arcangle > 0) then current_quadrant = "2";end
if (arc_currentx >= 0 and arc_currenty < 0 and arcangle < 0) then current_quadrant = "2";end
if (arc_currentx <= 0 and arc_currenty < 0 and arcangle > 0) then current_quadrant = "3";end
if (arc_currentx < 0 and arc_currenty <= 0 and arcangle < 0) then current_quadrant = "3";end
if (arc_currentx < 0 and arc_currenty >= 0 and arcangle > 0) then current_quadrant = "4";end
if (arc_currentx <= 0 and arc_currenty > 0 and arcangle < 0) then current_quadrant = "4";end
if (arc_endx >= 0 and arc_endy > 0 and arcangle<0) then finish_quadrant = "1";end
if (arc_endx > 0 and arc_endy >= 0 and arcangle>0) then finish_quadrant = "1";end
if (arc_endx > 0 and arc_endy <= 0 and arcangle<0) then finish_quadrant = "2";end
if (arc_endx >= 0 and arc_endy < 0 and arcangle>0) then finish_quadrant = "2";end
if (arc_endx <= 0 and arc_endy < 0 and arcangle<0) then finish_quadrant = "3";end
if (arc_endx < 0 and arc_endy <= 0 and arcangle>0) then finish_quadrant = "3";end
if (arc_endx < 0 and arc_endy >= 0 and arcangle<0) then finish_quadrant = "4";end
if (arc_endx <= 0 and arc_endy > 0 and arcangle>0) then finish_quadrant = "4";end
if (current_quadrant == finish_quadrant) then
--if the move starts and ends in the same quadrant
text("X"); number ( endx * scale, "0.0000")
text("Y"); number (endy * scale, "0.0000")
text("/X"); number ((arccentrex) * scale, "0.0000")
text("/Y"); number ((arccentrey) * scale, "0.0000")
text("n")
else
while (current_quadrant ~= finish_quadrant) do
--finish point is not in the current quadrant
if(arcangle <0) then
if (current_quadrant == "1") then
new_current_quadrant = "4"
currentxval = 0
currentyval = arc_distancetocenter
end
if (current_quadrant == "2") then
new_current_quadrant = "1"
currentxval = arc_distancetocenter
currentyval = 0
end
if (current_quadrant == "3") then
new_current_quadrant = "2"
currentxval = 0
currentyval = -arc_distancetocenter
end
if (current_quadrant == "4") then
new_current_quadrant = "3"
currentxval = -arc_distancetocenter
currentyval = 0
end
current_quadrant = new_current_quadrant
else
if (current_quadrant == "4") then
new_current_quadrant = "1"
currentxval = 0
currentyval = arc_distancetocenter
end
if (current_quadrant == "3") then
new_current_quadrant = "4"
currentxval = -arc_distancetocenter
currentyval = 0
end
if (current_quadrant == "2") then
new_current_quadrant = "3"
currentxval = 0
currentyval = -arc_distancetocenter
end
if (current_quadrant == "1") then
new_current_quadrant = "2"
currentxval = arc_distancetocenter
currentyval = 0
end
current_quadrant = new_current_quadrant
end
currentx = currentxval
currenty = currentyval
--if (round3(arc_currentx,1) == round3(arc_endx,1)) then
-- text ("*******X=Xn");
--end
text("X"); number ((arccentrex+currentx) * scale, "0.0000")
text("Y"); number ((arccentrey+currenty) * scale, "0.0000")
text("/X"); number ((arccentrex) * scale, "0.0000")
text("/Y"); number ((arccentrey) * scale, "0.0000")
text ("n")
end
--we have moved into the finish quadrant
text("X"); number (endx * scale, "0.0000")
text("Y"); number (endy * scale, "0.0000")
text("/X"); number ((arccentrex) * scale, "0.0000")
text("/Y"); number ((arccentrey) * scale, "0.0000")
text("n")
end
eol()
end
function round3(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
function spindlecw()
text (" M03")
eol()
end
function spindleccw()
text (" M04")
eol()
end
function spindleoff()
text (" M05n")
end
function newprocess()
if (plungerate <= 0) then
warning("WARNING: Plunge rate is zero")
end
if (feedrate <= 0) then
warning("WARNING: Feed rate is zero")
end
end
function toolchange()
--text (" M6 T")
--number (tool, "0")
eol()
end
function spindlechanged()
--if (spindlespeed <= 0) then
-- warning("WARNING: Spindle speed is zero")
--end
end
function newpart()
end
function floodon()
text(" M08n")
end
function miston()
text(" M07n")
end
function coolantoff()
text(" M09n")
end
function drill()
--Bandit Drill Cycle G83
-- It will Move down to "DrillStart"
-- Then it will Peck down "peckdepth"
-- And rapid retract "retract"
-- Until it reaches full depth
-- then return to where it started
rapid()
modalnumber ("Z", (endz+drillstart) * scale, "0.000")
text ("n")
text ("/Z")
number (drillz * scale, "0.000")
text ("Z")
number (peckdepth*scale,"0.000")
text ("/Z")
number (retract*scale,"0.000")
text ("G83n")
nonmodalnumber ("Z", (endz+drillstart) * scale, "0.000")
text ("n")
end