Of all the places to deploy a confident guesser, Fanuc Macro B is the worst one the language offers, and seeing why requires only one observation: macros are where programs guard machines. Probing routines, protection checks, programmer-defined alarms, tool-breakage detection, the macro layer exists mostly to stop bad things, which means an error there does not merely fail to help; it disarms a defense while reporting it armed.
Three reasons macros resist the models
The corpus is thin. Ordinary motion code saturates the training data; Macro B lives in manuals, a few forums, and shop folklore. Where data thins, large language models interpolate, and interpolated Macro B reads exactly like real Macro B with details from nowhere, the same niche-corpus failure that makes AI-edited post processors unreliable, at higher stakes.
System variables are per-control facts. Macro power comes from system variables, the numbered addresses where the control exposes positions, offsets, alarms, and probe results, and the numbers differ by control model and configuration. A hallucinated variable number is not a syntax error; it reads garbage or writes somewhere unintended, silently, which is the precise shape of mistake models make most: a specific, checkable-sounding fact, wrong.
Macro failures are quiet. A wrong motion block usually announces itself, an alarm, a visible gouge. A wrong conditional sense in a protection check announces nothing: the program runs, the check passes when it should fail, and the discovery happens whenever the guarded hazard finally occurs, unguarded.
The failure catalog
| The AI mistake | Why it reads fine | How it fails |
|---|---|---|
| Invented system-variable numbers | Formatted exactly like real ones | Reads or writes the wrong address, silently |
| Inverted conditional sense | The logic is fluent either way | Alarms on success, passes on failure |
| Wrong variable range | Locals and commons look alike | State vanishes or persists across calls unexpectedly |
| Unit and scaling confusion | The arithmetic is plausible | Comparisons against values in the wrong units |
| Incomplete protection blocks | Looks like the textbook pattern | Misses the one check this situation needed |
The last row is the deep one, because protection code is situational by nature: the checks a probing macro needs depend on the probe, the machine, and the failure history of that shop, knowledge that is not in any corpus. The variable layer’s everyday discipline exists precisely because this territory punishes approximation.
Where AI genuinely earns a place around macros
The explanation direction is safe and useful: paste a verified macro and ask for a line-by-line walkthrough, the stakes are zero and the pedagogy is real, the open-source program-logic documentation makes a good companion reference for the concepts. Drafting documentation comments for existing macros is similarly safe. Sketching logic in plain language, “check probe result against tolerance, alarm with a message if out”, is a reasonable thinking aid, provided the sketch then gets rebuilt, not transcribed, against your control’s macro documentation and a worked example from your own machine family.
The writing itself follows the safety-code standard: sourced from the manual, single-block proven, and tested by deliberately triggering every failure path, a protection check that has never been seen to fire is a hypothesis, not a guard. The same standard, notably, that makes template-generated probing routines the right call on machines that offer them: accumulated, tested correctness beats both hand-typing and model-guessing.
The boundary, stated once
The working rule for AI in the G-code loop holds everywhere, and tightens here: the model drafts, the human verifies, and verification effort scales with consequence. Macros sit at maximum consequence with minimum verifiability, thin corpus, per-control facts, quiet failures, so the verification effort exceeds the drafting savings, and the honest conclusion follows: build the safety layer from the documentation, use the model around it, and keep the fluency that makes the difference legible, the macro vocabulary at recall speed, which the free 60-second drills on the G-code practice page maintain alongside the rest of the core.
Sources
- Wikipedia: Hallucination (artificial intelligence)
- LinuxCNC: O-codes
- Wikipedia: Large language model
Frequently asked questions
Can AI write a safe Fanuc macro program?
Not unsupervised. Macro B is a thin training corpus, system variables differ per control in physically consequential ways, and macro code is typically the safety layer, where a plausible error inverts its purpose. Build macros from your control’s documentation; use AI to explain and sketch.
Why are macros harder for AI than ordinary G-code?
Three compounding reasons: niche corpus, so more interpolation; correctness depending on per-control system-variable numbers, the class models hallucinate; and quiet failures, wrong variable numbers and inverted conditions produce no syntax errors.
What macro mistakes does AI typically make?
Invented system-variable numbers, inverted conditional senses, confused variable ranges, unit and scaling errors, and protection blocks that look complete while missing the situational check. Every one reads fluently.
How should AI actually be used around Fanuc macros?
Explaining verified macros line by line, drafting documentation comments, and sketching check logic in plain language, then rebuilding from the control’s documentation with single-block proving and deliberately triggered failure tests.