Author Topic: G83 to grbl Conversion  (Read 11007 times)

Offline deltatango

  • Ewok
  • *
  • Posts: 2
    • View Profile
G83 to grbl Conversion
« on: November 16, 2016, 05:13:07 am »
This weekend I needed to peck drill several holes with my Xcarve. Since grbl cannot interpret G83 peck instructions I wrote a quick script that converts the G83 to grlbl accepted commands. I successfully used it with my Xcarve to drill >50 0.09" holes into 5/8 Aluminum. I've placed it on github https://github.com/deltatango2/G83_to_grbl_Peck_Drill_Converter, please pass along any comments or suggestions.

I suggest using something like OpenSCAM to simulate your code before trying it on your machine. 

I plan to add this as a post processing step to my CamBam output so it's all taken care of automatically.  I hope it helps other CamBam + grbl users.

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 9079
    • View Profile
Re: G83 to grbl Conversion
« Reply #1 on: November 16, 2016, 21:45:39 pm »
DT,
Around here, when WE write something useful to other users, we post it here, rather than on some outside site.  And when we add it into a post-processor or post-build processor, we also post that here.

Thanks,
LLoyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline deltatango

  • Ewok
  • *
  • Posts: 2
    • View Profile
Re: G83 to grbl Conversion
« Reply #2 on: November 17, 2016, 02:38:54 am »
Lloyd,  thanks for the info.  I'm used to github being a defacto code repo so I posted there first.  Happy to add code as seen below.  I didn't see a method to upload file, so I'm not sure what the preferred method for code sharing is. Its short so I hope a direct paste is OK.

The python script is below. It uses tkinter to provide a gui for file selection.  If Tkinter isn't available hardcode the path to the NC you want to convert into the variable "file_path" and comment out all code above.

Code: [Select]
"""
Created on Sun Nov 13 12:54:25 2016

@author: DTalaiver

This script converts G83 instructions to grbl accepted G-code.
"""

#drill parser

import Tkinter as tk
import tkFileDialog

root = tk.Tk()
root.withdraw()
root.deiconify()
root.lift()
root.focus_force()
root.withdraw()
file_path = tkFileDialog.askopenfilename(parent=root)

outfile = open(file_path[:-3]+'4grbl.nc', 'w')
retractFeed = 'F20'
clearHeight = '0.25'
with open(file_path) as f:
    for line in f:
        content = line
        elements = content.split(" ")
        if elements[0] != "G83": #if its not G83 just pass it out
            outfile.write(content)
        else:
            #extract elements from command
            for q in range(0,len(elements)):
                if "X" in elements[q]:
                    xCmd = elements[q]
                elif "Y" in elements[q]:
                    yCmd = elements[q]
                elif "Z" in elements[q]:
                    bottom = float(elements[q][1:])
                elif "Q" in elements[q]:
                    increment = float(elements[q][1:])
                elif "R" in elements[q]:
                    retract = (elements[q][1:])
                elif "F" in elements[q]:
                    plunge = elements[q]
            #begin pecking
            #go to position
            outfile.write('G0'+xCmd+yCmd+"\n")
            curDepth=0
            outfile.write('G0Z0'+"\n")
            while (curDepth>bottom):
                curDepth=curDepth-increment
                if curDepth<=bottom:
                    curDepth=bottom
                #plunge
                outfile.write('G1'+'Z'+str(curDepth)+plunge)
                #retract
                outfile.write('G1'+'Z'+retract+retractFeed+"\n")
            #pecking done
            outfile.write('G0Z'+clearHeight+"\n")
          
                
        


outfile.close()
« Last Edit: November 17, 2016, 02:42:13 am by deltatango »

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5329
  • Made in England
    • View Profile
Re: G83 to grbl Conversion
« Reply #3 on: November 17, 2016, 07:16:07 am »
 I didn't see a method to upload file, so I'm not sure what the preferred method for code sharing is. Its short so I hope a direct paste is OK.


That's fine for something short, use Zip files for anything larger, attach as shown in picture.
Filmed in Supermarionation

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 9079
    • View Profile
Re: G83 to grbl Conversion
« Reply #4 on: November 17, 2016, 10:36:02 am »
DT,
When you get ready to "fully integrate" that, we'll guide you through implementing it as a post-build process (if you haven't already figured that out).

That way, the conversion will be entirely automatic, and transparent to the operator.

LLoyd
"Pyro for Fun and Profit for More Than Fifty Years"