printrun-src/printrun/laser.py

changeset 19
234037fbca4b
parent 18
11f6d97f83b0
child 20
03b34402d405
--- a/printrun-src/printrun/laser.py	Fri Jun 03 10:06:09 2016 +0200
+++ b/printrun-src/printrun/laser.py	Fri Jun 03 21:14:09 2016 +0200
@@ -8,13 +8,13 @@
 LASERCUT SETTINGS
 TODO: move to printrun settings
 """
-ENGRAVE_SPEED = 40 * 60 # mm/min
+ENGRAVE_SPEED = 10 * 60 # mm/min
 # 30mm/min works for wood (regulate the output power to something between 10-30%)
 # 30mm/min for black anodized aluminum to get a light engraving @ 100% power
 # 10mm/min for black anodized aluminum to get more "silver" @ 100% power
 
-TRAVEL_SPEED = 60 * 60
-E_FACTOR = 0.1
+TRAVEL_SPEED = 120 * 60
+E_FACTOR = 0.5
 
 # BITMAP:
 DPI = 300
@@ -184,9 +184,11 @@
             if CHANGE_DIRECTION:
                 DIR = DIR * (-1) # change y direction on every X
 
-        fo.write("M571 S0 E0\n")
-        fo.write("M501 ; undo all settings made\n")
-        #fo.write("G28 X0 Y0 ; Home position\n")
+        fo.write("""M400 ; Wait for all moves to finish
+M571 S0 E0
+M42 P28 S0 ; Force laser off!
+M501 ; undo all settings made
+""")
 
         fo.close()
 
@@ -250,7 +252,7 @@
                         if LASER_STATE:
                             EN = " E%.4f F%.4f" % (
                               E_FACTOR *  math.hypot(coord[0] - last_coord[0], coord[1] - last_coord[1]),
-                              ENGRAVE_SPEED) 
+                              ENGRAVE_SPEED * 0.5 ) # 1/2 engraving speed
                         else:
                             EN = " F%.4f" % TRAVEL_SPEED
                             
@@ -266,9 +268,11 @@
                     last_cmd = cmd            
     
 
-        fo.write("M571 S0 E0\n")
-        fo.write("M501 ; undo all settings made\n")
-        #fo.write("G28 X0 Y0 ; Home position\n")
+        fo.write("""M400 ; Wait for all moves to finish
+M571 S0 E0
+M42 P28 S0 ; Force laser off!
+M501 ; undo all settings made
+""")
 
         fi.close()
         fo.close()    
@@ -278,7 +282,7 @@
             self.pronterwindow.load_gcode_async(filename + '.g')
 
 
-    def svg2gcode(self, filename, bed_max_x = 200, bed_max_y = 200, smoothness = 0.2):
+    def svg2gcode(self, filename, bed_max_x = 50, bed_max_y = 50, smoothness = 0.2):
         self.log("Generating paths from SVG...")        
 
         preamble = """
@@ -303,12 +307,13 @@
         self.log("Travel/Engrave speed: %d mm/sec, %d mm/sec" % (
             TRAVEL_SPEED / 60, ENGRAVE_SPEED / 60) )
 
-        postamble = ""
+        postamble = """M400 ; Wait for all moves to finish
+M571 S0 E0
+M42 P28 S0 ; Force laser off!
+M501 ; undo all settings made
+"""
         shape_preamble = "G92 E0\n"
-        shape_postamble =  """M571 S0 E0
-M501 ; undo all settings made
-
-"""
+        shape_postamble = ""
 
 
         """ 
@@ -358,7 +363,7 @@
                 m = shape_obj.transformation_matrix()
 
                 if d:
-                    fo.write("; printing shape: %s\n" % (tag_suffix))
+                    fo.write("M400 ; wait for moves finish, then printing shape: %s\n" % (tag_suffix))
                     E = 0
                     xo = 0
                     yo = 0
@@ -369,10 +374,12 @@
                         y = height - y
                         xs = scale_x * x
                         ys = scale_y * y
+                        if xo == xs and yo == ys: continue
+
                         if not pen: start = True 
                         if xs >= 0 and xs <= bed_max_x and ys >= 0 and ys <= bed_max_y:
                             if start:
-                                fo.write("G0 X%0.2f Y%0.2f ; Move to start of shape\n" % (xs, ys))
+                                fo.write("G0 X%0.2f Y%0.2f F%.4f ; Move to start of shape\n" % (xs, ys, TRAVEL_SPEED))
                                 start = False
                                 xo = xs
                                 yo = ys                                
@@ -380,8 +387,8 @@
                                 e_distance = math.hypot(xs - xo, ys - yo)
                                 xo = xs
                                 yo = ys                                
-                                E = E + (MM_PIXEL * e_distance)
-                                fo.write("G1 X%0.2f Y%0.2f E%.4f\n" % (xs, ys, E * E_FACTOR))
+                                E = E + (e_distance)
+                                fo.write("G1 X%0.2f Y%0.2f E%.4f F%.4f\n" % (xs, ys, E * E_FACTOR, ENGRAVE_SPEED))
                         else:
                             self.log("Position outside print dimension: %d, %d" % (xs, ys)) 
                     fo.write(shape_postamble)

mercurial