Advertisement
Guest User

Gary FIxler

a guest
Mar 4th, 2009
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.34 KB | None | 0 0
  1. # comments are preceded by # - the computer ignores anything following #
  2.  
  3. zmin = -0.05 # this is clearance past the end on the spindle side - never changes
  4. zmax = 0.92 # length of piece at tailstock, determined by jogging over to its end
  5.  
  6. xmin = -0.125 # diameter of original part - where to start shaving passes
  7. xmax = -0.26 # diameter of finished part - where to stop shaving passes
  8. xclr = -0.32 # a back-out diameter to move to before and after all cutting work
  9. xstp = 0.003 # how far to move in per-pass (went as high as 0.019" on Walnut)
  10.  
  11. print '%' # prog start (a necessary symbol for EMC2 - www.linuxcnc.org)
  12.  
  13. # clear and get in start position
  14. print '(clear and get in start position)' # ( and ) surround comments in g-code
  15. print 'F10' # feed speed of 10 (in/min, IIRC)
  16. print 'G1 X%0.3F' % xclr # G1 means 'move at feed speed'
  17. print 'G1 Z%0.3F' % zmax # this formatting is a Python thing, explained next...
  18.  
  19. # the Z will be printed in the previous line. %F in ""s or ''s will be replaced by
  20. # a valid floating point number (or the value of a variable containing one) after
  21. # the quotes and another % symbol to separate the two parts. Putting a 0.3 between
  22. # the % and the F means to print it with 3 decimal places, rounding up, or padding
  23. # with 0 if necessary. E.g. 0.5318 would become 0.532, and 0.12 would become 0.120
  24.  
  25. print '(begin cutting)'
  26. # the next statement starts up a loop between the xmax and xmin values, with the 1000s
  27. # being a convention to fix some problems with floating points that I can likely remove
  28. for i in range(int(xmax * 1000), int(xmin * 1000 + xstp * 1000), int(xstp * 1000)):
  29.     print 'F6' # slow down for pass each time
  30.     # the next line will move to the final pass in X only if we're less than a step away
  31.     if i / 1000.0 > xmin:
  32.         print 'G1 X%0.3F' % xmin
  33.     # otherwise just make each next pass
  34.     else:
  35.         print 'G1 X%0.3F' % (i / 1000.0)
  36.     # make the cut
  37.     print 'G1 Z%0.3F' % zmin
  38.     print 'F15' # speed up for finish pass each time
  39.     # make the finish pass back the other way
  40.     print 'G1 Z%0.3F' % zmax
  41.  
  42. # clear and return to start position
  43. print '(clear and return to start position)'
  44. print 'G1 X%0.3F' % xclr
  45. # for some reason, if I don't put the final line 2x, it doesn't run it - an EMC2 bug (?)
  46. print 'G1 Z%0.3F' % zclr
  47. print 'G1 Z%0.3F' % zclr
  48.  
  49. print '%' # prog end (another EMC2 convention - www.linuxcnc.org)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement