# HG changeset patch # User mbayer # Date 1465038390 -7200 # Node ID e18b2a4ef561980d0874560346062d8952d8b2c0 # Parent 4c9bb8f93ae8110d4400f311172fcab371c81cd0 Remove empty lines output on bitmap plotter diff -r 4c9bb8f93ae8 -r e18b2a4ef561 printrun-src/printrun/laser.py --- a/printrun-src/printrun/laser.py Sat Jun 04 12:41:32 2016 +0200 +++ b/printrun-src/printrun/laser.py Sat Jun 04 13:06:30 2016 +0200 @@ -46,9 +46,9 @@ """ def __init__(self): self.lc_engrave_speed = 10 - # 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 + # 30mm/sec works for wood (regulate the output power to something between 10-30%) + # 30mm/sec for black anodized aluminum to get a light engraving @ 100% power + # 10mm/sec for black anodized aluminum to get maximum possible engraving! @ 100% power self.lc_travel_speed = 120 # BITMAP: @@ -86,9 +86,11 @@ self.MM_PIXEL = round(self.INCH / self.settings.lc_dpi, 4) self.STEPS_PIXEL = self.MM_PIXEL * 80 # mine is 80 steps/mm on XY - self.log("Lasercutter library initialized\n%d DPI (%f mm/pixel)" % (self.settings.lc_dpi, self.MM_PIXEL)) + self.log("Lasercutter library initialized\n%d DPI (%f mm/pixel)" % ( + self.settings.lc_dpi, self.MM_PIXEL)) if self.STEPS_PIXEL <= 5: - self.log("WARNING: STEPS PER PIXEL NEEDS TO BE > 5 (otherwise marlin joins lines): %f" % self.STEPS_PIXEL) + self.log("WARNING: STEPS PER PIXEL NEEDS TO BE > 5 (otherwise marlin joins lines): %f" % ( + self.STEPS_PIXEL)) self.log("Travel/Engrave speed: %d mm/sec, %d mm/sec" % ( self.settings.lc_travel_speed, self.settings.lc_engrave_speed) ) self.log("") @@ -142,16 +144,15 @@ fo.write("; Filename: %s\n%s" % (filename, GCODE_HEAD)) fo.write(";Start engraving the raster image: %dx%d points @ %d DPI = %.0fx%.0f mm\n\n" % ( - im.size[0], im.size[1], self.settings.lc_dpi, im.size[0] * self.MM_PIXEL, im.size[1] * self.MM_PIXEL) ) + im.size[0], im.size[1], self.settings.lc_dpi, + im.size[0] * self.MM_PIXEL, im.size[1] * self.MM_PIXEL) ) INVERT_Y = self.MM_PIXEL * (im.size[1] -1) * (-1) DIR = 1 travel_speed = self.settings.lc_travel_speed * 60 engrave_speed = self.settings.lc_engrave_speed * 60 * self.settings.lc_bitmap_speed_factor for X in range(im.size[0]): - # TODO: Skip empty rows!!! - fo.write("M400 ; X=%d printing row: direction %i\n" % (X, DIR)) - fo.write("G92 E0\n") + gcode_col = "" E = 0 last_bit = 1 # we engrave on black pixel = 0 START_Y = 0 @@ -185,21 +186,28 @@ E = E + self.MM_PIXEL * (Y - START_Y) else: E = E + self.MM_PIXEL * (START_Y - Y) - fo.write("G1 X%.4f Y%.4f E%.4f F%.4f\n" % (XMM, YMM, E * E_FACTOR, engrave_speed)) + gcode_col += "G1 X%.4f Y%.4f E%.4f F%.4f\n" % ( + XMM, YMM, E * E_FACTOR, engrave_speed) else: # bit value has changed! if bit == 0: # jump to start of line to write START_Y = Y - fo.write("G0 X%.4f Y%.4f F%.4f\n" % (XMM, YMM, travel_speed)) + gcode_col += "G0 X%.4f Y%.4f F%.4f\n" % ( + XMM, YMM, travel_speed) else: # end of line to write if DIR > 0: E = E + (self.MM_PIXEL * (Y - START_Y)) else: E = E + (self.MM_PIXEL * (START_Y - Y)) - fo.write("G1 X%.4f Y%.4f E%.4f F%.4f\n" % (XMM, YMM, E * E_FACTOR, engrave_speed)) + gcode_col += "G1 X%.4f Y%.4f E%.4f F%.4f\n" % ( + XMM, YMM, E * E_FACTOR, engrave_speed) last_bit = bit + if gcode_col <> "": + # we skip empty columns + fo.write("M400 ; X=%d printing row: direction %i\nG92 E0\n%s" % ( + X, DIR, gcode_col)) if self.settings.lc_change_dir: DIR = DIR * (-1) # change y direction on every X @@ -244,7 +252,8 @@ if last_cmd == "PD": OFFSET_X = coord[0] * -1 OFFSET_Y = coord[1] * -1 - fo.write("; PD PU detected, set coord offset %.4f x %.4f mm\n" % (OFFSET_X, OFFSET_Y)) + fo.write("; PD PU detected, set coord offset %.4f x %.4f mm\n" % ( + OFFSET_X, OFFSET_Y)) elif cmd == "PA" or cmd == "PR": # TODO: convert relative coordinates to absolute here! coord = action[2:].split(",") @@ -342,7 +351,8 @@ 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 F%.4f ; Move to start of shape\n" % (xs, ys, travel_speed)) + 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 @@ -353,14 +363,16 @@ xo = xs yo = ys 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)) + 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)) if shape_obj.xml_node.get('fill'): # Close the polygon e_distance = math.hypot(object_xs - xo, object_ys - yo) E = E + (e_distance) - 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)) + 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)) print "connecting filled path end to start" fo.write(GCODE_FOOT)