Forum Replies Created
-
AuthorPosts
-
moorejl57Member
Actually that was my first Python script ever after reading a book on it for several hours, so I don’t have any GUI experience and there is a bug at the end of the scrip I have since fixed. All I was trying to accomplish was to expand the drill routines from CamBam into g-code that TinyG could handle and I wanted to try something different than Pearl. I won’t likely be writing much g-code by hand since I am happy with CamBam.
I am not much of a machinist, I have a Sherline mill and lathe and took one machining class at a junior college about ten years ago. I am actually a software engineer and this year I mentored a FIRST robotics team on electrical since they seemed to be having reliability issues with their robots the last four years. This re sparked my interest in CNC since they could really use some help in this area as well. They have an old Sharp knee mill with an Anilam controller on it that is not seeing much use.
I haven’t purchased the TinyG card yet for my pending Sherline conversion since I am still doing my homework. The only thing holding me back is the stepper motor drivers used on the board. I read a blog (dr-iguana.com) on stepper drivers and then I have started digging into a microchip application note on driver design using a dsp processor. I am still chewing on that (very technical) and now believe I might design my own driver board using their techniques, but make it TinyG compatible.
Thanks,
Jamiemoorejl57MemberSeems the code tag didn’t keep the formatting…
moorejl57MemberHere is a Python33 script I have played with for massaging CamBam files with G81 and G83 blocks. I am new to Python, so you may want to edit it to your liking 🙂
# expands canned drill g-codesimport re
import sysdef ExtractParameters(block, parms):
"""extracts drill parameters from g-code block"""
m = re.match(".*X([-]?\d+.\d+)", block)
if m:
parms["x"] = float(m.group(1))
m = re.match(".*Y([-]?\d+.\d+)", block)
if m:
parms["y"] = float(m.group(1))
m = re.match(".*Z([-]?\d+.\d+)", block)
if m:
parms["z"] = float(m.group(1))
m = re.match(".*Q([-]?\d+.\d+)", block)
if m:
parms["q"] = float(m.group(1))
m = re.match(".*R([-]?\d+.\d+)", block)
if m:
parms["r"] = float(m.group(1))
m = re.match(".*F([-]?\d+.\d+)", block)
if m:
parms["f"] = float(m.group(1))def G81(parms, outFile):
"""expands canned drill g-code G81, standard drill"""
outFile.write("G0 X{0} y{1}\n".format(parms["x"], parms["y"]))
outFile.write("G0 Z0.01\n")
outFile.write("G1 Z{0} F{1}\n".format(parms["z"], parms["f"]))
outFile.write("G0 Z{0}\n".format(parms["r"]))def G83(parms, outFile):
"""expands canned drill g-code G83, peck drill"""
outFile.write("G0 X{0} Y{1}\n".format(parms["x"], parms["y"]))
peckCount = int(abs(parms["z"]) // parms["q"])
if peckCount < 1: # drill depth less than peck depth outFile.write("G0 Z0.01\n") outFile.write("G1 Z{0} F{1}\n".format(parms["z"], parms["f"])) outFile.write("G0 Z{0}\n".format(parms["r"])) else: peckDepth = 0.0 while (peckCount > 0):
rapidDepth = peckDepth + 0.01
peckDepth -= parms["q"]
outFile.write("G0 Z{0}\n".format(round(rapidDepth, 5)))
outFile.write("G1 Z{0} F{1}\n".format(round(peckDepth, 5), parms["f"]))
outFile.write("G0 Z{0}\n".format(parms["r"]))
peckCount -= 1
finalDepth = abs(parms["z"]) % parms["q"]
if finalDepth > 0.0:
rapidDepth = peckDepth + 0.01;
outFile.write("G0 Z{0}\n".format(round(rapidDepth, 5)))
outFile.write("G1 Z{0} F{1}\n".format(parms["z"], parms["f"]))
outFile.write("G0 Z{0}\n".format(parms["r"]))def ProcessFile(parms, inFile, outFile):
for block in inFile:
if block.find("G98") != -1:
outFile.write("({0})\n".format(block[:-1]))
elif block.find("G81") != -1:
outFile.write("({0})\n".format(block[:-1]))
ExtractParameters(block, parms)
G81(parms, outFile)
elif block.find("G83") != -1:
outFile.write("({0})\n".format(block[:-1]))
ExtractParameters(block,drillParms)
G83(parms, outFile)
elif block.find("G80") != -1:
outFile.write("({0})\n".format(block[:-1]))
else:
outFile.write(block)
outFile.close()
inFile.close()if sys.argv == 3:
inFile = open(sys.argv[1], "r")
outFile = open(sys.argv[2], "w")
else:
fileName = input("Enter NC input file name: ")
inFile = open(fileName, "r")
fileName = input("Enter NC output file name: ")
outFile = open(fileName, "w")drillParms = {"x":0.0, "y":0.0, "z":0.0, "q":0.0, "r":0.0, "f":0.0}
ProcessFile(drillParms, inFile, outFile)
-
AuthorPosts