6 |
6 |
7 """ |
7 """ |
8 LASERCUT SETTINGS |
8 LASERCUT SETTINGS |
9 TODO: move to printrun settings |
9 TODO: move to printrun settings |
10 """ |
10 """ |
11 ENGRAVE_SPEED = 40 * 60 # mm/min |
11 ENGRAVE_SPEED = 10 * 60 # mm/min |
12 # 30mm/min works for wood (regulate the output power to something between 10-30%) |
12 # 30mm/min works for wood (regulate the output power to something between 10-30%) |
13 # 30mm/min for black anodized aluminum to get a light engraving @ 100% power |
13 # 30mm/min for black anodized aluminum to get a light engraving @ 100% power |
14 # 10mm/min for black anodized aluminum to get more "silver" @ 100% power |
14 # 10mm/min for black anodized aluminum to get more "silver" @ 100% power |
15 |
15 |
16 TRAVEL_SPEED = 60 * 60 |
16 TRAVEL_SPEED = 120 * 60 |
17 E_FACTOR = 0.1 |
17 E_FACTOR = 0.5 |
18 |
18 |
19 # BITMAP: |
19 # BITMAP: |
20 DPI = 300 |
20 DPI = 300 |
21 GREY_THRESHOLD = 0 |
21 GREY_THRESHOLD = 0 |
22 CHANGE_DIRECTION = True |
22 CHANGE_DIRECTION = True |
182 fo.write("G1 X%.4f Y%.4f E%.4f\n" % (XMM, YMM, E * E_FACTOR)) |
182 fo.write("G1 X%.4f Y%.4f E%.4f\n" % (XMM, YMM, E * E_FACTOR)) |
183 last_bit = bit |
183 last_bit = bit |
184 if CHANGE_DIRECTION: |
184 if CHANGE_DIRECTION: |
185 DIR = DIR * (-1) # change y direction on every X |
185 DIR = DIR * (-1) # change y direction on every X |
186 |
186 |
187 fo.write("M571 S0 E0\n") |
187 fo.write("""M400 ; Wait for all moves to finish |
188 fo.write("M501 ; undo all settings made\n") |
188 M571 S0 E0 |
189 #fo.write("G28 X0 Y0 ; Home position\n") |
189 M42 P28 S0 ; Force laser off! |
|
190 M501 ; undo all settings made |
|
191 """) |
190 |
192 |
191 fo.close() |
193 fo.close() |
192 |
194 |
193 if self.pronterwindow: |
195 if self.pronterwindow: |
194 self.log("") |
196 self.log("") |
248 coord[0] = (float(coord[0]) + OFFSET_X) * SCALE_FACTOR |
250 coord[0] = (float(coord[0]) + OFFSET_X) * SCALE_FACTOR |
249 coord[1] = (float(coord[1]) + OFFSET_Y) * SCALE_FACTOR |
251 coord[1] = (float(coord[1]) + OFFSET_Y) * SCALE_FACTOR |
250 if LASER_STATE: |
252 if LASER_STATE: |
251 EN = " E%.4f F%.4f" % ( |
253 EN = " E%.4f F%.4f" % ( |
252 E_FACTOR * math.hypot(coord[0] - last_coord[0], coord[1] - last_coord[1]), |
254 E_FACTOR * math.hypot(coord[0] - last_coord[0], coord[1] - last_coord[1]), |
253 ENGRAVE_SPEED) |
255 ENGRAVE_SPEED * 0.5 ) # 1/2 engraving speed |
254 else: |
256 else: |
255 EN = " F%.4f" % TRAVEL_SPEED |
257 EN = " F%.4f" % TRAVEL_SPEED |
256 |
258 |
257 fo.write("G%d X%.4f Y%.4f%s\n" % ( |
259 fo.write("G%d X%.4f Y%.4f%s\n" % ( |
258 LASER_STATE, coord[0], coord[1], EN) ) |
260 LASER_STATE, coord[0], coord[1], EN) ) |
264 else: |
266 else: |
265 print "UNKNOWN: %s" % action |
267 print "UNKNOWN: %s" % action |
266 last_cmd = cmd |
268 last_cmd = cmd |
267 |
269 |
268 |
270 |
269 fo.write("M571 S0 E0\n") |
271 fo.write("""M400 ; Wait for all moves to finish |
270 fo.write("M501 ; undo all settings made\n") |
272 M571 S0 E0 |
271 #fo.write("G28 X0 Y0 ; Home position\n") |
273 M42 P28 S0 ; Force laser off! |
|
274 M501 ; undo all settings made |
|
275 """) |
272 |
276 |
273 fi.close() |
277 fi.close() |
274 fo.close() |
278 fo.close() |
275 |
279 |
276 if self.pronterwindow: |
280 if self.pronterwindow: |
277 self.log("") |
281 self.log("") |
278 self.pronterwindow.load_gcode_async(filename + '.g') |
282 self.pronterwindow.load_gcode_async(filename + '.g') |
279 |
283 |
280 |
284 |
281 def svg2gcode(self, filename, bed_max_x = 200, bed_max_y = 200, smoothness = 0.2): |
285 def svg2gcode(self, filename, bed_max_x = 50, bed_max_y = 50, smoothness = 0.2): |
282 self.log("Generating paths from SVG...") |
286 self.log("Generating paths from SVG...") |
283 |
287 |
284 preamble = """ |
288 preamble = """ |
285 ; Filename: %s |
289 ; Filename: %s |
286 ; GCode generated by bitplotter one-night-quick-hack script (marlin code flavour) |
290 ; GCode generated by bitplotter one-night-quick-hack script (marlin code flavour) |
301 |
305 |
302 """ % (filename, TRAVEL_SPEED, ENGRAVE_SPEED) |
306 """ % (filename, TRAVEL_SPEED, ENGRAVE_SPEED) |
303 self.log("Travel/Engrave speed: %d mm/sec, %d mm/sec" % ( |
307 self.log("Travel/Engrave speed: %d mm/sec, %d mm/sec" % ( |
304 TRAVEL_SPEED / 60, ENGRAVE_SPEED / 60) ) |
308 TRAVEL_SPEED / 60, ENGRAVE_SPEED / 60) ) |
305 |
309 |
306 postamble = "" |
310 postamble = """M400 ; Wait for all moves to finish |
|
311 M571 S0 E0 |
|
312 M42 P28 S0 ; Force laser off! |
|
313 M501 ; undo all settings made |
|
314 """ |
307 shape_preamble = "G92 E0\n" |
315 shape_preamble = "G92 E0\n" |
308 shape_postamble = """M571 S0 E0 |
316 shape_postamble = "" |
309 M501 ; undo all settings made |
|
310 |
|
311 """ |
|
312 |
317 |
313 |
318 |
314 """ |
319 """ |
315 Used to control the smoothness/sharpness of the curves. |
320 Used to control the smoothness/sharpness of the curves. |
316 Smaller the value greater the sharpness. Make sure the |
321 Smaller the value greater the sharpness. Make sure the |
356 shape_obj = shape_class(elem) |
361 shape_obj = shape_class(elem) |
357 d = shape_obj.d_path() |
362 d = shape_obj.d_path() |
358 m = shape_obj.transformation_matrix() |
363 m = shape_obj.transformation_matrix() |
359 |
364 |
360 if d: |
365 if d: |
361 fo.write("; printing shape: %s\n" % (tag_suffix)) |
366 fo.write("M400 ; wait for moves finish, then printing shape: %s\n" % (tag_suffix)) |
362 E = 0 |
367 E = 0 |
363 xo = 0 |
368 xo = 0 |
364 yo = 0 |
369 yo = 0 |
365 fo.write(shape_preamble) |
370 fo.write(shape_preamble) |
366 p = point_generator(d, m, smoothness) |
371 p = point_generator(d, m, smoothness) |
367 start = True |
372 start = True |
368 for x,y,pen in p: |
373 for x,y,pen in p: |
369 y = height - y |
374 y = height - y |
370 xs = scale_x * x |
375 xs = scale_x * x |
371 ys = scale_y * y |
376 ys = scale_y * y |
|
377 if xo == xs and yo == ys: continue |
|
378 |
372 if not pen: start = True |
379 if not pen: start = True |
373 if xs >= 0 and xs <= bed_max_x and ys >= 0 and ys <= bed_max_y: |
380 if xs >= 0 and xs <= bed_max_x and ys >= 0 and ys <= bed_max_y: |
374 if start: |
381 if start: |
375 fo.write("G0 X%0.2f Y%0.2f ; Move to start of shape\n" % (xs, ys)) |
382 fo.write("G0 X%0.2f Y%0.2f F%.4f ; Move to start of shape\n" % (xs, ys, TRAVEL_SPEED)) |
376 start = False |
383 start = False |
377 xo = xs |
384 xo = xs |
378 yo = ys |
385 yo = ys |
379 else: |
386 else: |
380 e_distance = math.hypot(xs - xo, ys - yo) |
387 e_distance = math.hypot(xs - xo, ys - yo) |
381 xo = xs |
388 xo = xs |
382 yo = ys |
389 yo = ys |
383 E = E + (MM_PIXEL * e_distance) |
390 E = E + (e_distance) |
384 fo.write("G1 X%0.2f Y%0.2f E%.4f\n" % (xs, ys, E * E_FACTOR)) |
391 fo.write("G1 X%0.2f Y%0.2f E%.4f F%.4f\n" % (xs, ys, E * E_FACTOR, ENGRAVE_SPEED)) |
385 else: |
392 else: |
386 self.log("Position outside print dimension: %d, %d" % (xs, ys)) |
393 self.log("Position outside print dimension: %d, %d" % (xs, ys)) |
387 fo.write(shape_postamble) |
394 fo.write(shape_postamble) |
388 |
395 |
389 fo.write(postamble) |
396 fo.write(postamble) |