Commit 0a58a45f authored by leonmuller's avatar leonmuller

Merge back to master

parents 376ff061 a4ef99b1
About This Project
------------------
About This Fork Modified to output gcode that is compatible with K40 style laser cutter
--------------- running Marlin (https://github.com/lansing-makers-network/buildlog-lasercutter-marlin).
10.14.14 by ajf (https://github.com/ajfoul) 26-Feb-2015 - 2 hours : Forked from user ajfoul to extend functionality of smoothie
laser power levels 0.0 to 1.0, generic Marlin power levels being 0 to 100.
Modified to output gcode that is compatible with K40 style laser cutter running Marlin (https://github.com/lansing-makers-network/buildlog-lasercutter-marlin). 07-March-2015 - 10 hours : Cleaned up the exporters code a lot. Added ppm and feedrate detection from
the layer name. Updated the gcode that is exported to be neater and work better with
pulsed mode using G01, G02 and G03 commands.
I couldn't get the original version from LMN repo to work with LMN's Marlin as it never set the laser intensity on the M3 command. 07-March-2015 - Fixed the G28 command at the end of the job. Added defaults for laser power,
feedrates and ppm if defined. If ppm isn't defined in the layer options it will operate as
continuous wave mode. See the help in the extension dialog for how to use.
This works form me, but YMMV. Very limited testing. Never leave your laser cutter unattended while it's powered/operating. Keep a fire extinguisher close by, wear saftey goggles, and be afraid! 07-March-2015 - Marlin codebase mod : You need to patch the Marlin codebase to turn on the
laser before moving for G02 and G03 commands. This plugin assumes this has been done. More
details to come in the future. Copy the code from the G01 above in marlin_main.cpp
USE AT YOUR OWN RISK! Turnkey Laser Inkscape Gcode Export Plugin
------------------------------------------
10.17.14 - A little more testing reveals that G02 (CW ARC) and G03 (CCW ARC) moves are problematic. Not sure if it's the modifications in this fork, the original THLaser, LMN's Marlin, Inkscape, or some combination that is causing the issues.
Basically, you should consider this pre-alpha code. Examine the exported Gcode and do test runs on cardboard/paper before trying to cut on valuable stock.
Also: G28 at the end of the job doesn't seem to be working at the moment, at least not when running the gcode on my machine.
10.19.14 - G02 and G03 really screw things up, so I've set the default min_arc_radius to 500 to force all cut moves to be G01. That has it's own issues. At this point I wouldn't recommend using the Gcode from this for any real jobs.
11.22.14 - Reverted min_arc_radius default
THLaser Inkscape Plugin
-----------------------
This program is an Inkscape extension for exporting a set of paths as This program is an Inkscape extension for exporting a set of paths as
gcode script. It is primarily used by members to the think|haus hacker gcode script.
space (thinkhaus.org) for use with their laser cutter. As such it is
customized to suit our needs and so may not be your best choice if you
are looking for a general purpose Inkscape to gcode script.
This script is a fork of Gcodetools v1.2 written by Nick Drobchenko and This script is a fork of Gcodetools v1.2 written by Nick Drobchenko and
is released under the same license (GPL v2). is released under the same license (GPL v2).
...@@ -37,7 +31,7 @@ is released under the same license (GPL v2). ...@@ -37,7 +31,7 @@ is released under the same license (GPL v2).
Installation Installation
------------ ------------
Copy the files thlaser.py and thlaser.inx into your Inkscape extensions Copy the files turnkeylaser.py and turnkeylaser.inx into your Inkscape extensions
folder. Fire up inkscape and you will find the plugin under Extensions -> folder. Fire up inkscape and you will find the plugin under Extensions ->
Export -> THLaser GCode Export. Export -> THLaser GCode Export.
...@@ -48,7 +42,8 @@ You may find it handy to assign the extension to a keyboard shortcut. ...@@ -48,7 +42,8 @@ You may find it handy to assign the extension to a keyboard shortcut.
Include something like the following line to your inkscape keys Include something like the following line to your inkscape keys
preferences file (this will bind the plugin to Ctrl+\): preferences file (this will bind the plugin to Ctrl+\):
<bind key="backslash" modifiers="Ctrl" action="org.thinkhaus.filter.thlaser" display="true"/> <bind key="backslash" modifiers="Ctrl" action="org.thinkhaus.filter.thlaser"
display="true"/>
You can find your keyboard preferences file: You can find your keyboard preferences file:
...@@ -59,6 +54,6 @@ If that file doesn't exist, create it and include the following: ...@@ -59,6 +54,6 @@ If that file doesn't exist, create it and include the following:
<?xml version="1.0"?> <?xml version="1.0"?>
<keys name="My Keys"> <keys name="My Keys">
<bind key="backslash" modifiers="Ctrl" action="org.thinkhaus.filter.thlaser" display="true"/> <bind key="backslash" modifiers="Ctrl" action="org.thinkhaus.filter.thlaser"
display="true"/>
</keys> </keys>
This source diff could not be displayed because it is too large. You can view the blob instead.
Note : 73% on my unit runs the laser tube at 18ma. This is the maximum current that should be put through a 40 watt CO2 laser tube.
Cut Perspex = F300 @ 73%
Score cardboard = F1400 @ 9%
Cut Paper (Pulsed) = F600 @ 8% - 60ms pulse 2 pulse per millimetre.
\ No newline at end of file
G21 ; All units in mm
; Default Cut Feedrate 300 mm per minute
; Default Move Feedrate 2000 mm per minute
; Default Laser Intensity 72 percent
G28 ; home all
M5 ;turn the laser off
;(************************************************************)
;(***** Layer: 8 *****)
;(***** Laser Power: 8 *****)
;(***** Feed Rate: 600.0 *****)
;(***** Pulse Rate: None *****)
;(************************************************************)
;(MSG,Starting layer '8')
G00 X93.693928 Y42.800959 F2000
G01 S8.00 X93.693928 Y123.034303 F600 B0 D0
M5 ;turn the laser off
M5 ;turn the laser off
;(************************************************************)
;(***** Layer: 8 *****)
;(***** Laser Power: 8 *****)
;(***** Feed Rate: 600.0 *****)
;(***** Pulse Rate: 2.0 *****)
;(************************************************************)
;(MSG,Starting layer '8')
G00 X89.182149 Y42.856593 F2000
G01 S8.00 X89.182149 Y123.089937 F600 L60000 P1 B1 D0
M5 ;turn the laser off
M5 ;turn the laser off
;(************************************************************)
;(***** Layer: 8 *****)
;(***** Laser Power: 8 *****)
;(***** Feed Rate: 600.0 *****)
;(***** Pulse Rate: 1.0 *****)
;(************************************************************)
;(MSG,Starting layer '8')
G00 X84.297648 Y42.816729 F2000
G01 S8.00 X84.297648 Y123.050073 F600 L60000 P0.5 B1 D0
M5 ;turn the laser off
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension> <inkscape-extension>
<name>THLaser GCode Exporter</name> <name>TurnkeyLaser Exporter</name>
<id>org.thinkhaus.filter.thlaser</id> <id>com.turnkey.Tyranny</id>
<effect> <effect>
<object-type>path</object-type> <object-type>path</object-type>
...@@ -10,44 +10,61 @@ ...@@ -10,44 +10,61 @@
</effects-menu> </effects-menu>
</effect> </effect>
<dependency type="executable" location="extensions">thlaser.py</dependency> <dependency type="executable" location="extensions">turnkeylaser.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency>
<script> <script>
<command reldir="extensions" interpreter="python">thlaser.py</command> <command reldir="extensions" interpreter="python">turnkeylaser.py</command>
</script> </script>
<param name='tab' type="notebook"> <param name='tab' type="notebook">
<page name='tab' _gui-text='Help'> <page name='tab' _gui-text='Help'>
<_param name="fullhelp" type="description">THLaser converts inkscape paths to Gcode. (v1.30) <_param name="fullhelp" type="description">TurnkeyLaser exports Inkscape paths to Gcode compatible with Ramps+Marlin or Smoothieware laser mainboards.
This script is a fork of Gcodetools v1.2 by Nick Drobchenko. It is currently maintained by Peter Rogers (peter.rogers@gmail.com) at think|haus.</_param> You're able to specify in your layer names the laser power output, feedrate and optionally the pulse per millimetre option for pulsed lasing mode as opposed to the default continuous wave operation mode.
1)Name your layer like the following example :
35 [feed=600,ppm=40]
2)Draw your designs and group them based on lasing options in the layer name.
3)Select the paths you want to export, then run this script.
In the example above the layer will be cut at 35% power with a feedrate of 600mm per minute and a pulse rate of 40 pulses per millimetre (at 60ms pulses).
If the ppm option isn't specified in the layer options then output lines will be cut in continuous wave mode at the power and feed specified.
If you do not specify the laser power or other options in the layer name then they will default to the options in the export dialog box under "Preferences".
For the latest revision please visit https://github.com/TurnkeyTyranny/laser-gcode-exporter-inkscape-plugin
</_param>
</page> </page>
<page name='tab' _gui-text='Advanced'> <page name='tab' _gui-text='Advanced'>
<param name="biarc-tolerance" type='float' _gui-text='Biarc interpolation tolerance'>1</param> <param name="mainboard" type="enum" _gui-text="Mainboard: ">
<item value="ramps">Ramps 1.4</item>
<item value="smoothie">Smoothie</item>
</param>
<param name="biarc-tolerance" type='float' _gui-text='Biarc interpolation tolerance'>0.5</param>
<_param name="help" type="description">Biarc interpolation tolerance is the maximum allowed distance between a path and it's approximation. If this value is exceeded, the path will be split into two segments.</_param> <_param name="help" type="description">Biarc interpolation tolerance is the maximum allowed distance between a path and it's approximation. If this value is exceeded, the path will be split into two segments.</_param>
<param name="biarc-max-split-depth" type="int" _gui-text="Maximum splitting depth">4</param> <param name="biarc-max-split-depth" type="int" _gui-text="Maximum splitting depth">4</param>
<param name="min-arc-radius" type="float" precision="5" min="-1000" max="1000" _gui-text="Minimum arc radius">0.05</param> <param name="min-arc-radius" type="float" precision="5" min="-1000" max="5000" _gui-text="Minimum arc radius">0.00005</param>
<param name="Xoffset" type="float" precision="4" min="-1000" max="1000" _gui-text="Offset along X axis">0.0</param> <param name="Xoffset" type="float" precision="4" min="-1000" max="1000" _gui-text="Offset along X axis">0.0</param>
<param name="Yoffset" type="float" precision="4" min="-1000" max="1000" _gui-text="Offset along Y axis">0.0</param> <param name="Yoffset" type="float" precision="4" min="-1000" max="1000" _gui-text="Offset along Y axis">0.0</param>
<param name="logging" type="boolean" _gui-text="Log debug output from plugin:">true</param> <param name="logging" type="boolean" _gui-text="Log debug output from plugin:">true</param>
</page> </page>
<page name='tab' _gui-text='Preferences'> <page name='tab' _gui-text='Preferences'>
<param name="filename" type="string" _gui-text="File name: ">output.ngc</param> <param name="filename" type="string" _gui-text="File name: ">output.g</param>
<param name="directory" type="string" _gui-text="Directory: "></param> <param name="directory" type="string" _gui-text="Directory: "></param>
<_param name="help" type="description">(blank is your desktop)</_param> <_param name="help" type="description">(blank is your desktop)</_param>
<param name="feed" type="int" min="0" max="1000" _gui-text="Cut Feedrate:">60</param> <param name="feed" type="int" min="0" max="5000" _gui-text="Default Cut Feedrate:">300</param>
<param name="Mfeed" type="int" min="0" max="5000" _gui-text="Traversal Feedrate:">300</param> <param name="Mfeed" type="int" min="0" max="5000" _gui-text="Default Traversal Feedrate:">2000</param>
<param name="laser" type="int" min="0" max="100" _gui-text="Laser Intensity (0-100):">10</param> <param name="laser" type="int" min="0" max="100" _gui-text="Default Laser Intensity (0-100%):">10</param>
<param name="homebefore" type="boolean" _gui-text="HOMEALL (G28) Before:">true</param> <param name="homebefore" type="boolean" _gui-text="Home X & Y Before:">true</param>
<param name="homeafter" type="boolean" _gui-text="HOMEALL (G28) After:">false</param> <param name="homeafter" type="boolean" _gui-text="Home X & Y After:">false</param>
<param name="Xscale" type="float" precision="4" min="-1000" max="1000" _gui-text="Scale along X axis:">1</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="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> <param name="double_sided_cutting" type="boolean" _gui-text="Cut both sides of material?">false</param>
<param name="draw-curves" type="boolean" _gui-text="Draw curves:">true</param> <param name="draw-curves" type="boolean" _gui-text="Draw curves in inkscape layer">true</param>
<param name="unit" type="enum" _gui-text="Units: "> <param name="unit" type="enum" _gui-text="Units: ">
<item value="mm">mm</item> <item value="mm">mm</item>
......
#!/usr/bin/env python #!/usr/bin/env python
""" """
think|haus gcode inkscape extension TurnkeyLaserExporter
----------------------------------- -----------------------------------
Maintained by Peter Rogers (peter.rogers@gmail.com) Maintained by Turnkey Tyranny (https://github.com/TurnkeyTyranny/laser-gcode-exporter-inkscape-plugin)
Customized to suit our needs at thinkhaus.org (see change log below) Designed to run on Ramps 1.4 + Marlin firmware on a K40 CO2 Laser Cutter.
Based on think|haus gcode inkscape extension
Based on a script by Nick Drobchenko from the CNC club Based on a script by Nick Drobchenko from the CNC club
*** ***
...@@ -31,42 +33,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ...@@ -31,42 +33,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
""" """
""" """
Changelog 2012-01-12 - PAR:
* fixed bug in compile_paths when dealing with empty node data Changelog 2015-02-01:
* Beginning of the project. Based on a fork from ShinyLaser(https://github.com/ajfoul/thlaser-inkscape-plugin)
Changelog 2011-10-16 - PAR:
* general code cleanup to make things more readable Changelog 2015-02-16:
* now inkscape coordinate system matches laser bed coordinate system Added an option to export as Marlin or Smoothie Power levels
* removed "area curve" code, since it wasn't being used and wasn't working anyways
* cleanup of source code, reorganized the dialog window Changelog 2015-03-07:
Added capability to pick out power, ppm, feedrate etc from the layer names
Changelog 2011-08-06 - PAR: Added code to support Pulse Per Minute burning or continuous burning. Will default to continuous.
* layer and group transforms now taken into account M649 S100 L300 P10 - Set Laser settings to 100 percent power, pulses are each 300ms, and 10 pulses per mm.
* tool change now happens on every layer (only when multiple layers present) G0 : Move to a new location with the laser off.
* displays a message at the start of each layer G1 : Move to a new location with the laser on.
G2 : Move in a Clockwise Arc
Changelog 2011-07-31 - PAR: G3 : Move in a Counter Clockwise Arc
* misc bug fixes Name your layer like 10 [feed=600,ppm=40] for 10% power, 600mm per minute cut and 40 pulse per millimetre at 60ms duration
* objects in document root (ie not in a layer) now outputted properly
* skips 'comment' layers (ie name prefixed with '#')
* warns about any selected objects not outputted by the script
Changelog 2011-07-01 - PAR:
* logging is now enabled by default
* handling groups and layers properly
* toolchange operation (M6) added between outputting layers
* removed 'options.ids' in favor of 'self.selected'
Changelog 2011-02-20 - Adina:
* removed any movement in the z axis when the laser is trying to etch a curve.
* removed extra M3s: the laser only turns on at the beginning of a cut block, not before every line.
Changelog 2010-04-07 - Adina:
* separate scaling factor for x and y,
* x and y scaled to mm or inches that match the dimensions in inkscape (not 1px = 1 in or mm)
Changelog 2010-04-20:
* made the .inx file refer to the correct .py file... it should work now?
""" """
### ###
...@@ -83,7 +65,7 @@ import re ...@@ -83,7 +65,7 @@ import re
import copy import copy
import sys import sys
import time import time
_ = inkex._ #_ = inkex._
################################################################################ ################################################################################
...@@ -92,13 +74,12 @@ _ = inkex._ ...@@ -92,13 +74,12 @@ _ = inkex._
### ###
################################################################################ ################################################################################
VERSION = "1.30" VERSION = "1.0.1"
STRAIGHT_TOLERANCE = 0.0001 STRAIGHT_TOLERANCE = 0.0001
STRAIGHT_DISTANCE_TOLERANCE = 0.0001 STRAIGHT_DISTANCE_TOLERANCE = 0.0001
LASER_ON = "M3" # Peter - LASER ON MCODE LASER_ON = "M3 ;turn the laser on" # LASER ON MCODE
LASER_OFF = "M5\n" # Peter - LASER OFF MCODE LASER_OFF = "M5 ;turn the laser off\n" # LASER OFF MCODE
TOOL_CHANGE = "T%02d (select tool)\nM6 (tool change)\n\n"
HEADER_TEXT = "" HEADER_TEXT = ""
FOOTER_TEXT = "" FOOTER_TEXT = ""
...@@ -391,11 +372,11 @@ def parse_layer_name(txt): ...@@ -391,11 +372,11 @@ def parse_layer_name(txt):
(field, value) = arg.split("=") (field, value) = arg.split("=")
except: except:
raise ValueError("Invalid argument in layer '%s'" % layerName) raise ValueError("Invalid argument in layer '%s'" % layerName)
if (field == "feed"): if (field == "feed" or field == "ppm"):
try: try:
value = float(value) value = float(value)
except: except:
raise ValueError("Invalid feed rate '%s'" % value) raise ValueError("Invalid layer name '%s'" % value)
params[field] = value params[field] = value
logger.write("%s == %s" % (field, value)) logger.write("%s == %s" % (field, value))
...@@ -428,11 +409,12 @@ class Gcode_tools(inkex.Effect): ...@@ -428,11 +409,12 @@ class Gcode_tools(inkex.Effect):
self.OptionParser.add_option("-x", "--Xoffset", action="store", type="float", dest="Xoffset", default="0.0", help="Offset along X") 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("-y", "--Yoffset", action="store", type="float", dest="Yoffset", default="0.0", help="Offset along Y")
# added move (laser off) feedrate and laser intensity; made all int rather than float - (ajf) # 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="300", help="Move Feed rate in unit/min") self.OptionParser.add_option("-m", "--Mfeed", action="store", type="int", dest="Mfeed", default="2000", help="Default 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("-p", "--feed", action="store", type="int", dest="feed", default="300", help="Default Cut Feed rate in unit/min")
self.OptionParser.add_option("-b", "--homebefore", action="store", type="inkbool", dest="homebefore", default=True, help="Home all axis beofre starting (G28)") self.OptionParser.add_option("-l", "--laser", action="store", type="int", dest="laser", default="10", help="Default Laser intensity (0-100 %)")
self.OptionParser.add_option("-a", "--homeafter", action="store", type="inkbool", dest="homeafter", default=False, help="Home all axis at end of job (G28)") self.OptionParser.add_option("-b", "--homebefore", action="store", type="inkbool", dest="homebefore", default=True, help="Home all beofre starting (G28)")
self.OptionParser.add_option("-a", "--homeafter", action="store", type="inkbool", dest="homeafter", default=False, help="Home X Y at end of job")
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-tolerance", action="store", type="float", dest="biarc_tolerance", default="1", help="Tolerance used when calculating biarc interpolation.")
...@@ -450,7 +432,9 @@ class Gcode_tools(inkex.Effect): ...@@ -450,7 +432,9 @@ class Gcode_tools(inkex.Effect):
self.OptionParser.add_option("", "--loft-direction", action="store", type="string", dest="loft_direction", default="crosswise", help="Direction of loft's interpolation.") self.OptionParser.add_option("", "--loft-direction", action="store", type="string", dest="loft_direction", default="crosswise", help="Direction of loft's interpolation.")
self.OptionParser.add_option("", "--loft-interpolation-degree",action="store", type="float", dest="loft_interpolation_degree", default="2", help="Which interpolation use to loft the paths smooth interpolation or staright.") self.OptionParser.add_option("", "--loft-interpolation-degree",action="store", type="float", dest="loft_interpolation_degree", default="2", help="Which interpolation use to loft the paths smooth interpolation or staright.")
self.OptionParser.add_option("", "--min-arc-radius", action="store", type="float", dest="min_arc_radius", default=".1", help="All arc having radius less than minimum will be considered as straight line") self.OptionParser.add_option("", "--min-arc-radius", action="store", type="float", dest="min_arc_radius", default="0.0005", help="All arc having radius less than minimum will be considered as straight line")
self.OptionParser.add_option("", "--mainboard", action="store", type="string", dest="mainboard", default="ramps", help="Mainboard")
def parse_curve(self, path): def parse_curve(self, path):
# if self.options.Xscale!=self.options.Yscale: # if self.options.Xscale!=self.options.Yscale:
...@@ -583,53 +567,68 @@ class Gcode_tools(inkex.Effect): ...@@ -583,53 +567,68 @@ class Gcode_tools(inkex.Effect):
args.append(s[i] + ("%f" % value) + s1[i]) args.append(s[i] + ("%f" % value) + s1[i])
return " ".join(args) return " ".join(args)
def generate_gcode(self, curve, depth, altfeed=None): def generate_gcode(self, curve, depth, laserPower, altfeed=None, altppm=None):
gcode = '' gcode = ''
#Setup our feed rate, either from the layer name or from the default value.
if (altfeed): if (altfeed):
# Use the "alternative" feed rate specified # Use the "alternative" feed rate specified
f = " F%i" % altfeed cutFeed = "F%i" % altfeed
else: else:
if self.options.generate_not_parametric_code: if self.options.generate_not_parametric_code:
f = " F%i" % self.options.feed cutFeed = "F%i" % self.options.feed
else:
cutFeed = "F%i" % self.options.feed
#Setup our pulse per millimetre option, if applicable
#B: laser firing mode (0 = continuous, 1 = pulsed, 2 = raster)
if (altppm):
# Use the "alternative" ppm - L60000 is 60ms
ppmValue = "L60000 P%.2f B1 D0" % altppm
else: else:
f = " F100" #Set the laser firing mode to continuous.
ppmValue = "B0 D0"
cwArc = "G02" cwArc = "G02"
ccwArc = "G03" ccwArc = "G03"
if (self.flipArcs):
# The geometry is reflected, so invert the orientation of the arcs to match # The geometry is reflected, so invert the orientation of the arcs to match
if (self.flipArcs):
(cwArc, ccwArc) = (ccwArc, cwArc) (cwArc, ccwArc) = (ccwArc, cwArc)
# Peter's note: Here's where the 'laser on' and 'laser off' m-codes get appended to the GCODE generation # The 'laser on' and 'laser off' m-codes get appended to the GCODE generation
lg = 'G00' lg = 'G00'
for i in range(1,len(curve)): for i in range(1,len(curve)):
s, si = curve[i-1], curve[i] s, si = curve[i-1], curve[i]
#feed = f if lg not in ['G01','G02','G03'] else ''
if (lg not in ["G01", "G02", "G03"]):
feed = f
else:
feed = ""
#G00 : Move with the laser off to a new point
if s[1] == 'move': 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. #Turn off the laser if it was on previously.
gcode += LASER_OFF + "\nG00" + " " + self.make_args(si[0]) + " F%i" % self.options.Mfeed + "\n" if lg != "G00":
gcode += LASER_OFF + "\n"
gcode += "G00" + " " + self.make_args(si[0]) + " F%i" % self.options.Mfeed + "\n"
lg = 'G00' lg = 'G00'
elif s[1] == 'end': elif s[1] == 'end':
lg = 'G00' lg = 'G00'
#G01 : Move with the laser turned on to a new point
elif s[1] == 'line': elif s[1] == 'line':
if lg=="G00": #No longer needed because G01, G02 and G03 will be forced in marlin to automatically fire the laser.
#gcode += "G01 " + self.make_args([None,None,s[5][0]+depth]) + feed +"\n" + LASER_ON #If the laser was turned off, turn it back on.
gcode += LASER_ON + " S%i" % self.options.laser + "\n" #if lg == "G00":
gcode += "G01 " +self.make_args(si[0]) + " F%i" % self.options.feed + "\n" # gcode += LASER_ON + "\n"
gcode += "G01 " + "S%.2f " % laserPower + self.make_args(si[0]) + " %s " % cutFeed + "%s" % ppmValue + "\n"
lg = 'G01' lg = 'G01'
#G02 and G03 : Move in an arc with the laser turned on.
elif s[1] == 'arc': elif s[1] == 'arc':
if lg=="G00": #No longer needed because G01, G02 and G03 will be forced in marlin to automatically fire the laser.
#gcode += "G01 " + self.make_args([None,None,s[5][0]+depth]) + feed +"\n" + LASER_ON #If the laser was turned off, turn it back on.
gcode += LASER_ON + " S%i" % self.options.laser + "\n" #if lg == "G00":
# gcode += LASER_ON + "\n"
dx = s[2][0]-s[0][0] dx = s[2][0]-s[0][0]
dy = s[2][1]-s[0][1] dy = s[2][1]-s[0][1]
...@@ -641,7 +640,7 @@ class Gcode_tools(inkex.Effect): ...@@ -641,7 +640,7 @@ class Gcode_tools(inkex.Effect):
gcode += cwArc gcode += cwArc
else: else:
gcode += ccwArc gcode += ccwArc
gcode += " " + self.make_args(si[0] + [None, dx, dy, None]) + " F%i" % self.options.feed + "\n" gcode += " " + "S%.2f " % laserPower + self.make_args(si[0] + [None, dx, dy, None]) + " %s " % cutFeed + "%s" % ppmValue + "\n"
else: else:
r = (r1.mag()+r2.mag())/2 r = (r1.mag()+r2.mag())/2
...@@ -649,21 +648,19 @@ class Gcode_tools(inkex.Effect): ...@@ -649,21 +648,19 @@ class Gcode_tools(inkex.Effect):
gcode += cwArc gcode += cwArc
else: else:
gcode += ccwArc gcode += ccwArc
gcode += " " + self.make_args(si[0]) + " R%f" % (r*self.options.Xscale) + " F%i" % self.options.feed + "\n" gcode += " " + "S%.2f " % laserPower + self.make_args(si[0]) + " R%f" % (r*self.options.Xscale) + " %s " % cutFeed + "%s" % ppmValue + "\n"
lg = cwArc lg = cwArc
#The arc is less than the minimum arc radius, draw it as a straight line.
else: else:
if lg=="G00": gcode += "G01 " + "S%.2f " % laserPower + self.make_args(si[0]) + " %s " % cutFeed + "%s" % ppmValue + "\n"
#gcode += "G01 " + self.make_args([None,None,s[5][0]+depth]) + feed +"\n" + LASER_ON
gcode += LASER_ON + " S%i" % self.options.laser + "\n"
gcode += "G01 " +self.make_args(si[0]) + " F%i" % self.options.feed + "\n"
lg = 'G01' lg = 'G01'
#The end of the layer.
if si[1] == 'end': if si[1] == 'end':
gcode += LASER_OFF gcode += LASER_OFF
if self.options.homeafter:
gcode += "\n\nG28 ; home all"
return gcode return gcode
...@@ -748,6 +745,7 @@ class Gcode_tools(inkex.Effect): ...@@ -748,6 +745,7 @@ class Gcode_tools(inkex.Effect):
# Check if the layer specifies an alternative (from the default) feed rate # Check if the layer specifies an alternative (from the default) feed rate
altfeed = layerParams.get("feed", None) altfeed = layerParams.get("feed", None)
altppm = layerParams.get("ppm", None)
logger.write("layer %s" % layerName) logger.write("layer %s" % layerName)
if (layerParams): if (layerParams):
...@@ -770,25 +768,46 @@ class Gcode_tools(inkex.Effect): ...@@ -770,25 +768,46 @@ class Gcode_tools(inkex.Effect):
continue continue
curve = self.parse_curve(pathList) curve = self.parse_curve(pathList)
#Determind the power of the laser that this layer should be cut at.
#If the layer is not named as an integer value then default to the laser intensity set at the export settings.
#Fetch the laser power from the export dialog box.
laserPower = self.options.laser
if (int(layerName) > 0 and int(layerName) <= 100):
laserPower = int(layerName)
else :
laserPower = self.options.laser
#Switch between smoothie power levels and ramps+marlin power levels
#ramps and marlin expect 0 to 100 while smoothie wants 0.0 to 1.0
if (self.options.mainboard == 'smoothie'):
laserPower = laserPower / 100
# If there are several layers, start with a tool change operation # If there are several layers, start with a tool change operation
if (len(layers) > 1): #Turnkey : Always output the layer header for information.
if (len(layers) > 0):
gcode += LASER_OFF+"\n" gcode += LASER_OFF+"\n"
size = 60 size = 60
gcode += "(%s)\n" % ("*"*size) gcode += ";(%s)\n" % ("*"*size)
gcode += ("(***** LAYER: %%-%ds *****)\n" % (size-19)) % (layerName) gcode += (";(***** Layer: %%-%ds *****)\n" % (size-19)) % (layerName)
gcode += "(%s)\n" % ("*"*size) gcode += (";(***** Laser Power: %%-%ds *****)\n" % (size-25)) % (laserPower)
gcode += "(MSG,Starting layer '%s')\n\n" % layerName gcode += (";(***** Feed Rate: %%-%ds *****)\n" % (size-23)) % (altfeed)
gcode += (";(***** Pulse Rate: %%-%ds *****)\n" % (size-24)) % (altppm)
gcode += ";(%s)\n" % ("*"*size)
gcode += ";(MSG,Starting layer '%s')\n\n" % layerName
# Move the laser into the starting position (so that way it is positioned # Move the laser into the starting position (so that way it is positioned
# for testing the power level, if the user wants to change that). # for testing the power level, if the user wants to change that).
arg = curve[0] arg = curve[0]
pt = arg[0] pt = arg[0]
gcode += "G00 " + self.make_args(pt) + "\n" #gcode += "G00 " + self.make_args(pt) + "\n"
gcode += self.tool_change()
if (self.options.drawCurves): if (self.options.drawCurves):
self.draw_curve(curve) self.draw_curve(curve)
gcode += self.generate_gcode(curve, 0, altfeed=altfeed) #Generate the GCode for this layer
gcode += self.generate_gcode(curve, 0, laserPower, altfeed=altfeed, altppm=altppm)
# If there are any objects left over, it's because they don't belong # If there are any objects left over, it's because they don't belong
# to any inkscape layer (bug in inkscape?). Output those now. # to any inkscape layer (bug in inkscape?). Output those now.
...@@ -804,13 +823,21 @@ class Gcode_tools(inkex.Effect): ...@@ -804,13 +823,21 @@ class Gcode_tools(inkex.Effect):
if (self.options.drawCurves): if (self.options.drawCurves):
self.draw_curve(curve) self.draw_curve(curve)
gcode += "\n(*** Root objects ***)\n" gcode += "\n;(*** Root objects ***)\n"
if (layers):
# Include a tool change operation between the layers outputted above #Fetch the laser power from the export dialog box.
# and these "orphaned" objects. laserPower = self.options.laser
gcode += self.tool_change()
#Switch between smoothie power levels and ramps+marlin power levels
#ramps and marlin expect 0 to 100 while smoothie wants 0.0 to 1.0
if (self.options.mainboard == 'smoothie'):
laserPower = laserPower / 100
gcode += self.generate_gcode(curve, 0, laserPower)
if self.options.homeafter:
gcode += "\n\nG00 X0 Y0 F4000 ; home"
gcode += self.generate_gcode(curve, 0)
return gcode return gcode
def effect(self): def effect(self):
...@@ -856,9 +883,9 @@ class Gcode_tools(inkex.Effect): ...@@ -856,9 +883,9 @@ class Gcode_tools(inkex.Effect):
if not self.options.generate_not_parametric_code: if not self.options.generate_not_parametric_code:
gcode += """ gcode += """
; Cut Feedrate %i ; Default Cut Feedrate %i mm per minute
; Move Feedrate %i ; Default Move Feedrate %i mm per minute
; Laser Intensity %i \n""" % (self.options.feed, self.options.Mfeed, self.options.laser) ; Default Laser Intensity %i percent\n""" % (self.options.feed, self.options.Mfeed, self.options.laser)
if self.options.homebefore: if self.options.homebefore:
gcode += "G28 ; home all\n\n" gcode += "G28 ; home all\n\n"
...@@ -867,7 +894,7 @@ class Gcode_tools(inkex.Effect): ...@@ -867,7 +894,7 @@ class Gcode_tools(inkex.Effect):
gcode += self.effect_curve(selected) gcode += self.effect_curve(selected)
if (self.options.double_sided_cutting): if (self.options.double_sided_cutting):
gcode += "\n\n(MSG,Please flip over material)\n\n" gcode += "\n\n;(MSG,Please flip over material)\n\n"
# Include a tool change operation # Include a tool change operation
gcode += self.tool_change() gcode += self.tool_change()
......
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