Back to Supported G-Codes

G20 & G21 - Unit Selection Commands

DMC File Mode: Supported
Streaming Mode: Supported

Description

G20 and G21 are unit selection commands that specify whether coordinate values in subsequent G-code commands should be interpreted as inches or millimeters respectively.

  • G20 - Sets the coordinate system to use inches
  • G21 - Sets the coordinate system to use millimeters

Important: Galil Motion Controller Implementation

These commands do not directly affect machine operation because Galil's motion controllers operate in "counts" (encoder counts or step counts). The actual machine movement is determined by the "counts per unit" configuration value for each axis.

As long as the user defines all of their machine configuration and G-code commands using the same consistent units (either all inches or all millimeters), the machine will operate correctly regardless of which unit system is selected.

Syntax

G20 ; Set units to inches
G21 ; Set units to millimeters

Parameters

CommandParametersDescription
G20NoneSets coordinate system to inches
G21NoneSets coordinate system to millimeters

Examples

Example 1: Setting Up for Inch-Based Machining

G20 ; Set units to inches
G90 ; Absolute positioning
G0 X1.5 Y2.0 ; Rapid move to 1.5", 2.0"
G1 Z-0.1 F10 ; Linear move down 0.1" at 10 inches/min

Example 2: Setting Up for Metric Machining

G21 ; Set units to millimeters
G90 ; Absolute positioning
G0 X38.1 Y50.8; Rapid move to 38.1mm, 50.8mm
G1 Z-2.54 F254; Linear move down 2.54mm at 254 mm/min