A site dedicated to CNC of Mini lathes - the 7x10, 7x12, 7x14, and 7x16

NGCGUI - Conversational CNC

Posted by  7xCNC  Nov 9, 2012

NGCGUI is a subroutine system for LinuxCNC. It's conversational CNC programming. That means rather than designing a model in CAD then running it through CAM to get Gcode which you run via LinuxCNC, you can enter a few parameters directly into LinuxCNC and go.

It's great for simple machining, and in fact can cover the majority of lathe operations. You can build a whole program from a number of different subroutines. For example, you can turn a length to size, then thread part of it and put a radius on the end. There are all sorts of combinations possible.

There are a whole bunch of subroutines available (most in the LinuxCNC forum) and you can easily write your own.

Implementing NGCGUI

You'll need to make some .ini changes that tell LinuxCNC to load some tabs and where to look for files. This is explained here

To create a subroutine for ngcgui:

Create a file called simple.ngc (The file name and subroutine mame within the file must match (minus .ngc))

The first line is a comment
(info: example -- simple subroutine example)

The next line opens the sub and names it
o<example> sub

Next you define parameters. LinuxCNC considers all numbered parameters in the range #1 thru #30 to be calling parameters so ngcgui provides entry boxes for any occurence of parameters in this range. It is good practice to avoid use of numbered parameters #1 through #30 anywhere else in the subroutine. Using local, named parameters is recommended for all internal variables.
#<ra> = #1 (=.6 Radius A) ;Example parm with comment (in the GUI parameter 1 will be named Radius A and have a default value of .6)
#<radius_b> = #2 (=0.4) ;Example parm with no comment
#<endx> = #3 (End X) ;Example with no preset

Then you define the code
G0 X0Z1 (Rapid to X0 Z1)
G3 i#<ra> F10 (Counterclockwise arc with i defined by <ra> parameter set in GUI)
G3 i-#<radius_b> F100
G0 X#<endx> (Rapid to positon defined by <endx>)

The sub must always end with the following (with the correct name!)
o<example> endsub

Putting it all together:

(info: example -- simple subroutine example)
o<example> sub
#<ra> = #1 (=.6 Radius A) ;Example parm with comment
#<radius_b> = #2 (=0.4) ;Example parm with no comment
#<endx> = #3 (End X) ;Example with no preset
G0 X0Z1
G3 i#<ra> F10
G3 i-#<radius_b> F100
G0 X#<endx>
o<example> endsub

The above is just an example of the structure and isn't really a functional routine.

Detailed documentation is available on the LinuxCNC site and from NGCGUI.txt

