File: ngc_writer.py

package info (click to toggle)
opencamlib 2023.01.11-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,800 kB
  • sloc: cpp: 8,722; python: 5,530; sh: 604; javascript: 310; makefile: 209
file content (62 lines) | stat: -rw-r--r-- 1,326 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

# very simple G-code writer.
# Anders Wallin 2012

clearance_height= 20
feed_height = 10
feed = 200
plunge_feed = 100
metric = True

def line_to(x,y,z):
    print("G1 X% 8.6f Y% 8.6f Z% 8.6f F%.0f" % (x, y, z, feed))

def xy_line_to(x,y):
    print("G1 X% 8.4f Y% 8.4f " % (x, y))

# (endpoint, radius, center, cw?)
def xy_arc_to( x,y, r, cx,cy, cw ):
    if (cw):
        print("G2 X% 8.5f Y% 8.5f R% 8.5f" % (x, y, r))
    else:
        print("G3 X% 8.5f Y% 8.5f R% 8.5f" % (x, y, r))
    # FIXME: optional IJK format arcs
    
def xy_rapid_to(x,y):
    print("G0 X% 8.4f Y% 8.4f " % (x, y))

def pen_up():
    print("G0Z% 8.4f " % (clearance_height))

"""
def pen_down():
    print("G0Z% 8.4f" % (feed_height))
    plunge(0)
"""

def pen_down(z=0):
    print("G0Z% 8.4f" % (feed_height))
    plunge(z)

def plunge(z):
    print("G1 Z% 8.4f F% 8.0f" % (z, plunge_feed))

def preamble():
    if (metric):
        print("G21 F% 8.0f" % (feed)) # G20 F6 for inch
    else:
        print("G20 F% 8.0f" % (feed)) # G20 F6 for inch
        
    print("G64 P0.001") # linuxcnc blend mode
    pen_up()
    print("G0 X0 Y0") # this might not be a good idea!?

def postamble():
    pen_up()
    print("M2") # end of program

def comment(s=""):
    print("( ",s," )")
    
if __name__ == "__main__":
    print("Nothing to see here.")