G-code: Difference between revisions

Content deleted Content added
m Minor clarification
Added a sample program
Line 70:
 
Some CNC machines use "Conversational" programming, which is a [[wizard_(software)|wizard]]-like programming mode that either hides G-code or completely bypasses the use of G-code.
 
 
== Example ==
 
This is a generic program that demonstrates the use of G-Code to turn a 1" diameter X 1" long part. Assume that a bar of material is in the machine and that the bar is slightly oversized in length and diameter and that the bar protrudes by more than 1" from the face of the chuck. (Caution: This is generic, it might not work on any real machine! Pay particular attention to point 5 below.)
 
{|border="1" cellpadding="2"
|+ Sample
|-
|N01 M216 || (Turn on load monitor)
|-
|N02 G00 X20 Z20 || (Rapid move away from the part, to ensure the starting position of the tool)
|-
|N03 G50 S2000 || (Set Maximum spindle speed)
|-
|N04 T03 || (Choose tool #3 from the carousel)
|-
|N05 G97 S854 M42 M03 M08 || (Variable speed cutting, 854 ft/min, High spindle gear, Start spindle CW rotation, Turn the coolant on)
|-
|N06 G00 X1.1 Z1.1 T0303 || (Rapid feed to a point 0.1" from the end of the bar and 0.05" from the side, Use offset values for tool #3)
|-
|N07 M01 || (Optional Stop)
|-
|N08 G01 Z1.0 F.05 || (Feed in horizontally until the tool is standing 1" from the datum)
|-
|N09 X0.0 || (Feed down until the tool is on center - Face the end of the bar)
|-
|N10 G00 Z1.1 || (Rapid feed 0.1" away from the end of the bar)
|-
|N11 X1.0 || (Rapid feed up until the tool is standing at the finished OD)
|-
|N12 G01 Z0.0 || (Feed in horizontally cutting the bar to 1" diameter all the way to the datum)
|-
|N13 G00 X1.1 || (Rapid feed 0.05" away from the surface of the part)
|-
|N14 G00 X20 Z20 || (Rapid feed back out away from the work)
|-
|N15 M05 M09 || (Stop the spindle, Turn off the coolant)
|-
|N16 M215 || (Turn the load monitor off)
|-
|N17 M02 || (End of program)
|}
 
 
Several points to note:
 
1) There is room for some programming style, even in this short program. The grouping of codes in line N05 could have been put on multiple lines. Doing so may have made it easier to follow program execution.
 
2) Many codes are "Modular" meaning that they stay in effect until they are cancelled or replaced by a contradictory code. For example, once variable speed cutting had been selected (G97), it stayed in effect until the end of the program. In operation, the spindle speed would increase as the tool neared the center of the work in order to maintain a constant cutting speed. Similarly, once rapid feed was selected (G00) all tool movements would be rapid until a feed rate code (G01, G02, G03) was selected.
 
3) It is common practice to use a load monitor with CNC machinery. The load monitor will stop the machine if the spindle or feed loads exceed a preset value that is set during the set-up operation. The job of the load monitor is to prevent damage in the event of tool breakage. Furthermore, to some extent it can warn of a tool that that is becoming dull and needs to be replaced or sharpened.
 
4) It is common practice to bring the tool in rapidly to a "safe" point that is close to the part - in this case 0.01" away - and then start feeding the tool. How close that "safe" distance is, depends on the skill and comfort level of the programmer.
 
5) If the program is wrong. There is a high probability that the machine will crash! That can be very costly. It is wise to intersperse the program with optional stops (M01 code) which allow the program to be run piecemeal. This gives the programmer a better view of the overall progress of the cutting cycle. The optional stops remain in the program but they are skipped during the normal running of the machine.
 
 
 
==See also==