G21 G-Code Command

G21 G-Code Command

G21 is a G-code command used in CNC machining to set the machine to operate in metric units. This means that all subsequent commands and measurements will be interpreted in millimeters instead of inches. G20, on the other hand, is the G-code command used to set the machine to operate in inches. The choice between G20 and G21 depends on the specific requirements of the machining project and the preferences of the operator.

How G21 G-Code Command is used

Here’s an example of how G21 can be used in a G-code program:

G21         (Switch to metric units)
G90         (Set absolute positioning mode)
G1 X50 Y50  (Move to X=50mm, Y=50mm)
G1 X100 Y100 (Move to X=100mm, Y=100mm)

In this example, the first line (G21) tells the machine to operate in metric units. The second line (G90) sets the positioning mode to absolute, meaning that the machine will move to the exact coordinates specified in the subsequent commands. The third and fourth lines (G1 X50 Y50 and G1 X100 Y100) are movement commands that tell the machine to move to the specified X and Y coordinates in millimeters.

The comments in brackets are added for human readability and do not affect the operation of the machine.

Share on pinterest
Share on email
Share on print

Table of Contents