

In general, each of the lettered codes refers to a CNC “word,” with G representing general motion, M signifying miscellaneous machine functions, S specifying spindle speed, F referring to feed rate, T referencing tool selection, and H defining the offset. Similar programs are used on turning centers but the codes will vary somewhat. Axes are ascribed according to the right-hand rule: placed palm-side up on the vertical mill table, outstretched thumb points to positive X, forefinger points to positive Y, and raised middle finger points to positive Z. A simple sketch will help the reader to envision the process. The tool is then moved 1/2" in the negative Y direction and cutting begins along the X-axis, proceeding clockwise around the part. Notice that on line 5, the tool is placed 1/8" clear of the part before any cutting begins. The workpiece is clamped centrally on the origin of the machine’s three axes and all instructions are made as absolute moves. Tool length is stored as an offset code and used to zero the Z-axis before the end mill is lowered 3/4 in. Compensation is used in the program both for tool diameter and tool length. end mill is stored in position 1 in the tool turret. Line 14 Return to home set incremental Z travel spindle stop

Line 13 Compensation off X and Y travel coolant off Line 8 Set compensation left Y travel move at specified speed feed rate Line 7 Move at specified speed Z travel feed rate Line 6 Tool length compensation offset code Z travel coolant on Line 5 Sets absolute sets workpiece coordinate system fast move to start point set speed spindle on Line 4 Calls out the tool in turret position 1 automatic tool change Line 3 Lines can be numbered as needed comments are placed in parentheses % Line-by-Line Description of G-code stepsĪ description of each of the G-code commands for this sample program appears below: Users should always follow the instructions for their particular machines. Codes are based on Fanuc controllers and this same program on another controller would probably look similar but might have minor differences. The following example program could be used to mill a 6 in. For more information about G-code and M code, please refer to other related articles in this series listed at the end of this article. This article presents a simple CNC program to demonstrate the typical structure and workings of G-code. Through various combinations of G-code, M-code, and other lettered commands, a CNC machine is told to change tools, start spindles, move cutting tools, etc.

CNC programs direct computer-controlled lathes and mills – usually referred to as turning and machining centers – in the machining of parts.
