Modal & Position Data

Modal Group Variables (#4001 - #4120)

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 (TLC)43=G43, 44=G44, 49=G49(cancel)
#4009Group 9 (canned cycle)73-89 = various canned cycles
#4014Group 14 (WCS)54=G54, 55=G55, ... 59=G59
#4109Group 9 (canned cycle)Same as #4009, alternate
#4120N/ACurrent T code number

These are read-only variables. Use them to validate machine state before running critical operations.

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.

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.

Skip (#5061-#5063)

Position captured when the skip signal (probe trigger) fires during a G31 skip move. This is the foundation of all touch-probe probing routines.

Tool Length Compensation Variables

Variables #5081 through #5086 hold the tool length compensation values currently active on the control.

Variable Description
#5081H offset number currently in use
#5082 - #5086Active TLC compensation values (axes)

These reflect the active TLC, not the stored offset values in the offset table. If you cancel TLC with G49, these values become zero.

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 - #5206External work offsetN/A
#5221 - #5226G54G54
#5241 - #5246G55G55
#5261 - #5266G56G56
#5281 - #5286G57G57
#5301 - #5306G58G58
#5321 - #5326G59G59
#7001 - #7006G54.1 P1G54.1 P1
#7021 - #7026G54.1 P2G54.1 P2
...... up to P48
#7941 - #7946G54.1 P48G54.1 P48

Within each set, offsets 1-6 correspond to X, Y, Z, A, B, C axes. For example: #5221 = G54 X offset, #5222 = G54 Y offset, #5223 = G54 Z offset.

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.

References

  • Peter Smid, Fanuc CNC Custom Macros, Industrial Press, 2004.
  • Fanuc, Operator’s Manual / Parameter Manual, FANUC Corporation.

Have a question or want to contribute?

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

Get in Touch