51 G0 X0 Y0 F%d ; Set moving speed TRAVEL_SPEED |
51 G0 X0 Y0 F%d ; Set moving speed TRAVEL_SPEED |
52 G1 X0 Y0 F%d ; Set linear engraving speed ENGRAVE_SPEED |
52 G1 X0 Y0 F%d ; Set linear engraving speed ENGRAVE_SPEED |
53 |
53 |
54 """ % (TRAVEL_SPEED, ENGRAVE_SPEED) |
54 """ % (TRAVEL_SPEED, ENGRAVE_SPEED) |
55 |
55 |
56 GCODE_FOOT = """M400 ; Wait for all moves to finish |
56 GCODE_FOOT = """G0 X0 Y0 F%.4f |
|
57 M400 ; Wait for all moves to finish |
57 M571 S0 E0 |
58 M571 S0 E0 |
58 M42 P28 S0 ; Force laser off! |
59 M42 P28 S0 ; Force laser off! |
59 M501 ; undo all settings made |
60 M501 ; undo all settings made |
60 """ |
61 """ % (TRAVEL_SPEED) |
61 |
62 |
62 from PIL import Image |
63 from PIL import Image |
63 import sys |
64 import sys |
64 |
65 |
65 # Imports for SVG |
66 # Imports for SVG |
75 parameters: log = logger function (fuction has to accept a string) |
76 parameters: log = logger function (fuction has to accept a string) |
76 """ |
77 """ |
77 def __init__(self, pronterwindow = None): |
78 def __init__(self, pronterwindow = None): |
78 if pronterwindow: |
79 if pronterwindow: |
79 self.pronterwindow = pronterwindow |
80 self.pronterwindow = pronterwindow |
80 self.log = pronterwindow.log |
81 #self.log = pronterwindow.log |
|
82 self.log = self.log_print |
81 self.pronterwindow.clear_log(None) |
83 self.pronterwindow.clear_log(None) |
82 else: |
84 else: |
83 self.pronterwindow = None |
85 self.pronterwindow = None |
84 self.log = lambda : None |
86 self.log = lambda : None |
85 self.log("Lasercutter library initialized\n%d DPI (%f mm/pixel)" % (DPI, MM_PIXEL)) |
87 self.log("Lasercutter library initialized\n%d DPI (%f mm/pixel)" % (DPI, MM_PIXEL)) |
87 self.log("WARNING: STEPS PER PIXEL NEEDS TO BE > 5 (otherwise marlin joins lines): %f" % STEPS_PIXEL) |
89 self.log("WARNING: STEPS PER PIXEL NEEDS TO BE > 5 (otherwise marlin joins lines): %f" % STEPS_PIXEL) |
88 self.log("Travel/Engrave speed: %d mm/sec, %d mm/sec" % ( |
90 self.log("Travel/Engrave speed: %d mm/sec, %d mm/sec" % ( |
89 TRAVEL_SPEED / 60, ENGRAVE_SPEED / 60) ) |
91 TRAVEL_SPEED / 60, ENGRAVE_SPEED / 60) ) |
90 self.log("") |
92 self.log("") |
91 |
93 |
|
94 def log_print(self, msg): |
|
95 print(msg) |
|
96 |
92 |
97 |
93 def pixel2bit(self, pixel, threshold=128): |
98 def pixel2bit(self, pixel, threshold=128): |
94 """Convert the pixel value to a bit.""" |
99 """Convert the pixel value to a bit.""" |
95 # some really weird stuff here ;-P |
100 # some really weird stuff here ;-P |
96 |
101 |
331 if xs >= 0 and xs <= bed_max_x and ys >= 0 and ys <= bed_max_y: |
336 if xs >= 0 and xs <= bed_max_x and ys >= 0 and ys <= bed_max_y: |
332 if start: |
337 if start: |
333 fo.write("G0 X%0.2f Y%0.2f F%.4f ; Move to start of shape\n" % (xs, ys, TRAVEL_SPEED)) |
338 fo.write("G0 X%0.2f Y%0.2f F%.4f ; Move to start of shape\n" % (xs, ys, TRAVEL_SPEED)) |
334 start = False |
339 start = False |
335 xo = xs |
340 xo = xs |
336 yo = ys |
341 yo = ys |
|
342 object_xs = xs |
|
343 object_ys = ys |
337 else: |
344 else: |
338 e_distance = math.hypot(xs - xo, ys - yo) |
345 e_distance = math.hypot(xs - xo, ys - yo) |
339 xo = xs |
346 xo = xs |
340 yo = ys |
347 yo = ys |
341 E = E + (e_distance) |
348 E = E + (e_distance) |
342 fo.write("G1 X%0.2f Y%0.2f E%.4f F%.4f\n" % (xs, ys, E * E_FACTOR, ENGRAVE_SPEED)) |
349 fo.write("G1 X%0.2f Y%0.2f E%.4f F%.4f\n" % (xs, ys, E * E_FACTOR, ENGRAVE_SPEED)) |
343 else: |
350 else: |
344 self.log("Position outside print dimension: %d, %d" % (xs, ys)) |
351 self.log("Position outside print dimension: %d, %d" % (xs, ys)) |
|
352 if shape_obj.xml_node.get('fill'): |
|
353 # Close the polygon |
|
354 e_distance = math.hypot(object_xs - xo, object_ys - yo) |
|
355 E = E + (e_distance) |
|
356 fo.write("G1 X%0.2f Y%0.2f E%.4f F%.4f ; Close the object polygon\n" % (object_xs, object_ys, E * E_FACTOR, ENGRAVE_SPEED)) |
|
357 print "connecting polycommon path end to start" |
|
358 |
345 fo.write(shape_postamble) |
359 fo.write(shape_postamble) |
346 |
360 |
347 fo.write(GCODE_FOOT) |
361 fo.write(GCODE_FOOT) |
348 fo.close() |
362 fo.close() |
349 |
363 |