printrun-src/printrun/laser.py

changeset 42
ea4c43494a19
parent 37
926424f97c8e
child 43
f7e9bd735ce1
--- a/printrun-src/printrun/laser.py	Thu May 30 18:10:01 2019 +0200
+++ b/printrun-src/printrun/laser.py	Thu May 30 19:02:52 2019 +0200
@@ -163,6 +163,8 @@
         engrave_speed = self.settings.lc_engrave_speed * 60 * self.settings.lc_bitmap_speed_factor
         for X in range(im.size[0]):
             gcode_col = ""
+            first_ymm = None
+            first_xmm = None
             E = 0
             last_bit = 1 # we engrave on black pixel = 0
             START_Y = 0
@@ -176,6 +178,7 @@
             for Y in range(range_start, range_stop, DIR):
                 YMM = abs((Y * self.MM_PIXEL) + INVERT_Y)
                 XMM = X * self.MM_PIXEL
+
                 #print "X %d Y %d" % (X, Y)
                 bit = self.pixel2bit(pix[X, Y])
                 if self.settings.lc_invert_cut:
@@ -198,13 +201,21 @@
                                 E = E + self.MM_PIXEL * (START_Y - Y)
                             gcode_col += "G1 X%.4f Y%.4f E%.4f F%.4f\n" % (
                                 XMM, YMM, E * E_FACTOR, engrave_speed)
+                            if not first_xmm:
+                                first_xmm = XMM + 0.1 # little offset needed!
+                                first_ymm = YMM * 1
                 else:
+                    if not first_xmm:
+                        first_xmm = XMM + 0.1 # little offset needed!
+                        first_ymm = YMM * 1
                     # bit value has changed!
                     if bit == 0:
                         # jump to start of line to write
                         START_Y = Y
                         gcode_col += "G0 X%.4f Y%.4f F%.4f\n" % (
                             XMM, YMM, travel_speed)
+                        last_xmm = None
+                        last_ymm = None
                     else:
                         # end of line to write
                         if DIR > 0:
@@ -216,6 +227,11 @@
                 last_bit = bit
             if gcode_col <> "":
                 # we skip empty columns
+                # place last position as G0 to be sure to switch off laser immediately at finish of the line!
+                if first_xmm:
+                    fo.write("G0 X%.4f Y%.4f F%.4f ; force laser off\n" % (
+                            first_xmm, first_ymm, travel_speed))
+
                 fo.write("M400 ; X=%d printing row: direction %i\nG92 E0\n%s" % (
                     X, DIR, gcode_col))
             if self.settings.lc_change_dir:

mercurial