Experiment 6 - CNC Programing-Milling
Experiment 6 - CNC Programing-Milling
2. G-code
G-code stands for “geometric code”. G-codes, also called preparatory codes, are any word in a
CNC program that begins with the letter G. Generally it is a code telling the machine tool what
type of action to perform, such as:
Rapid movement (transport the tool as quickly as possible in between cuts)
Controlled feed in a straight line or arc
Series of controlled feed movements that would result in a hole being bored, a workpiece
cut (routed) to a specific dimension, or a profile (contour) shape added to the edge of a
workpiece
Set tool information such as offset
Switch coordinate systems
3. M-codes
Most M codes activate machine functions like the coolant, spindle, etc. These are decided by the
machine manufacturer, and depend on the features that are available on the machine. E.g., a
machine with a tailstock will have M codes for tailstock in/out. A few (like M00, M01, M02, M98,
etc.in the list below) are fixed and based on the controller.
4. Program format
Program formats and commands explained in this chapter relate to the Fanuc 0iT controller. A
CNC program consists of a number of lines, called blocks. Each block contains a number of
commands.
Block format
A block consists of a set of words. Each word is a command. E.g., X30.0 is a word. A word
consists of an alphabet called the address, followed by a number.
In the previous example, X30.0, X is an address.
Common addresses
N- Block number - specifies the start of the block
G- Preparatory functions
M- Miscellaneous functions X X-axis coordinate
Z- Z-axis coordinate
I- X-axis location of arc center
K- Z-axis location of arc center
R- Radius of arc
S- Spindle speed or Cutting speed F Feed rate
T- Tool number
Start
- The first line is the percent “%” character. The percent “%” is used to denote the beginning
and end of a program. Put one as the first line (block) and one as the last line (block) of
any g-code program. Not all controllers require this. Most will ignore anything after the
“%”, so you can put comments there.
- The second line is the program number, written as Onnnn
Example: O2345 means program number 2345
End
- The last is the program end command (M02 or M30). The last line is the % character.
Block numbers
- Block numbers add clarity to the program. They are written as Nxxxx
Example:
- -- -
N0123 G00 G90 X100.0 Y150.0
N0124 G01 Z-10.0 F250.0
N0125 X120.0
- -- -
- Block numbers are optional. They can be omitted from all blocks or included in some
blocks only. Quite often block numbers are used only in tool change blocks.
- The leading zero is optional. E.g., N0005 and N5 mean the same.
Comments
- Comments can be inserted to add clarity to the program. They can be operation names, tool
names, instructions to the operator, etc.
- Comments are inserted within brackets. Without comments a program is just a mass of
alphabets and numbers and you cannot figure out what each section of the program is doing.
- A comment can be in a separate block by itself, or after a set of commands.
Example
(RAPID TO TOOL CHANGE POSITION)
G00 X200.0 Z150.0 M05
T0202 (GROOVING TOOL)
Figure 2: Axes on a vertical milling machine where X within the long side of the table and Y is
normal to it. Z is along the spindle
6.2. Coordinate system
In Absolute programming the end point of a motion is programmed with reference to the program
zero point. In Incremental programming the end point is specified with reference to the current
tool position.
Absolute traverse to P1, then to P2
G90 X50.0 Y20.0
X30.0 Y50.0
Absolute traverse to P1, incremental to P2
G90 X50.0 Y20.0
G91 X-20.0 Y30.0
Format
G01 X_ Y_ Z_ F_
X, Y, Z = coordinates of destination point F = Feed rate
The block consists of the linear interpolation command G01 followed by the destination
coordinates and the feed rate.
In this picture, to move to the position Z0, the programed coordinate would be Z80, Z160, Z100
and Z200 for tools T1 to T4, respectively. Each time that a tool got worn out and you had to
change it, you would have to change the Z coordinates in the whole program.
To eliminate this problem, machines have a length compensation feature. The program is written
for the drawing coordinates, without considering tool lengths. The lengths are entered in the
(0,0)
N10 G90
N20 F100 S1200 T1 M06
N30 G00 X-5 Y0 Z0
N40 G01 X0 Y0 Z-3
N50 G01 X0 Y55
N60 G01 X10 Y65
N70 G01 X65 Y65
N80 G01 X65 Y15
N90 G02 X50 Y0 R15 F0.23
N100 G01 X0 Y0 F100
N110 G01 Z3
N120 M05 M30
9. Exercise
Write a CNC Milling program for a FANUC controlled machine for the given component. Use
Incremental coordinate system. Take the depth of cut 1mm, speed 1200rpm. Assume suitable feed