G90 and G91 are two G-codes that control the positioning mode of a CNC machine. Positioning mode determines how the machine interprets the coordinates given in the program. G90 and G91 are also known as absolute and incremental mode, respectively.
Usage format
The usage format of G90 and G91 is very simple. They are usually placed at the beginning of a program or a block of code to set the positioning mode for the following commands. For example:
G90 ; Set absolute mode
G0 X10 Y20 Z5 ; Move to the point (10, 20, 5) in the machine coordinate system
G91 ; Set incremental mode
G0 X5 Y-10 Z0 ; Move 5 units in the positive X direction, 10 units in the negative Y direction, and 0 units in the Z direction from the current position
Explanation
The difference between absolute and incremental mode is how the machine interprets the coordinates given in the program. In absolute mode, the coordinates are absolute values that refer to a fixed point in the machine coordinate system. This means that the machine will move to the exact location specified by the coordinates, regardless of its current position. In incremental mode, the coordinates are relative values that refer to the distance and direction from the current position. This means that the machine will move by the amount specified by the coordinates, in the direction indicated by the sign (+ or -).
To illustrate the difference, consider the following example:
G90 ; Set absolute mode
G0 X10 Y10 ; Move to the point (10, 10) in the machine coordinate system
G0 X20 Y20 ; Move to the point (20, 20) in the machine coordinate system
G91 ; Set incremental mode
G0 X10 Y10 ; Move 10 units in the positive X and Y direction from the current position
G0 X20 Y20 ; Move 20 units in the positive X and Y direction from the current position
The text diagram below shows the path of the machine in both modes:
+---------------------+ Y
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
+---------------------+ X
In absolute mode, the machine will move from the origin (0, 0) to the point (10, 10), then to the point (20, 20), as shown by the solid line:
+---------------------+ Y
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | *
| | /
| | /
+---------------------+ X
* /
/ /
/ /
/ /
/ /
/ /
/ /
/ /
/ /
/ /
/ /
/ /
/ /
/ /
/ /
/ /
/ /
/ /
/ /
/ /
* /
In incremental mode, the machine will move from the origin (0, 0) to the point (10, 10), then to the point (30, 30), then to the point (50, 50), as shown by the dashed line:
+---------------------+ Y
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | *
| | /
| | /
| |/
| *
+---------------------+ X
/|
/ |
/ |
/ |
/ |
/ |
/ |
/ |
/ |
/ |
/ |
/ |
/ |
/ |
/ |
/ |
/ |
/ |
/ |
/ |
* |
Example
Here is an example of a CNC program that uses both absolute and incremental mode to cut a square shape:
G90 ; Set absolute mode
G0 X0 Y0 Z5 ; Move to the origin and raise the tool 5 units above the workpiece
G1 Z-1 F100 ; Lower the tool 1 unit into the workpiece with a feed rate of 100 units per minute
G1 X10 F200 ; Cut a line 10 units long in the positive X direction with a feed rate of 200 units per minute
G91 ; Set incremental mode
G1 Y10 ; Cut a line 10 units long in the positive Y direction
G1 X-10 ; Cut a line 10 units long in the negative X direction
G1 Y-10 ; Cut a line 10 units long in the negative Y direction
G90 ; Set absolute mode
G0 Z5 ; Raise the tool 5 units above the workpiece
G0 X0 Y0 ; Move back to the origin
M30 ; End of program
The text diagram below shows the shape of the cut:
+---------------------+ Y
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | *
| | |
| | |
| | |
| *---*
+---------------------+ X