Note: The below examples need careful checking and air cutting before you use them for real cutting. Most are in metric (millimeters) and have default values.

  1. (info: OD Turning)
  2. o<od> sub
  3. #<material-dia> = #1 (=0.750 Start Diameter)
  4. #<final_dia> = #2 (=0.700 Finish Diameter)
  5. #<rough-doc> = #3 (=0.020 Roughing DOC)
  6. #<final-doc> = #4 (=0.010 Finish DOC)
  7. #<surface-speed> = #5 (=100 Surface Speed)
  8. #<rough-feed> = #6 (=2 Rough Feed)
  9. #<finish-feed> = #7 (=1 Finish Feed)
  10. #<max_rpm> = #8 (=1500 Max RPM)
  11. #<z-end> = #9 (=-0.5 End of Cut)
  12. #<z-start> = #10 (=0.100 Start of Cut)
  13. #<rough-tool> = #11 (=1 Roughing Tool)
  14. #<finish-tool> = #12 (=1 Finishing Tool)
  15. #<coolant> = #13 (=8 Flood=8, Off=9)
  16.  
  17. #<roughing> = 0
  18. G7 G96 D#<max_rpm> S#<surface-speed>
  19.  
  20. ; Rough the OD if needed
  21. o100 if [[#<material-dia> - #<final_dia>]/2 GT #<final-doc>]
  22. #<roughing> = 1
  23. #<rough-diam> = [#<final_dia> + [#<final-doc> * 2]]
  24. #<rough-passes> = FUP[[[[#<material-dia> - #<rough-diam>]/2]/#<rough-doc>]]
  25. #<rough-cut> = [[#<material-dia> - #<rough-diam>]/#<rough-passes>]
  26. T#<rough-tool> M6 G43
  27.  
  28. M3 M#<coolant>
  29. G0 X#<material-dia> Z#<z-start>
  30. #1=#<material-dia>
  31.  
  32. F#<rough-feed>
  33. o110 repeat[#<rough-passes>]
  34. #1 = [#1 - #<rough-cut>]
  35. X#1
  36. G1 Z#<z-end>
  37. X[#1 + #<rough-cut> + 0.025]
  38. G0 Z#<z-start>
  39. o110 endrepeat
  40.  
  41. M9
  42. o100 endif
  43.  
  44. o120 if [#<roughing> EQ 1]
  45. o130 if [#<rough-tool> NE #<finish-tool>]
  46. (msg,rough)
  47. T#<finish-tool> M6 G43
  48. o130 endif
  49. o120 else
  50. (msg,no rough)
  51. T#<finish-tool> M6 G43
  52. o120 endif
  53.  
  54. ;Final Cut
  55. M3 M#<coolant>
  56. F#<finish-feed>
  57. #1 = #<final_dia>
  58. G0 X#1 Z#<z-start>
  59. G1 Z#<z-end>
  60. X[#<material-dia> + 0.025]
  61. G0 Z#<z-start>
  62.  
  63. G0 X[#1+0.025]
  64. M5 M9
  65. Z#<z-start>
  66. G97
  67. G53 G0 X0 Z0
  68. o<od> endsub
  1. ;odtaper_lathe3 for lathe
  2. ;outside diam taper for end of shaft
  3.  
  4. ;UNTESTED concept only, edit and test for your own use before using
  5.  
  6. ;Before running make sure tool is in a position that it can safely travel to Stock Diameter and Z Start.
  7.  
  8. o<odtaper_lathe3>sub
  9. #<Stock_Diam> = #1 (=20.00 Stock Diameter)
  10. #<Small_Diam> = #2 (=15 Small Diameter)
  11. #<Max_Cut> = #3 (=1.0 Max Depth of Cut)
  12. #<Start_z> = #4 (=1.00 Z Start of Cut)
  13. #<End_z> = #5 (=-10 Z End of Cut)
  14. #<Feed> = #6 (=100 Feed mm/min)
  15. #<RPM> = #7 (=500 RPM)
  16. #<Final_Cut> = #8 (=.1 Final Cut)
  17. #<Fin_ Feed> = #9 (=50 Final cut speed)
  18. #<Spring_Cuts> = #10 (=1 Spring Cuts)
  19.  
  20. #<Large_Diam_F> = #<Stock_Diam>
  21. #<Small_Diam_F> = #<Small_Diam>
  22. #<Stock_Diam> = [#<Stock_Diam> + #<Final_Cut>]
  23. #<Small_Diam> = [#<Small_Diam> + #<Final_Cut>]
  24. #<Z_Len> = [#<Start_z> - #<End_z>]
  25. #<Cut_Amount> = [#<Stock_Diam> - #<Small_Diam>] ; deepest X cut
  26. #<Cuts> = FUP [[#<Cut_Amount> / #<Max_Cut>]] ; round up the number of passes to reach deepest cut
  27. #<Max_Cut> = [#<Cut_Amount> / #<Cuts>] ; amount to take off X each pass
  28. #<Z_Cut> = [#<Z_Len> / #<Cuts>] ;length of each Z cut
  29.  
  30. G18 (xz plane)
  31. G21 (millimeters)
  32. G40 (cancel cutter radius compensation)
  33. G49 (cancel tool length offset)
  34. G90 (absolute distance mode)
  35. G94 (units/min feed rate)
  36. G54 (Coordinant system 1 default)
  37. G7 (diameter mode)
  38. G64 p.001 q.001 (set path tolerance)
  39.  
  40. ; if Z End of Cut is greater than Z Start of Cut do not run
  41. o201 if [#<End_z> gt #<Start_z>]
  42. (debug, Z End of Cut #<End_z># greater than Z Start of Cut #<Start_z>)
  43. o200 return
  44. o201 endif
  45.  
  46. ; if X Stock Diam is less than Small Diam do not run
  47. o301 if [#<Stock_Diam> lt #<Small_Diam>]
  48. (debug, Stock Diam #<Stock_Diam> less than Small Diam #<Small_Diam>)
  49. o300 return
  50. o301 endif
  51.  
  52. S#<RPM>
  53. F#<Feed>
  54. M3 ; spindle cw
  55. G4 P1 ; pause for spindle to reach RPM
  56.  
  57. G0 X[#<Stock_Diam> + .010] Z#<Start_z>
  58. G1 X#<Stock_Diam>
  59. #<Current-Diameter> = #<Stock_Diam>
  60. #<Current-Z> = #<Start_z>
  61. #<X_Target> = #<Stock_Diam>
  62. #<Z_Target> = #<Start_z>
  63.  
  64. o100 while [#<Cuts> gt 0]
  65. #<Current-Diameter> = [#<Current-Diameter> - #<Max_Cut>]
  66. #<Z_Target> = [#<Z_Target> - #<Z_Cut>]
  67. G0 X [#<Current-Diameter> + .010]
  68. G1 X #<Current-Diameter>
  69. G1 X #<Stock_Diam> Z #<Z_Target>
  70. G0 X [#<Stock_Diam> + .010]
  71. G0 Z #<Start_z>
  72. #<Cuts> = [#<Cuts> - 1]
  73. o100 endwhile
  74.  
  75. ;final cut
  76. F#<Fin_ Feed>
  77. G0 X [#<Current-Diameter> + .010]
  78. G1 X #<Small_Diam_F>
  79. G1 X #<Large_Diam_F> Z #<End_z>
  80. G0 X [#<Large_Diam_F> + .010]
  81. G0 Z #<Start_z>
  82.  
  83. ;spring cuts
  84. o102 while [#<Spring_Cuts> gt 0]
  85. G0 X [#<Small_Diam_F> + .010]
  86. G1 X #<Small_Diam_F>
  87. G1 Z #<End_z> X #<Large_Diam_F>
  88. G0 X [#<Large_Diam_F> + .010]
  89. G0 Z #<Start_z>
  90. #<Spring_Cuts> = [#<Spring_Cuts> -1]
  91. o102 endwhile
  92.  
  93. M5 ; stop spindle
  94. G0 Z #<Start_z>
  95.  
  96. o<odtaper_lathe3>endsub