printrun-src/printrun/laser.py

changeset 42
ea4c43494a19
parent 37
926424f97c8e
child 43
f7e9bd735ce1
equal deleted inserted replaced
41:08d027d2a532 42:ea4c43494a19
161 DIR = 1 161 DIR = 1
162 travel_speed = self.settings.lc_travel_speed * 60 162 travel_speed = self.settings.lc_travel_speed * 60
163 engrave_speed = self.settings.lc_engrave_speed * 60 * self.settings.lc_bitmap_speed_factor 163 engrave_speed = self.settings.lc_engrave_speed * 60 * self.settings.lc_bitmap_speed_factor
164 for X in range(im.size[0]): 164 for X in range(im.size[0]):
165 gcode_col = "" 165 gcode_col = ""
166 first_ymm = None
167 first_xmm = None
166 E = 0 168 E = 0
167 last_bit = 1 # we engrave on black pixel = 0 169 last_bit = 1 # we engrave on black pixel = 0
168 START_Y = 0 170 START_Y = 0
169 if DIR > 0: 171 if DIR > 0:
170 range_start = 0 172 range_start = 0
174 range_stop = -1 176 range_stop = -1
175 177
176 for Y in range(range_start, range_stop, DIR): 178 for Y in range(range_start, range_stop, DIR):
177 YMM = abs((Y * self.MM_PIXEL) + INVERT_Y) 179 YMM = abs((Y * self.MM_PIXEL) + INVERT_Y)
178 XMM = X * self.MM_PIXEL 180 XMM = X * self.MM_PIXEL
181
179 #print "X %d Y %d" % (X, Y) 182 #print "X %d Y %d" % (X, Y)
180 bit = self.pixel2bit(pix[X, Y]) 183 bit = self.pixel2bit(pix[X, Y])
181 if self.settings.lc_invert_cut: 184 if self.settings.lc_invert_cut:
182 if bit == 0: 185 if bit == 0:
183 bit = 1 186 bit = 1
196 E = E + self.MM_PIXEL * (Y - START_Y) 199 E = E + self.MM_PIXEL * (Y - START_Y)
197 else: 200 else:
198 E = E + self.MM_PIXEL * (START_Y - Y) 201 E = E + self.MM_PIXEL * (START_Y - Y)
199 gcode_col += "G1 X%.4f Y%.4f E%.4f F%.4f\n" % ( 202 gcode_col += "G1 X%.4f Y%.4f E%.4f F%.4f\n" % (
200 XMM, YMM, E * E_FACTOR, engrave_speed) 203 XMM, YMM, E * E_FACTOR, engrave_speed)
204 if not first_xmm:
205 first_xmm = XMM + 0.1 # little offset needed!
206 first_ymm = YMM * 1
201 else: 207 else:
208 if not first_xmm:
209 first_xmm = XMM + 0.1 # little offset needed!
210 first_ymm = YMM * 1
202 # bit value has changed! 211 # bit value has changed!
203 if bit == 0: 212 if bit == 0:
204 # jump to start of line to write 213 # jump to start of line to write
205 START_Y = Y 214 START_Y = Y
206 gcode_col += "G0 X%.4f Y%.4f F%.4f\n" % ( 215 gcode_col += "G0 X%.4f Y%.4f F%.4f\n" % (
207 XMM, YMM, travel_speed) 216 XMM, YMM, travel_speed)
217 last_xmm = None
218 last_ymm = None
208 else: 219 else:
209 # end of line to write 220 # end of line to write
210 if DIR > 0: 221 if DIR > 0:
211 E = E + (self.MM_PIXEL * (Y - START_Y)) 222 E = E + (self.MM_PIXEL * (Y - START_Y))
212 else: 223 else:
214 gcode_col += "G1 X%.4f Y%.4f E%.4f F%.4f\n" % ( 225 gcode_col += "G1 X%.4f Y%.4f E%.4f F%.4f\n" % (
215 XMM, YMM, E * E_FACTOR, engrave_speed) 226 XMM, YMM, E * E_FACTOR, engrave_speed)
216 last_bit = bit 227 last_bit = bit
217 if gcode_col <> "": 228 if gcode_col <> "":
218 # we skip empty columns 229 # we skip empty columns
230 # place last position as G0 to be sure to switch off laser immediately at finish of the line!
231 if first_xmm:
232 fo.write("G0 X%.4f Y%.4f F%.4f ; force laser off\n" % (
233 first_xmm, first_ymm, travel_speed))
234
219 fo.write("M400 ; X=%d printing row: direction %i\nG92 E0\n%s" % ( 235 fo.write("M400 ; X=%d printing row: direction %i\nG92 E0\n%s" % (
220 X, DIR, gcode_col)) 236 X, DIR, gcode_col))
221 if self.settings.lc_change_dir: 237 if self.settings.lc_change_dir:
222 DIR = DIR * (-1) # change y direction on every X 238 DIR = DIR * (-1) # change y direction on every X
223 239

mercurial