Commit 4dbf9e2a authored by ajfoul's avatar ajfoul

Modified to output LMN Marlin friendly gcode

A few changes to gcode generation:
+ M3 commands include laser intensity (S[0-100])
+ G00 (move w/laser off) get feedrate independent of cut moves
+ G01-03 (cut moves) get feedrate independent of G00 rate
+ Option to insert home all (G28) before starting
+ All above get fields/toggle in dialog
- Removed header and footer in out put (was causing me issues)
+/- more appropriate comments
parent e4806c6e
......@@ -38,7 +38,11 @@ This script is a fork of Gcodetools v1.2 by Nick Drobchenko. It is currently mai
<param name="filename" type="string" _gui-text="File name: ">output.ngc</param>
<param name="directory" type="string" _gui-text="Directory: "></param>
<_param name="help" type="description">(blank is your desktop)</_param>
<param name="feed" type="float" precision="4" min="0" max="1000" _gui-text="Feed rate (unit/min):">4.0</param>
<param name="feed" type="int" min="0" max="10000" _gui-text="Cut Feedrate:">60</param>
<param name="Mfeed" type="int" min="0" max="10000" _gui-text="Move Feedrate:">1000</param>
<param name="laser" type="int" min="0" max="100" _gui-text="Laser Intensity (0-100):">10</param>
<param name="homebefore" type="boolean" _gui-text="HOMEALL (G28) Before:">true</param>
<param name="Xscale" type="float" precision="4" min="-1000" max="1000" _gui-text="Scale along X axis:">1</param>
<param name="Yscale" type="float" precision="4" min="-1000" max="1000" _gui-text="Scale along Y axis:">1</param>
<param name="double_sided_cutting" type="boolean" _gui-text="Double-sided cutting:">false</param>
......
......@@ -96,12 +96,12 @@ VERSION = "1.30"
STRAIGHT_TOLERANCE = 0.0001
STRAIGHT_DISTANCE_TOLERANCE = 0.0001
LASER_ON = "M3\n" # Peter - LASER ON MCODE
LASER_ON = "M3" # Peter - LASER ON MCODE
LASER_OFF = "M5\n" # Peter - LASER OFF MCODE
TOOL_CHANGE = "T%02d (select tool)\nM6 (tool change)\n\n"
HEADER_TEXT = '%%\n(Generated by thlaser v%s inkscape plugin)\n(based on code from gcode_tools)\n\nG96 S90 (set spindle speed so M3/M5 will work)\n' % VERSION
FOOTER_TEXT = "%s\nM2 (end)\n%%" % LASER_OFF
HEADER_TEXT = ""
FOOTER_TEXT = ""
BIARC_STYLE = {
'biarc0': simplestyle.formatStyle({ 'stroke': '#88f', 'fill': 'none', 'stroke-width':'1' }),
......@@ -115,7 +115,8 @@ SVG_GROUP_TAG = inkex.addNS("g", "svg")
SVG_PATH_TAG = inkex.addNS('path','svg')
SVG_LABEL_TAG = inkex.addNS("label", "inkscape")
GCODE_EXTENSION = ".ngc"
GCODE_EXTENSION = ".g" # changed to be Marlin friendly (ajf)
options = {}
......@@ -426,7 +427,12 @@ class Gcode_tools(inkex.Effect):
self.OptionParser.add_option("-v", "--Yscale", action="store", type="float", dest="Yscale", default="1.0", help="Scale factor Y")
self.OptionParser.add_option("-x", "--Xoffset", action="store", type="float", dest="Xoffset", default="0.0", help="Offset along X")
self.OptionParser.add_option("-y", "--Yoffset", action="store", type="float", dest="Yoffset", default="0.0", help="Offset along Y")
self.OptionParser.add_option("-p", "--feed", action="store", type="float", dest="feed", default="4.0", help="Feed rate in unit/min")
# added move (laser off) feedrate and laser intensity; made all int rather than float - (ajf)
self.OptionParser.add_option("-p", "--feed", action="store", type="int", dest="feed", default="60", help="Cut Feed rate in unit/min")
self.OptionParser.add_option("-m", "--Mfeed", action="store", type="int", dest="Mfeed", default="1000", help="Move Feed rate in unit/min")
self.OptionParser.add_option("-l", "--laser", action="store", type="int", dest="laser", default="10", help="Laser intensity (0-100)")
self.OptionParser.add_option("", "--homebefore", action="store", type="inkbool", dest="homebefore", default=True, help="Home all beofre starting (G28)")
self.OptionParser.add_option("", "--biarc-tolerance", action="store", type="float", dest="biarc_tolerance", default="1", help="Tolerance used when calculating biarc interpolation.")
self.OptionParser.add_option("", "--biarc-max-split-depth", action="store", type="int", dest="biarc_max_split_depth", default="4", help="Defines maximum depth of splitting while approximating using biarcs.")
......@@ -580,10 +586,10 @@ class Gcode_tools(inkex.Effect):
gcode = ''
if (altfeed):
# Use the "alternative" feed rate specified
f = " F%f" % altfeed
f = " F%i" % altfeed
else:
if self.options.generate_not_parametric_code:
f = " F%f" % self.options.feed
f = " F%i" % self.options.feed
else:
f = " F100"
......@@ -606,7 +612,7 @@ class Gcode_tools(inkex.Effect):
if s[1] == 'move':
# Traversals (G00) tend to signal either the toolhead coming up, going down, or indexing to a new workplace. All other cases seem to signal cutting.
gcode += LASER_OFF + "\nG00 " + self.make_args(si[0]) + "\n"
gcode += LASER_OFF + "\nG00" + " " + self.make_args(si[0]) + " F%i" % self.options.Mfeed + "\n"
lg = 'G00'
elif s[1] == 'end':
......@@ -615,14 +621,14 @@ class Gcode_tools(inkex.Effect):
elif s[1] == 'line':
if lg=="G00":
#gcode += "G01 " + self.make_args([None,None,s[5][0]+depth]) + feed +"\n" + LASER_ON
gcode += LASER_ON
gcode += "G01 " +self.make_args(si[0]) + feed + "\n"
gcode += LASER_ON + " S%i" % self.options.laser + "\n"
gcode += "G01 " +self.make_args(si[0]) + " F%i" % self.options.feed + "\n"
lg = 'G01'
elif s[1] == 'arc':
if lg=="G00":
#gcode += "G01 " + self.make_args([None,None,s[5][0]+depth]) + feed +"\n" + LASER_ON
gcode += LASER_ON
gcode += LASER_ON + " S%i" % self.options.laser + "\n"
dx = s[2][0]-s[0][0]
dy = s[2][1]-s[0][1]
......@@ -634,7 +640,7 @@ class Gcode_tools(inkex.Effect):
gcode += cwArc
else:
gcode += ccwArc
gcode += " " + self.make_args(si[0] + [None, dx, dy, None]) + feed + "\n"
gcode += " " + self.make_args(si[0] + [None, dx, dy, None]) + " F%i" % self.options.feed + "\n"
else:
r = (r1.mag()+r2.mag())/2
......@@ -642,16 +648,17 @@ class Gcode_tools(inkex.Effect):
gcode += cwArc
else:
gcode += ccwArc
gcode += " " + self.make_args(si[0]) + " R%f" % (r*self.options.Xscale) + feed + "\n"
gcode += " " + self.make_args(si[0]) + " R%f" % (r*self.options.Xscale) + " F%i" % self.options.feed + "\n"
lg = cwArc
else:
if lg=="G00":
#gcode += "G01 " + self.make_args([None,None,s[5][0]+depth]) + feed +"\n" + LASER_ON
gcode += LASER_ON
gcode += "G01 " +self.make_args(si[0]) + feed + "\n"
gcode += LASER_ON + " S%i" % self.options.laser + "\n"
gcode += "G01 " +self.make_args(si[0]) + " F%i" % self.options.feed + "\n"
lg = 'G01'
# This added an extra M5 to final block (ajf)
if si[1] == 'end':
gcode += LASER_OFF
return gcode
......@@ -835,22 +842,23 @@ class Gcode_tools(inkex.Effect):
if (self.options.unit == "mm"):
self.unitScale = 0.282222
gcode += "G21 (All units in mm)\n"
gcode += "G21 ; All units in mm\n"
elif (self.options.unit == "in"):
self.unitScale = 0.011111
gcode += "G20 (All units in in)\n"
gcode += "G20 ; All units in in\n"
else:
inkex.errormsg(_("You must choose mm or in"))
return
if not self.options.generate_not_parametric_code:
gcode += """
1.0 = %f (Scale X - relative to the dimensions shown in svg)
1.0 = %f (Scale Y - relative to the dimensions shown in svg)
100 = %f (Feed rate units/min)
0.0 = %f (Offset x)
0.0 = %f (Offset y)
\n""" % (self.options.Xscale, self.options.Yscale, self.options.feed, self.options.Xoffset, self.options.Yoffset)
; Cut Feedrate %i
; Move Feedrate %i
; Laser Intensity %i \n""" % (self.options.feed, self.options.Mfeed, self.options.laser)
if self.options.homebefore:
gcode += "G28 ; home all\n\n"
#if self.options.function == 'Curve':
gcode += self.effect_curve(selected)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment