This FANUC probing lesson has two parts. First you will write a single-surface G31 probe in X, read the skip position and turn it into a surface position with the stylus radius. Then you will build a custom probing cycle that takes two G31 touches, finds the centre of a slot and writes that centre to G54 X.
You can step through both programs in MacroMill VMC Pro, which supports the G31 skip signal and custom probing cycle creation. Yes, programs and macros you write and test in a MacroMill simulator can be saved or exported and run on a real CNC machine, after a normal prove-out with single block, reduced rapids and a dry run.
What G31 does in FANUC probing
On a FANUC control, G31 is the skip function. It is a feed move, like G01, with one difference. The axis starts toward the programmed end point. When the probe, or another skip signal, triggers, motion stops, the rest of that block is discarded, and the next block starts.
The position at that moment is stored in the skip-position system variables, in the active workpiece coordinate system, for example G54 if G54 is selected. On a typical mill those standard variables are #5061 for X, #5062 for Y and #5063 for Z. Other axes use #5064 and so on. Copy the value into your own variable on the next line. The next G31 overwrites #5061 to #5063.
If the skip signal does not trigger, G31 simply finishes at the programmed end point, and #5061 to #5063 hold that end point. The control does not raise an alarm on its own, so a real cycle must check that a touch actually happened. Cancel cutter compensation first: G31 with G41 or G42 active gives an alarm on FANUC. Keep the probe’s tool-length offset on with G43, so the X and Y skip position is the centre of the stylus ball.
Lesson 1: a single-surface probe in X
The aim is to find one face in X. The figures below are metric training values, not a job setup. The program starts at X20, drops to Z5, then makes a G31 move toward X-20. That is a move in the minus X direction, so it would touch the right-hand face of a part that sits somewhere between those two points.
O8001 (TRAINING - SINGLE SURFACE X)
G90 G54 G17 G21 G40 G49 G80
#111 = 3.0 (TRAINING STYLUS RADIUS)
G00 X20. Y0.
G43 Z50. H01
G00 Z5.
G31 X-20. F100
#100 = #5061
#110 = #100 - #111
G00 X20.
G00 Z50.
M30
Read it line by line.
The safe-start line selects absolute metric motion in G54, the XY plane, and cancels cutter compensation, tool length and cycles. #111 holds the stylus ball radius. Use your calibrated radius on a real probe; 3.0 mm is only a training value. The next lines send the probe to a safe XY start, apply a tool-length offset, and drop to the measuring height.
G31 X-20. F100 is the measuring move. The axis feeds toward X-20. When the probe triggers, motion stops and #5061 holds the X skip position: the centre of the ball, in G54. The next line copies that into #100 so it is safe if another G31 comes later.
The surface is not at the ball centre. Because this move was in the minus X direction, the ball touched on its minus-X side, and the face is one radius further in that direction. Subtract the stylus radius:
#110 = #100 – #111
If you approached from the other side, starting to the left of a left-hand face and moving in plus X, you would add the radius instead:
#110 = #100 + #111
The rule is simple. Add the stylus radius when the G31 move is in the plus X direction. Subtract it when the G31 move is in the minus X direction. The same plus-or-minus rule applies in Y with #5062. The program then retracts to a safe height.
If you wanted that face to become G54 X0, you would not replace #5221 with #110. #5061, and therefore #110, is already in the current workpiece coordinate system. #5221 is the standard FANUC system variable for the G54 X workpiece zero point offset. You shift the existing offset by the measured work position:
#5221 = #5221 + #110
If the compensated face currently reads X2.0 in G54, adding 2.0 to #5221 moves the G54 origin so that face becomes X0. A direct #5221 = #110 would write a work-coordinate measurement on top of an offset, which is not the same thing. Confirm #5221 against your control’s Custom Macro B manual. On a typical mill, #5222 is G54 Y and #5223 is G54 Z.
Once you have the program, step it through in MacroMill VMC Pro. It is the full FANUC VMC simulator plus a Renishaw-style probing suite, with an OMP60-style probe, and it supports the G31 skip signal. Run O8001 in single block, watch the touch point live in 2D and 3D, and check that #5061 and #110 are the values you expected before you ever try the same move on a machine.
Lesson 2: a custom cycle that finds a slot centre
A single face is useful, but a lot of setup work needs a centre. This custom cycle starts roughly in the middle of a slot, takes one G31 touch to the plus-X wall and one to the minus-X wall, then writes the centre to G54 X. The figures are again training values, not a job setup. This is a teaching cycle, not a finished shop routine: it uses one measuring feed, and it does not include your machine’s probe on or off M-codes.
O8002 (TRAINING - SLOT CENTRE X)
G90 G54 G17 G21 G40 G49 G80
#111 = 3.0 (TRAINING STYLUS RADIUS)
G00 X0. Y0.
G43 Z50. H01
G00 Z5.
G31 X25. F100
IF [ABS[#5061-25.] LT 0.02] GOTO 90
#101 = #5061
G00 X0.
G31 X-25. F100
IF [ABS[#5061+25.] LT 0.02] GOTO 90
#102 = #5061
#103 = [#101+#102]/2
#5221 = #5221+#103
G00 X0.
G00 Z50.
M30
N90 #3000=1(NO SKIP TOUCH)
The first G31 moves in plus X toward X25. If the probe triggers, #101 stores that skip position, the ball centre at the right-hand wall. The IF check is the no-touch test: if #5061 is still at the programmed end point, within 0.02 mm, the skip never happened and the program jumps to a #3000 alarm. The probe then returns to X0 and repeats the same idea in minus X, storing the left-hand skip position in #102.
The centre of the slot, in the current G54, is the average of the two skip positions:
#103 = [#101+#102]/2
You do not add or subtract the stylus radius here. The two ball-centre positions are each one radius away from their wall, in opposite directions, so the radius cancels and #103 is the true centre. The same centre formula works for a web, where the two touches come from the outside instead of from inside a slot.
Then the cycle writes the result to G54 X by shifting the existing offset:
#5221 = #5221+#103
After that line, the measured centre is G54 X0, and the following G00 X0. should put the ball on that new centre. The stylus radius does not cancel if you want the width of the feature. For a slot, the true width is the distance between the two ball centres plus one ball diameter: ABS[#101-#102] + 2*#111. For a web, subtract the diameter instead: ABS[#101-#102] – 2*#111.
A shop cycle would usually add a protected approach, a second slower measuring touch, and a retract that is not hard-coded to X0. The logic you have just written is still the core of a custom probing cycle: two G31 moves, two stored skip positions, a centre, and a write to #5221. For the macro slips that most often show up at the control, see common FANUC macro mistakes that crash machines. For a wider path from writing a macro to running it on the machine, see Write a FANUC macro, test it in MacroMill, then run it on your machine.
This is also the point at which a custom cycle should be tested, not guessed at on a live probe. MacroMill VMC Pro supports custom probing cycle creation, so you can write that slot-centre program, step through both G31 touches, and watch G54 update in the live 2D and 3D graphics. The probing suite already includes packages for slots, webs, bores, bosses, edges, corners and pockets, and the setup screen can write a G65 probe macro for those cycles, so you can compare your own logic with a standard pickup, then save or export the program when it is right.
Try it yourself
Work these out before you look at the answers. In a training run, the two skip positions are #101 = 12.0 and #102 = -8.0, the stylus radius #111 is 3.0, and #5221 is currently 200.0.
- What is the slot centre #103?
- What is the true slot width?
- What value should #5221 have after you write the centre so that it becomes G54 X0?
- If the first G31 was a plus-X move to a left-hand face, do you add or subtract #111 to get the surface from #5061?
- If a G31 move never triggers, what does #5061 hold?
Answers: the centre is [12.0 + -8.0] / 2 = 2.0. The true slot width is ABS[12.0 – (-8.0)] + 2*3.0 = 26.0. The new #5221 is 200.0 + 2.0 = 202.0, not 2.0. You add the stylus radius for a plus-X measuring move. If the skip never triggers, #5061 holds the programmed end point of the G31 block.
When the answers make sense on paper, run the same figures in MacroMill VMC Pro and confirm them on the control. Single-block the cycle, check #103 and the new #5221, and only then save or export the program for a prove-out on the machine. You can do that work on any of the ten FANUC-style controls in VMC Pro, and use Macro Lab if you want more macro practice around the same ideas.
Prove it out before you cut
Learning the logic in a simulator is the right first step, but it does not replace a prove-out. Addresses, stylus radius, tool-length offsets, clearances, feeds and the work offset you write must be confirmed against your machine, your probe and your control’s Custom Macro B manual. On many FANUC controls, feed override does not slow a G31 move, so keep the probing feed modest. When the program is ready, save or export it, load it on the machine, and prove it out with single block, reduced rapids and a dry run before you rely on the offset or cut the part.
Practise the lesson in MacroMill VMC Pro
If you want to learn FANUC probing properly, the practical next step is to run the programs, not only read them. MacroMill VMC Pro Probing Edition gives you a place to step through the G31 lesson, test your custom slot-centre cycle, and watch every touch point as G54 updates, without tying up a production machine. It supports the G31 skip signal and custom probing cycle creation, and you can save or export the program when it is ready for a prove-out.
Start with the product page at macromillcnc.com/macromill-vmc-pro, or buy it at payhip.com/b/FX2DZ. If you have a question about the lesson, write to info@macromillcnc.online.
For tips and updates, join the MacroMill WhatsApp group: chat.whatsapp.com/Htae97asBiD14QiwMXjGJA.
The software is for training and simulation only. Yes, programs and macros you write and test in a MacroMill simulator can be saved or exported and run on a real CNC machine. As with any new program, prove it out first with single block, reduced rapids and a dry run before you cut. Addresses, tool offsets, stylus data, clearances, spindle speeds and feeds must be confirmed against your machine, your tooling, your probe and your control’s Custom Macro B manual.
MacroMill

Leave a Reply