G-code: Difference between revisions

Content deleted Content added
Blazotron (talk | contribs)
m Example: small math error
Line 124:
# It is common practice to bring the tool in rapidly to a "safe" point that is close to the part - in this case 0.1" away - and then start feeding the tool. How close that "safe" distance is, depends on the skill and comfort level of the programmer.
# 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.
 
==Basic ISO CNC Code==
 
:|
:M03, M04, M05 Spindle CW, Spindle CCW, Spindle Stop
:|
:M08, M09 Coolant/lubricant On, Coolant/lubricant Off
:M02 Program Stop
:M30 Program end, rewind
:M99 Subprogram end
:M00, M01 Program stop, optional stop
:|
:G96, G97 Constant surface speed, Constant Spindle speed
:G50 Maximum spindle speed
:G18, G19 Feed mm pr revolvation, feed mm/min
:G00, G01 rapid movement, Linear Interpolation (cutting in a straight line)
:|
:F Feed
:S Spindle Speed
:|
:direction Coordinats X Y Z A B C
 
 
----
'''Example of a simple CNC lathe program'''
[[Image:cnc_prog.jpg|thumb|right|the stock and the part the program produces]]
:O1234
:G50 S2000
:G96 S300 M03
:G00 T0606 (ROUGHT TURN TOOL)
:G18 X37. Z0.
:G01 X-1. F0.2
:Z1.
:G00 X30.
:G01 Z-20.
:X33.
:X35. Z-21.
:Z-25.
:X37.
:G00 X150. Z300.
:M01
:T0101 (18MM DRILL)
:G97 S1000
:G19 M03
:X0. Z5.
:G01 Z-25. F100
:G00 Z5.
:X150. Z300.
:M05
:M30
 
 
----
'''Example of a simple CNC milling program'''
 
A simple example might be a 4" x 2" rectangle. The basic code might read something like:
[[Image:cnc_prog_mill.jpg|thumb|right|the stock and the part the program produces]]
N1X0Y0T01
N2X0Y2000
N3X4000Y2000
N4X4000Y0
N5X0Y0
N6M00
 
:Line 1 (N1) tells the machine to traverse to grid point X0Y0 and to pick tool #1
:Line 2 tells the machine to traverse to grid point X0Y2.000
:Line 3 tells the machine to travel to grid point X4.000Y2.000
:Line 4 tells the machine to travel to grid point X4.000Y0
:Line 5 returns the machine to origin
:Line 6 stops the machine
 
:Note that the program does nothing to define the tool cutting path. If the machine is a router and uses a 1/8" radius cutter, the actual part will end up 1/4" smaller than designed (1/8" per side). To compensate, a G-code command (in this case) may be used to adjust the tool path.
 
N1G44M0125
N2X0Y0T01
N3X0Y2000
N4X4000Y2000
N5X4000Y0
N6X0Y0
N7M00
 
:In this case, the controller sees the first line and adjusts the ___location of the cutter to .125 (or 1/8") to the outside of the cutting profile. Now the machine will make a part that matches the one designed. Depending on the cutting tool, the compensation can be set as needed. For example, a laser with a very fine beam might have a compensation of .005", while a waterjet with a .060 inside tip diameter may need a compensation of .030.
 
 
==See also==