Wed, 20 Jan 2021 10:17:01 +0100
updated pronterface.py losing my own changes
4 | 1 | import math |
2 | ||
3 | INCH = 25.4 # mm | |
8 | 4 | STEPS_PER_MM = 80 # hardware: steps/mm on XY |
4 | 5 | |
6 | class Gcode(object): | |
8 | 7 | def __init__(self, scale=1.0, travel_speed=20, engrave_speed=20): |
4 | 8 | self.dpi = 300 |
9 | self.e_factor = 0.1 | |
10 | self.mm_pixel = round(INCH / self.dpi, 4) | |
11 | ||
12 | self.lines = [] | |
13 | self.dist_start = (0, 0) | |
14 | self.dist = 0.0 | |
15 | ||
16 | self.scale = scale | |
17 | self.travel_speed = travel_speed * 60 | |
18 | self.engrave_speed = engrave_speed * 60 | |
19 | ||
8 | 20 | self._check_resolution() |
21 | ||
22 | def _check_resolution(self): | |
23 | steps_pixel = self.mm_pixel * STEPS_PER_MM | |
24 | print "Resolution is %f mm per pixel" % self.mm_pixel | |
25 | if steps_pixel <= 5: | |
26 | print "Warning: Steps per pixel (needs to be > 5, otherwise marlin joins lines): %f" % steps_pixel | |
27 | ||
4 | 28 | def _dimensions(self, x, y): |
29 | x = self.mm_pixel * x | |
30 | y = self.mm_pixel * y | |
31 | if self.scale != 1.0: | |
32 | x = x * self.scale | |
33 | y = y * self.scale | |
34 | return (x, y) | |
35 | ||
8 | 36 | def comment(self, msg): |
37 | self.lines.append("; %s" % msg) | |
38 | ||
4 | 39 | def move(self, x, y): |
40 | x, y = self._dimensions(x, y) | |
41 | if self.e_factor > 0: | |
42 | self.dist_start = (x, y) | |
43 | self.dist = 0.0 | |
44 | self.lines.append("G92 E0") # reset extruder length | |
45 | self.lines.append( | |
46 | "G0 X%.4f Y%.4f F%s" % (x, y, self.travel_speed) | |
47 | ) | |
48 | ||
49 | def engrave(self, x, y): | |
50 | x, y = self._dimensions(x, y) | |
51 | if self.e_factor > 0: | |
52 | self.dist += abs(math.hypot(x - self.dist_start[0], y - self.dist_start[1])) | |
53 | e = "E%.4f" % (self.e_factor * self.dist) | |
54 | self.dist_start = (x, y) | |
55 | else: | |
56 | e = "" | |
57 | self.lines.append( | |
58 | "G1 X%.4f Y%.4f %s F%s" % (x, y, e, self.engrave_speed) | |
59 | ) | |
60 | ||
61 | ||
62 | def write(self, filename): | |
63 | # write gcode file | |
64 | fout = open(filename, "w") | |
65 | ||
8 | 66 | fout.write("""; Filename: %s |
67 | ; GCode generated by one-night-and-several-days-not-so-quick-hack-script (marlin code flavour) | |
68 | ; https://neo-soft.org/hg-public/lasercut-scripts | |
4 | 69 | G21 ; Metric |
70 | ; We assume Z is in focus height and laser head is focus at bottom left of image! | |
71 | G92 X0 Y0 E0 ; set zero position - new origin | |
72 | G90 ; absolute positioning | |
73 | M82 ; Set extruder (laser) to absolute positioning | |
74 | M201 X1000 Y1000 E500 ; Set acceleration | |
75 | M203 X1000 Y1000 Z4 E10 ; Set max feedrate | |
76 | M209 S0 ; disable firmware retraction, we dont want to burn holes... | |
77 | M302 ; Allow cold extrudes - doesnt matter because we hack the extruder physically off with the M571 E mod | |
78 | M571 S1 E1 ; Activate Laser output on extrusion, but block real motor movement! | |
79 | G0 X0 Y0 F%.1f ; Set moving speed | |
80 | G1 X0 Y0 F%.1f ; Set engrave speed | |
81 | ||
82 | """ % (filename, self.travel_speed, self.engrave_speed)) | |
83 | ||
84 | for g in self.lines: | |
85 | fout.write(g + "\n") | |
86 | fout.close() |