Added dwell (G4) post processing option to gcode.
This commit is contained in:
parent
36d0a2e029
commit
6136afe84c
|
@ -245,7 +245,9 @@ class App(QtCore.QObject):
|
||||||
"cncjob_plot": self.defaults_form.cncjob_group.plot_cb,
|
"cncjob_plot": self.defaults_form.cncjob_group.plot_cb,
|
||||||
"cncjob_tooldia": self.defaults_form.cncjob_group.tooldia_entry,
|
"cncjob_tooldia": self.defaults_form.cncjob_group.tooldia_entry,
|
||||||
"cncjob_prepend": self.defaults_form.cncjob_group.prepend_text,
|
"cncjob_prepend": self.defaults_form.cncjob_group.prepend_text,
|
||||||
"cncjob_append": self.defaults_form.cncjob_group.append_text
|
"cncjob_append": self.defaults_form.cncjob_group.append_text,
|
||||||
|
"cncjob_dwell": self.defaults_form.cncjob_group.dwell_cb,
|
||||||
|
"cncjob_dwelltime": self.defaults_form.cncjob_group.dwelltime_cb
|
||||||
}
|
}
|
||||||
|
|
||||||
self.defaults = LoudDict()
|
self.defaults = LoudDict()
|
||||||
|
@ -289,8 +291,13 @@ class App(QtCore.QObject):
|
||||||
"cncjob_tooldia": 0.016,
|
"cncjob_tooldia": 0.016,
|
||||||
"cncjob_prepend": "",
|
"cncjob_prepend": "",
|
||||||
"cncjob_append": "",
|
"cncjob_append": "",
|
||||||
"background_timeout": 300000, #default value is 5 minutes
|
"cncjob_dwell": True,
|
||||||
"verbose_error_level": 0, # shell verbosity 0 = default(python trace only for unknown errors), 1 = show trace(show trace allways), 2 = (For the future).
|
"cncjob_dwelltime": 1,
|
||||||
|
"background_timeout": 300000, # Default value is 5 minutes
|
||||||
|
"verbose_error_level": 0, # Shell verbosity 0 = default
|
||||||
|
# (python trace only for unknown errors),
|
||||||
|
# 1 = show trace(show trace allways),
|
||||||
|
# 2 = (For the future).
|
||||||
|
|
||||||
# Persistence
|
# Persistence
|
||||||
"last_folder": None,
|
"last_folder": None,
|
||||||
|
|
|
@ -806,6 +806,26 @@ class CNCJobOptionsGroupUI(OptionsGroupUI):
|
||||||
self.append_text = FCTextArea()
|
self.append_text = FCTextArea()
|
||||||
self.layout.addWidget(self.append_text)
|
self.layout.addWidget(self.append_text)
|
||||||
|
|
||||||
|
# Dwell
|
||||||
|
grid1 = QtGui.QGridLayout()
|
||||||
|
self.layout.addLayout(grid1)
|
||||||
|
|
||||||
|
dwelllabel = QtGui.QLabel('Dwell:')
|
||||||
|
dwelllabel.setToolTip(
|
||||||
|
"Pause to allow the spindle to reach its\n"
|
||||||
|
"speed before cutting."
|
||||||
|
)
|
||||||
|
dwelltime = QtGui.QLabel('Duration [sec.]:')
|
||||||
|
dwelltime.setToolTip(
|
||||||
|
"Number of second to dwell."
|
||||||
|
)
|
||||||
|
self.dwell_cb = FCCheckBox()
|
||||||
|
self.dwelltime_cb = FCEntry()
|
||||||
|
grid1.addWidget(dwelllabel, 0, 0)
|
||||||
|
grid1.addWidget(self.dwell_cb, 0, 1)
|
||||||
|
grid1.addWidget(dwelltime, 1, 0)
|
||||||
|
grid1.addWidget(self.dwelltime_cb, 1, 1)
|
||||||
|
|
||||||
|
|
||||||
class GlobalOptionsUI(QtGui.QWidget):
|
class GlobalOptionsUI(QtGui.QWidget):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from cStringIO import StringIO
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from ObjectUI import *
|
from ObjectUI import *
|
||||||
|
@ -981,7 +982,9 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
|
||||||
"plot": True,
|
"plot": True,
|
||||||
"tooldia": 0.4 / 25.4, # 0.4mm in inches
|
"tooldia": 0.4 / 25.4, # 0.4mm in inches
|
||||||
"append": "",
|
"append": "",
|
||||||
"prepend": ""
|
"prepend": "",
|
||||||
|
"dwell": False,
|
||||||
|
"dwelltime": 1
|
||||||
})
|
})
|
||||||
|
|
||||||
# Attributes to be included in serialization
|
# Attributes to be included in serialization
|
||||||
|
@ -1001,7 +1004,9 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
|
||||||
"plot": self.ui.plot_cb,
|
"plot": self.ui.plot_cb,
|
||||||
"tooldia": self.ui.tooldia_entry,
|
"tooldia": self.ui.tooldia_entry,
|
||||||
"append": self.ui.append_text,
|
"append": self.ui.append_text,
|
||||||
"prepend": self.ui.prepend_text
|
"prepend": self.ui.prepend_text,
|
||||||
|
"dwell": self.ui.dwell_cb,
|
||||||
|
"dwelltime": self.ui.dwelltime_entry
|
||||||
})
|
})
|
||||||
|
|
||||||
self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
|
self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
|
||||||
|
@ -1019,6 +1024,8 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
|
||||||
def on_exportgcode_button_click(self, *args):
|
def on_exportgcode_button_click(self, *args):
|
||||||
self.app.report_usage("cncjob_on_exportgcode_button")
|
self.app.report_usage("cncjob_on_exportgcode_button")
|
||||||
|
|
||||||
|
self.read_form()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
filename = QtGui.QFileDialog.getSaveFileName(caption="Export G-Code ...",
|
filename = QtGui.QFileDialog.getSaveFileName(caption="Export G-Code ...",
|
||||||
directory=self.app.defaults["last_folder"])
|
directory=self.app.defaults["last_folder"])
|
||||||
|
@ -1030,10 +1037,51 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
|
||||||
|
|
||||||
self.export_gcode(filename, preamble=preamble, postamble=postamble)
|
self.export_gcode(filename, preamble=preamble, postamble=postamble)
|
||||||
|
|
||||||
|
def dwell_generator(self, lines):
|
||||||
|
|
||||||
|
log.debug("dwell_generator()...")
|
||||||
|
|
||||||
|
m3m4re = re.compile(r'^\s*[mM]0[34]')
|
||||||
|
g4re = re.compile(r'^\s*[gG]4\s+([\d\.\+\-e]+)')
|
||||||
|
bufline = None
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
# If the buffer contains a G4, yield that.
|
||||||
|
# If current line is a G4, discard it.
|
||||||
|
if bufline is not None:
|
||||||
|
yield bufline
|
||||||
|
bufline = None
|
||||||
|
|
||||||
|
if not g4re.search(line):
|
||||||
|
yield line
|
||||||
|
|
||||||
|
continue
|
||||||
|
|
||||||
|
# If start spindle, buffer a G4.
|
||||||
|
if m3m4re.search(line):
|
||||||
|
log.debug("Found M03/4")
|
||||||
|
bufline = "G4 {}\n".format(self.options['dwelltime'])
|
||||||
|
|
||||||
|
yield line
|
||||||
|
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
def export_gcode(self, filename, preamble='', postamble=''):
|
def export_gcode(self, filename, preamble='', postamble=''):
|
||||||
f = open(filename, 'w')
|
|
||||||
f.write(preamble + '\n' + self.gcode + "\n" + postamble)
|
lines = StringIO(self.gcode)
|
||||||
f.close()
|
|
||||||
|
if self.options['dwell']:
|
||||||
|
log.debug("Will add G04!")
|
||||||
|
lines = self.dwell_generator(lines)
|
||||||
|
|
||||||
|
with open(filename, 'w') as f:
|
||||||
|
f.write(preamble + "\n")
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
|
||||||
|
f.write(line)
|
||||||
|
|
||||||
|
f.write(postamble)
|
||||||
|
|
||||||
# Just for adding it to the recent files list.
|
# Just for adding it to the recent files list.
|
||||||
self.app.file_opened.emit("cncjob", filename)
|
self.app.file_opened.emit("cncjob", filename)
|
||||||
|
@ -1309,8 +1357,7 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
||||||
|
|
||||||
app_obj.progress.emit(80)
|
app_obj.progress.emit(80)
|
||||||
|
|
||||||
|
if use_thread:
|
||||||
if use_thread:
|
|
||||||
# To be run in separate thread
|
# To be run in separate thread
|
||||||
def job_thread(app_obj):
|
def job_thread(app_obj):
|
||||||
with self.app.proc_container.new("Generating CNC Job."):
|
with self.app.proc_container.new("Generating CNC Job."):
|
||||||
|
|
22
ObjectUI.py
22
ObjectUI.py
|
@ -163,7 +163,9 @@ class CNCObjectUI(ObjectUI):
|
||||||
)
|
)
|
||||||
self.custom_box.addWidget(self.updateplot_button)
|
self.custom_box.addWidget(self.updateplot_button)
|
||||||
|
|
||||||
|
##################
|
||||||
## Export G-Code
|
## Export G-Code
|
||||||
|
##################
|
||||||
self.export_gcode_label = QtGui.QLabel("<b>Export G-Code:</b>")
|
self.export_gcode_label = QtGui.QLabel("<b>Export G-Code:</b>")
|
||||||
self.export_gcode_label.setToolTip(
|
self.export_gcode_label.setToolTip(
|
||||||
"Export and save G-Code to\n"
|
"Export and save G-Code to\n"
|
||||||
|
@ -194,6 +196,26 @@ class CNCObjectUI(ObjectUI):
|
||||||
self.append_text = FCTextArea()
|
self.append_text = FCTextArea()
|
||||||
self.custom_box.addWidget(self.append_text)
|
self.custom_box.addWidget(self.append_text)
|
||||||
|
|
||||||
|
# Dwell
|
||||||
|
grid1 = QtGui.QGridLayout()
|
||||||
|
self.custom_box.addLayout(grid1)
|
||||||
|
|
||||||
|
dwelllabel = QtGui.QLabel('Dwell:')
|
||||||
|
dwelllabel.setToolTip(
|
||||||
|
"Pause to allow the spindle to reach its\n"
|
||||||
|
"speed before cutting."
|
||||||
|
)
|
||||||
|
dwelltime = QtGui.QLabel('Duration [sec.]:')
|
||||||
|
dwelltime.setToolTip(
|
||||||
|
"Number of second to dwell."
|
||||||
|
)
|
||||||
|
self.dwell_cb = FCCheckBox()
|
||||||
|
self.dwelltime_entry = FCEntry()
|
||||||
|
grid1.addWidget(dwelllabel, 0, 0)
|
||||||
|
grid1.addWidget(self.dwell_cb, 0, 1)
|
||||||
|
grid1.addWidget(dwelltime, 1, 0)
|
||||||
|
grid1.addWidget(self.dwelltime_entry, 1, 1)
|
||||||
|
|
||||||
# GO Button
|
# GO Button
|
||||||
self.export_gcode_button = QtGui.QPushButton('Export G-Code')
|
self.export_gcode_button = QtGui.QPushButton('Export G-Code')
|
||||||
self.export_gcode_button.setToolTip(
|
self.export_gcode_button.setToolTip(
|
||||||
|
|
12
camlib.py
12
camlib.py
|
@ -2720,7 +2720,8 @@ class CNCjob(Geometry):
|
||||||
self.feedrate = feedrate
|
self.feedrate = feedrate
|
||||||
self.tooldia = tooldia
|
self.tooldia = tooldia
|
||||||
self.unitcode = {"IN": "G20", "MM": "G21"}
|
self.unitcode = {"IN": "G20", "MM": "G21"}
|
||||||
self.pausecode = "G04 P1"
|
# TODO: G04 Does not exist. It's G4 and now we are handling in postprocessing.
|
||||||
|
#self.pausecode = "G04 P1"
|
||||||
self.feedminutecode = "G94"
|
self.feedminutecode = "G94"
|
||||||
self.absolutecode = "G90"
|
self.absolutecode = "G90"
|
||||||
self.gcode = ""
|
self.gcode = ""
|
||||||
|
@ -2818,7 +2819,7 @@ class CNCjob(Geometry):
|
||||||
else:
|
else:
|
||||||
gcode += "M03\n" # Spindle start
|
gcode += "M03\n" # Spindle start
|
||||||
|
|
||||||
gcode += self.pausecode + "\n"
|
#gcode += self.pausecode + "\n"
|
||||||
|
|
||||||
for tool in tools:
|
for tool in tools:
|
||||||
|
|
||||||
|
@ -2915,7 +2916,7 @@ class CNCjob(Geometry):
|
||||||
self.gcode += "M03 S%d\n" % int(self.spindlespeed) # Spindle start with configured speed
|
self.gcode += "M03 S%d\n" % int(self.spindlespeed) # Spindle start with configured speed
|
||||||
else:
|
else:
|
||||||
self.gcode += "M03\n" # Spindle start
|
self.gcode += "M03\n" # Spindle start
|
||||||
self.gcode += self.pausecode + "\n"
|
#self.gcode += self.pausecode + "\n"
|
||||||
|
|
||||||
## Iterate over geometry paths getting the nearest each time.
|
## Iterate over geometry paths getting the nearest each time.
|
||||||
log.debug("Starting G-Code...")
|
log.debug("Starting G-Code...")
|
||||||
|
@ -3031,6 +3032,8 @@ class CNCjob(Geometry):
|
||||||
:param gtext: A single string with g-code
|
:param gtext: A single string with g-code
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
log.debug("pre_parse()")
|
||||||
|
|
||||||
# Units: G20-inches, G21-mm
|
# Units: G20-inches, G21-mm
|
||||||
units_re = re.compile(r'^G2([01])')
|
units_re = re.compile(r'^G2([01])')
|
||||||
|
|
||||||
|
@ -3097,7 +3100,8 @@ class CNCjob(Geometry):
|
||||||
|
|
||||||
# TODO: Merge into single parser?
|
# TODO: Merge into single parser?
|
||||||
gobjs = self.pre_parse(self.gcode)
|
gobjs = self.pre_parse(self.gcode)
|
||||||
|
|
||||||
|
log.debug("gcode_parse(): pre_parse() done.")
|
||||||
# Last known instruction
|
# Last known instruction
|
||||||
current = {'X': 0.0, 'Y': 0.0, 'Z': 0.0, 'G': 0}
|
current = {'X': 0.0, 'Y': 0.0, 'Z': 0.0, 'G': 0}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue