G52 is a G-code command that is used to shift the local coordinate system of a CNC machine. This means that the origin point (0,0,0) of the coordinate system can be moved to a different location on the workpiece, without affecting the global coordinate system of the machine. This can be useful for performing multiple operations on the same workpiece, or for aligning the tool with a specific feature on the workpiece.

## Usage format

The general format of the G52 command is:

`G52 Xx Yy Zz`

where x, y, and z are the distances to shift the local coordinate system along the X, Y, and Z axes, respectively. These distances are measured from the current position of the tool to the desired origin point of the local coordinate system. The units of the distances are determined by the G20 or G21 command, which set the units to inches or millimeters, respectively.

## Explanation

When the G52 command is executed, the CNC machine will create a new local coordinate system that is shifted by the specified distances from the global coordinate system. The tool will then use the new local coordinate system for all subsequent commands, until the G52 command is canceled or overwritten by another G52 command. The global coordinate system will remain unchanged, and the machine will keep track of both coordinate systems.

To cancel the G52 command and return to the global coordinate system, the G52 command can be followed by the word `cancel`

, or by the G53 command. For example:

`G52 cancel`

or

`G53`

To overwrite the G52 command and create a new local coordinate system, the G52 command can be followed by new distances. For example:

`G52 X10 Y20 Z30`

will create a new local coordinate system that is shifted by 10, 20, and 30 units along the X, Y, and Z axes, respectively, from the global coordinate system.

## Example

Here is an example of how the G52 command can be used to perform multiple operations on the same workpiece. Suppose we have a rectangular workpiece that is 100 mm long, 50 mm wide, and 10 mm thick. We want to drill four holes at the corners of the workpiece, and then mill a slot along the center of the workpiece. We can use the G52 command to shift the local coordinate system to each corner of the workpiece, and then drill the hole using the same coordinates. Then, we can cancel the G52 command and mill the slot using the global coordinate system. Here is the G-code program for this example:

```
G21 ; set units to millimeters
G90 ; set absolute positioning mode
G00 X0 Y0 Z10 ; move to the origin of the global coordinate system
G52 X10 Y10 ; shift the local coordinate system by 10 mm along the X and Y axes
G81 X0 Y0 Z-5 R2 F100 ; drill a hole at the origin of the local coordinate system
G52 X80 ; shift the local coordinate system by 80 mm along the X axis
G81 X0 Y0 Z-5 R2 F100 ; drill a hole at the origin of the local coordinate system
G52 Y30 ; shift the local coordinate system by 30 mm along the Y axis
G81 X0 Y0 Z-5 R2 F100 ; drill a hole at the origin of the local coordinate system
G52 X-80 ; shift the local coordinate system by -80 mm along the X axis
G81 X0 Y0 Z-5 R2 F100 ; drill a hole at the origin of the local coordinate system
G52 cancel ; cancel the local coordinate system shift
G00 X10 Y25 Z10 ; move to the start point of the slot
G01 X90 F200 ; mill the slot along the X axis
G00 Z10 ; move to the safe height
M30 ; end of program
```

Here is a text diagram to illustrate the example:

```
Global coordinate system (X,Y,Z)
/|\
/ | \
/ | \
/ | \
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |_______________________
| | / /
| | / /
| | / /
| |/ /
| / /
| / /
| / /
|/______________________/
Workpiece (100 mm x 50 mm x 10 mm)
+-----------------------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
+-----------------------+
Local coordinate system (x,y,z) shifted by G52 X10 Y10
+-----------------------+
| o |
| |
| |
| |
| |
| |
| |
| |
| o |
+-----------------------+
Local coordinate system (x,y,z) shifted by G52 X80
+-----------------------+
| |
| |
| |
| |
| |
| |
| |
| o |
| |
+-----------------------+
Local coordinate system (x,y,z) shifted by G52 Y30
+-----------------------+
| |
| |
| |
| |
| |
| |
| o |
| |
| |
+-----------------------+
Local coordinate system (x,y,z) shifted by G52 X-80
+-----------------------+
| |
| |
| |
| |
| |
| |
| |
| |
| o |
+-----------------------+
Slot milled using global coordinate system (X,Y,Z)
+-----------------------+
| o |
| |
| |
| |
| |
| |
| |
| |
| o |
+-----------------------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
+-----------------------+
```