Added support for multiple cutting passes with automatic Z refocusing

Sat, 23 Sep 2017 08:51:58 +0200

author
mdd
date
Sat, 23 Sep 2017 08:51:58 +0200
changeset 33
eee51ca7cbe7
parent 32
0abfa4642776
child 34
654a41b13258

Added support for multiple cutting passes with automatic Z refocusing

printrun-src/printrun/gui/controls.py file | annotate | diff | comparison | revisions
printrun-src/printrun/laser.py file | annotate | diff | comparison | revisions
printrun-src/printrun/pronterface.py file | annotate | diff | comparison | revisions
--- a/printrun-src/printrun/gui/controls.py	Fri Sep 22 17:40:08 2017 +0200
+++ b/printrun-src/printrun/gui/controls.py	Sat Sep 23 08:51:58 2017 +0200
@@ -73,6 +73,12 @@
         "extrude": (3, 0),
         "reverse": (3, 2),
         "lasercut": (lasercut_base_line, 0),
+        "lasercut_material_thickness": (lasercut_base_line+1, 4),
+        "lasercut_material_thickness_label": (lasercut_base_line+1, 0),
+        "lasercut_pass_count": (lasercut_base_line+2, 4),
+        "lasercut_pass_count_label": (lasercut_base_line+2, 0),
+        "lasercut_pass_zdiff": (lasercut_base_line+3, 4),
+        "lasercut_pass_zdiff_label": (lasercut_base_line+3, 0),
     }
 
     span_mapping = {
@@ -310,6 +316,17 @@
     root.printerControls.append(root.lc_optionsbtn)
     add("lasercut", root.lc_optionsbtn, flag = wx.EXPAND)
 
+    root.lc_pass_count = speed_spin = FloatSpin(parentpanel, -1, value = 1, min_val = 1, max_val = 10, digits = 0, style = wx.ALIGN_LEFT, size = (80, -1))
+    add("lasercut_pass_count", root.lc_pass_count)
+    add("lasercut_pass_count_label", wx.StaticText(parentpanel, -1, _("Number of cutting passes:")), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
+
+    root.lc_pass_zdiff = speed_spin = FloatSpin(parentpanel, -1, increment = 0.1, value = -1, min_val = -2, max_val = 2, digits = 1, style = wx.ALIGN_LEFT, size = (80, -1))
+    add("lasercut_pass_zdiff", root.lc_pass_zdiff)
+    add("lasercut_pass_zdiff_label", wx.StaticText(parentpanel, -1, _("Z movement after each cut:")), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
+
+    root.lc_material_thickness = speed_spin = FloatSpin(parentpanel, -1, increment = 0.1, value = 4, min_val = 0, max_val = 75, digits = 1, style = wx.ALIGN_LEFT, size = (80, -1))
+    add("lasercut_material_thickness", root.lc_material_thickness)
+    add("lasercut_material_thickness_label", wx.StaticText(parentpanel, -1, _("Material Thickness:")), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
 
     # Extrusion controls #
 
--- a/printrun-src/printrun/laser.py	Fri Sep 22 17:40:08 2017 +0200
+++ b/printrun-src/printrun/laser.py	Sat Sep 23 08:51:58 2017 +0200
@@ -36,12 +36,12 @@
 """
 
 GCODE_FOOT = """
+M400 ; Wait for all moves to finish
 M42 P28 S0 ; Force laser off!
 M85 S30 ; re-enable idle hold timeout
 G0 X0 Y0 F%.4f ; Move back to origin
-M400 ; Wait for all moves to finish
-M571 S0 E0 ; disable extruder firmware hack
-M501 ; undo all settings made
+; M571 S0 E0 ; disable extruder firmware hack
+; M501 ; undo all settings made
 """ % (100*60)
 
 
@@ -421,7 +421,7 @@
 
                     for sp in p:
                             cspsubdiv.subdiv( sp, smoothness)
-                            self.log("Laser ON at: " + repr(sp[0][0]))
+                            #self.log("Laser ON at: " + repr(sp[0][0]))
                             x = sp[0][0][0] + ofs_x
                             y = sp[0][0][1] + ofs_y
                             y = height - y # invert the bed
@@ -467,7 +467,7 @@
 
 
                                 #print "   Point: ", end_pt[0], end_pt[1], pen
-                            self.log("Laser OFF at: " + repr(sp[-1][-1]))
+                            #self.log("Laser OFF at: " + repr(sp[-1][-1]))
 
                     if shape_obj.xml_node.get('fill'):
                         # Close the polygon
--- a/printrun-src/printrun/pronterface.py	Fri Sep 22 17:40:08 2017 +0200
+++ b/printrun-src/printrun/pronterface.py	Sat Sep 23 08:51:58 2017 +0200
@@ -257,6 +257,39 @@
         if self.settings.monitor:
             self.update_monitor()
 
+        self.pass_current = 1
+
+    #  --------------------------------------------------------------
+    #  Lasercutter methods
+    #  --------------------------------------------------------------
+
+
+    def endcb_lasercut(self):
+        # LASERCUT: Now check if we should do another print pass?
+        pass_count = self.lc_pass_count.GetValue()
+        if pass_count > 1:
+            time.sleep(0.5)
+            if self.pass_current < pass_count:
+                self.pass_current += 1
+                self.log("Starting lasercut pass # %i of %i" % (self.pass_current, pass_count))
+                if self.lc_pass_zdiff.GetValue() != 0:
+                    # move Z focus
+                    new_z = self.settings.lc_z_focus + self.lc_material_thickness.GetValue() + (self.lc_pass_zdiff.GetValue() * self.pass_current)
+                    self.log("Re-Positioning laser focus by %.1f mm to %.1f" % (self.lc_pass_zdiff.GetValue(), new_z))
+                    line = self.precmd("G1 Z%.2f" % (new_z))
+                    self.onecmd(line)
+                    time.sleep(0.5)
+
+                # "click" print button again
+                tmp = self.pass_current
+                self.printfile(None)
+                self.pass_current = tmp
+            else:
+                self.log("Resetting Z axis to initial focus")
+                line = self.precmd("G1 Z%.2f" % (self.settings.lc_z_focus + self.lc_material_thickness.GetValue()))
+                self.onecmd(line)
+
+
     #  --------------------------------------------------------------
     #  Main interface handling
     #  --------------------------------------------------------------
@@ -863,6 +896,7 @@
         self.settings._add(StaticTextSetting("separator_lc_general", "General laser settings", "", group = "Laser"))
         self.settings._add(SpinSetting("lc_travel_speed", 120, 1, 300, "Travel speed in mm/s", "", "Laser"), self.update_lc_settings)
         self.settings._add(SpinSetting("lc_engrave_speed", 10, 1, 300, "Engrave speed in mm/s", "", "Laser"), self.update_lc_settings)
+        self.settings._add(SpinSetting("lc_z_focus", 16, -80, 80, "Laser Z focus position", "", "Laser"), self.update_lc_settings)
 
         self.settings._add(StaticTextSetting("separator_lc_bitmap", "PNG Bitmap processing", "", group = "Laser"))
         self.settings._add(FloatSpinSetting("lc_bitmap_speed_factor", 1.0, 0.1, 2.0, "Engrave speed factor", "", "Laser"), self.update_lc_settings)
@@ -1198,6 +1232,7 @@
         self.sdprinting = False
         self.on_startprint()
         self.p.startprint(self.fgcode)
+        self.pass_current = 1
 
     def sdprintfile(self, event):
         self.extra_print_time = 0
@@ -1600,6 +1635,8 @@
             wx.CallAfter(self.printbtn.SetLabel, _("Print"))
             wx.CallAfter(self.toolbarsizer.Layout)
 
+            wx.CallAfter(self.endcb_lasercut)
+
     def online(self):
         """Callback when printer goes online"""
         self.log(_("Printer is now online."))

mercurial