Modal & Position Data

Modal Group Variables (#4001 - #4130)

Read the currently active G-code for each modal group. These are read-only variables that let your macro check which G-codes are active before executing operations.

Variable Modal Group Current Value Meaning
#4001Group 1 (interpolation)0=G00, 1=G01, 2=G02, 3=G03
#4002Group 2 (plane)17=G17(XY), 18=G18(ZX), 19=G19(YZ)
#4003Group 3 (absolute/incr)90=G90, 91=G91
#4005Group 5 (feed mode)94=G94(per min), 95=G95(per rev)
#4006Group 6 (inch/metric)20=G20, 21=G21
#4007Group 7 (cutter comp)40=G40(cancel), 41=G41, 42=G42
#4008Group 8 (TLC)43=G43, 44=G44, 49=G49(cancel)
#4009Group 9 (canned cycle)73, 74, 76, 80-89 = active canned cycle
#4014Group 14 (WCS)54=G54, 55=G55, ... 59=G59
#4109Modal address, not a groupCurrent F code (feedrate)
#4111Modal address, not a groupCurrent H code (length offset number)
#4113Modal address, not a groupCurrent M code
#4120Modal address, not a groupCurrent T code number
#4130Modal address, not a groupCurrent G54.1 additional-WCS P number

These are read-only variables. Use them to validate machine state before running critical operations. Note that they report modal state through the last block read into the buffer, not necessarily the block executing at the spindle — the pattern is group NN → #40NN, with groups up to 22 on 16i/18i and 0i controls and up to 30 on the 30i series. The 30i series adds two parallel sets: #4201–#4330 for the block currently executing and #4401–#4530 for the block interrupted by an interrupt-type macro.

Example: Verifying G90 Mode

IF [#4003 NE 90] THEN #3000=1(MUST BE IN G90 MODE)

Position Variables

Fanuc provides several sets of position variables for reading the current tool location in different coordinate frames.

Position Type X Y Z
Endpoint (programmed)#5001#5002#5003
Machine coordinate#5021#5022#5023
Current position (work)#5041#5042#5043
Skip signal position#5061#5062#5063

Endpoint (#5001-#5003)

The last commanded position in the current work coordinate system. This is where the program told the tool to go, not necessarily where it ended up.

Machine (#5021-#5023)

Absolute machine position relative to home. These values are independent of any work coordinate offset and always reflect the true mechanical position. The manuals mark them “read operation during movement: disabled” — read them with the axes stopped, or the buffered (pre-read) value is not guaranteed.

Current (#5041-#5043)

Where the tool actually is right now in work coordinates. This accounts for the active work offset (G54, G55, etc.) and any tool length compensation. Same caveat as the machine position: only guaranteed with the axes stopped.

Skip (#5061-#5063)

Position captured (latched) at the instant the skip signal (probe trigger) fires during a G31 skip move — which is why these are valid during motion. If the probe never trips, they hold the programmed end point of the G31 block instead. This is the foundation of all touch-probe probing routines.

Each set covers one variable per axis in axis order (1st axis = X, 2nd = Y, 3rd = Z on a typical mill): 0i-B controls document 4 axes per set, 16i/18i document 8 (e.g. skip = #5061–#5068), and the 30i series stretches every set to 20 (skip = #5061–#5080, with a separate #100001+ range for up to 50 axes).

Tool Length Compensation Variables

Variables #5081 through #5088 hold the tool length compensation values currently active on the control, one per axis.

Variable Description
#5081Active TLC value, 1st axis (X)
#5082Active TLC value, 2nd axis (Y)
#5083Active TLC value, 3rd axis (Z) — the usual mill case
#5084 - #5088Active TLC values, 4th–8th axes

Per the manuals, these hold the compensation value currently used for execution — not the stored entry in the offset table, and not the value from the immediately preceding offset. If you cancel TLC with G49, they read zero. The H offset number in use is a different variable: modal #4111.

Work Coordinate Offset Variables

These variables give you direct read/write access to all work coordinate offsets stored in the control. You can modify offsets from within a macro program.

Variable Range Work Offset G-Code
#5201 - #5208External work offset (common shift on every WCS)N/A
#5221 - #5228G54G54
#5241 - #5248G55G55
#5261 - #5268G56G56
#5281 - #5288G57G57
#5301 - #5308G58G58
#5321 - #5328G59G59
#7001 - #7008G54.1 P1G54.1 P1
#7021 - #7028G54.1 P2 (each P adds 20 to the base)G54.1 P2
...... up to P48
#7941 - #7948G54.1 P48G54.1 P48
#14001 - #19988G54.1 P1–P300 (300-set option)G54.1 P1-P300

Within each set the variable index is the axis number — 1st axis = X, 2nd = Y, 3rd = Z on a typical mill, then 4th axis onward in machine axis order. For example: #5221 = G54 X offset, #5222 = G54 Y offset, #5223 = G54 Z offset. The ranges above show the 8-axis (16i/18i-era) numbering; 0i-B documents 4 axes per set and the 30i series 20 (G54 = #5221–#5240), but the base numbers and the 20-per-P spacing are the same everywhere.

These are READ/WRITE - you can update work offsets from a macro. This is commonly used in probing routines to store measured results directly into the active work offset.

Example: Adding Probing Result to G54 X

#5221=#5221+#500 (ADD PROBING RESULT TO G54 X)

Saving and Restoring Modal State

When writing macros that change G-codes (like switching to G91, changing WCS, etc.), it is best practice to save the current modal state and restore it when done. This prevents the macro from leaving the machine in an unexpected mode.

(SAVE CURRENT STATE)
#120=#4001 (INTERPOLATION MODE)
#121=#4003 (ABS/INCR)
#122=#4006 (INCH/METRIC)
#123=#4014 (WCS)
(... do macro work ...)
(RESTORE STATE)
G#121 (RESTORE ABS/INCR)
G#122 (RESTORE UNITS)
G#123 (RESTORE WCS)

See also: Fanuc System Variables for the complete reference, Tool Offset Variables for tool compensation data, and Renishaw Inspection Plus for skip signal (#5061) probing usage.

Open the Macro Playground — write and run macros like these in your browser, with live variable values as the program executes.

References

  • FANUC, Series 30i/31i/32i-MODEL B Plus Operator’s Manual (Common), B-64724EN/01, Ch. 16 “Custom Macro” (modal, position, and workpiece-origin system variables).
  • FANUC, Series 30i/31i/32i-MODEL A User’s Manual (Common), B-63944EN/03, Ch. 16 “Custom Macro”.
  • FANUC, Series 16i/18i/160i/180i-MODEL B Operator’s Manual (Machining Center), B-63534EN/02, Ch. 15 “Custom Macro”.
  • FANUC, Series 0i-MODEL B Operator’s Manual (Machining Center), B-63844EN/02, Ch. 15 “Custom Macro”.
  • Peter Smid, Fanuc CNC Custom Macros, Industrial Press, 2004.

Have a question or want to contribute?

Contact us with corrections, additions, or topics you'd like covered.

Get in Touch