# comments are preceded by # - the computer ignores anything following # zmin = -0.05 # this is clearance past the end on the spindle side - never changes zmax = 0.92 # length of piece at tailstock, determined by jogging over to its end xmin = -0.125 # diameter of original part - where to start shaving passes xmax = -0.26 # diameter of finished part - where to stop shaving passes xclr = -0.32 # a back-out diameter to move to before and after all cutting work xstp = 0.003 # how far to move in per-pass (went as high as 0.019" on Walnut) print '%' # prog start (a necessary symbol for EMC2 - www.linuxcnc.org) # clear and get in start position print '(clear and get in start position)' # ( and ) surround comments in g-code print 'F10' # feed speed of 10 (in/min, IIRC) print 'G1 X%0.3F' % xclr # G1 means 'move at feed speed' print 'G1 Z%0.3F' % zmax # this formatting is a Python thing, explained next... # the Z will be printed in the previous line. %F in ""s or ''s will be replaced by # a valid floating point number (or the value of a variable containing one) after # the quotes and another % symbol to separate the two parts. Putting a 0.3 between # the % and the F means to print it with 3 decimal places, rounding up, or padding # with 0 if necessary. E.g. 0.5318 would become 0.532, and 0.12 would become 0.120 print '(begin cutting)' # the next statement starts up a loop between the xmax and xmin values, with the 1000s # being a convention to fix some problems with floating points that I can likely remove for i in range(int(xmax * 1000), int(xmin * 1000 + xstp * 1000), int(xstp * 1000)): print 'F6' # slow down for pass each time # the next line will move to the final pass in X only if we're less than a step away if i / 1000.0 > xmin: print 'G1 X%0.3F' % xmin # otherwise just make each next pass else: print 'G1 X%0.3F' % (i / 1000.0) # make the cut print 'G1 Z%0.3F' % zmin print 'F15' # speed up for finish pass each time # make the finish pass back the other way print 'G1 Z%0.3F' % zmax # clear and return to start position print '(clear and return to start position)' print 'G1 X%0.3F' % xclr # for some reason, if I don't put the final line 2x, it doesn't run it - an EMC2 bug (?) print 'G1 Z%0.3F' % zclr print 'G1 Z%0.3F' % zclr print '%' # prog end (another EMC2 convention - www.linuxcnc.org)