Cutter compensation is a feature of CNC machines that allows the programmer to specify the desired dimensions of the part, without worrying about the actual size of the cutting tool. The CNC machine automatically adjusts the tool path to account for the tool radius, ensuring that the part is machined to the correct size. However, there are situations where the programmer may want to cancel the cutter compensation and use the programmed coordinates as the actual tool path. This is where the G40 code comes in handy.
Usage Format
The G40 code is used to cancel the cutter compensation that was previously activated by either G41 (left compensation) or G42 (right compensation). The G40 code must be placed on the same line as the motion command (such as G01, G02, or G03) that moves the tool away from the compensated path. The G40 code should also be accompanied by the X and Y coordinates of the destination point, and optionally the Z coordinate if the tool needs to move in the Z-axis as well. The general format of the G40 code is:
G40 Gxx Xx Yy Zz
where:
- G40 is the code for cutter compensation cancel
- Gxx is the motion command (such as G01, G02, or G03)
- Xx is the X coordinate of the destination point
- Yy is the Y coordinate of the destination point
- Zz is the Z coordinate of the destination point (optional)
Explanation
The G40 code is useful for situations where the programmer wants to move the tool along a straight or curved line that is not affected by the tool radius. For example, if the programmer wants to cut a slot with a rectangular shape, they can use the G41 or G42 code to activate the cutter compensation for the four sides of the slot, and then use the G40 code to cancel the compensation for the two ends of the slot. This way, the tool will move along the exact coordinates of the slot, without any offset due to the tool radius.
Another example of using the G40 code is when the programmer wants to retract the tool from the part after finishing the machining. The programmer can use the G40 code to cancel the cutter compensation and then move the tool to a safe position, such as the machine zero point or the tool change position. This will prevent the tool from colliding with the part or the fixture during the retraction.
Example
Here is an example of a CNC program that uses the G40 code to cancel the cutter compensation. The program is designed to cut a rectangular slot with a width of 20 mm and a length of 100 mm, using a 10 mm diameter end mill. The program assumes that the part is located at the origin of the coordinate system, and that the tool is initially positioned at X0 Y0 Z10.
% (Program start)
O1000 (Program number)
T1 M06 (Select tool 1 and change tool)
G90 G54 (Set absolute mode and work offset)
S1000 M03 (Set spindle speed and start spindle)
G00 X-5 Y-10 Z10 (Rapid move to the starting point)
G43 H01 Z2 (Activate tool length compensation)
G41 D01 X0 Y0 (Activate left cutter compensation and move to the first corner)
G01 Z-5 F500 (Feed down to the cutting depth)
G01 X100 F1000 (Cut the first side of the slot)
G01 Y20 (Cut the second side of the slot)
G40 G01 X105 Y25 (Cancel cutter compensation and move to the end of the slot)
G00 Z10 (Rapid move up to the clearance height)
G00 X0 Y0 (Rapid move back to the starting point)
G40 G01 X-5 Y-10 (Cancel cutter compensation and move away from the slot)
G00 Z100 (Rapid move up to the safe height)
G53 G00 X0 Y0 Z0 (Move to the machine zero point)
M05 (Stop spindle)
M30 (Program end)
% (Program stop)
Here is a text diagram that shows the tool path of the program, with the cutter compensation and the G40 code. The dashed lines represent the programmed coordinates, and the solid lines represent the actual tool path. The circles represent the tool radius.
Y
^
|
| /----\ /----\
| / \ / \
| / X \
| / \
100 |X X
| \ /
| \ X /
| \ / \ /
| \----/ \----/
|
|_________________________> X
0 0 50 100 105