| 1 |
|
| 2 |
# very simple G-code writer. |
| 3 |
# Anders Wallin 2012 |
| 4 |
|
| 5 |
clearance_height= 20 |
| 6 |
feed_height = 10 |
| 7 |
feed = 200 |
| 8 |
plunge_feed = 100 |
| 9 |
metric = True |
| 10 |
|
| 11 |
def line_to(x,y,z): |
| 12 |
print("G1 X% 8.6f Y% 8.6f Z% 8.6f F%.0f" % (x, y, z, feed)) |
| 13 |
|
| 14 |
def xy_line_to(x,y): |
| 15 |
print("G1 X% 8.4f Y% 8.4f " % (x, y)) |
| 16 |
|
| 17 |
# (endpoint, radius, center, cw?) |
| 18 |
def xy_arc_to( x,y, r, cx,cy, cw ): |
| 19 |
if (cw): |
| 20 |
print("G2 X% 8.5f Y% 8.5f R% 8.5f" % (x, y, r)) |
| 21 |
else: |
| 22 |
print("G3 X% 8.5f Y% 8.5f R% 8.5f" % (x, y, r)) |
| 23 |
# FIXME: optional IJK format arcs |
| 24 |
|
| 25 |
def xy_rapid_to(x,y): |
| 26 |
print("G0 X% 8.4f Y% 8.4f " % (x, y)) |
| 27 |
|
| 28 |
def pen_up(): |
| 29 |
print("G0Z% 8.4f " % (clearance_height)) |
| 30 |
|
| 31 |
""" |
| 32 |
def pen_down(): |
| 33 |
print("G0Z% 8.4f" % (feed_height)) |
| 34 |
plunge(0) |
| 35 |
""" |
| 36 |
|
| 37 |
def pen_down(z=0): |
| 38 |
print("G0Z% 8.4f" % (feed_height)) |
| 39 |
plunge(z) |
| 40 |
|
| 41 |
def plunge(z): |
| 42 |
print("G1 Z% 8.4f F% 8.0f" % (z, plunge_feed)) |
| 43 |
|
| 44 |
def preamble(): |
| 45 |
if (metric): |
| 46 |
print("G21 F% 8.0f" % (feed)) # G20 F6 for inch |
| 47 |
else: |
| 48 |
print("G20 F% 8.0f" % (feed)) # G20 F6 for inch |
| 49 |
|
| 50 |
print("G64 P0.001") # linuxcnc blend mode |
| 51 |
pen_up() |
| 52 |
print("G0 X0 Y0") # this might not be a good idea!? |
| 53 |
|
| 54 |
def postamble(): |
| 55 |
pen_up() |
| 56 |
print("M2") # end of program |
| 57 |
|
| 58 |
def comment(s=""): |
| 59 |
print("( ",s," )") |
| 60 |
|
| 61 |
if __name__ == "__main__": |
| 62 |
print("Nothing to see here.") |