Parametric Programming

What Is Parametric Programming?

Parametric programming replaces fixed coordinate values with variables, creating a single program that can machine a family of similar parts. Instead of writing 20 programs for 20 different size pockets, you write ONE program that takes length, width, and depth as arguments.

Benefits include fewer programs to manage, faster setup changes, reduced programming errors, and easier optimization. Parametric programming is not limited to geometry -- feed rates, spindle speeds, step-over distances, and even tool choices can all be parameterized.

When to Use Parametric Programming

Scenario Standard Program Parametric Program
One-off partGood choiceOverkill
Family of parts (same features, different sizes)Many programs neededOne program
Repeated geometry (bolt patterns, pocket arrays)Copy/paste coordinatesLoop with variables
Probing and inspectionNot possibleRequired
In-process decisions (wear comp, adaptive)Not possibleRequired
Custom canned cyclesNot possibleRequired

Identifying Variable Data

The first step in parametric design is to identify what CHANGES between parts. Common variable data points include:

  • Part dimensions (length, width, depth, diameter)
  • Feature positions (hole locations, pocket centers)
  • Machining parameters (feed rate, speed, depth of cut, step-over)
  • Tool data (tool number, offset number)
  • Stock allowance and finish passes

Everything else stays FIXED in the program.

Program Design Process

  1. Define the argument interface (what inputs does the macro need?)
  2. Validate all inputs at the top (use #3000 alarms)
  3. Calculate derived values (speeds, feeds, step counts)
  4. Generate the toolpath using variables
  5. Output results if needed (DPRNT)
  6. Restore state and return (M99)

Worked Example - Rectangular Pocket

A single macro that cuts any rectangular pocket. Arguments: L=length, W=width, D=depth, S=step-over, F=feed, T=tool diameter.

O9100 (RECTANGULAR POCKET MACRO)
(CALL: G65 P9100 A[LENGTH] B[WIDTH] C[DEPTH] D[STEPOVER] F[FEED] R[TOOL DIA])
(------------------------------------)
(VALIDATE ARGUMENTS)
IF [#1 EQ #0] THEN #3000=100(A= LENGTH REQUIRED)
IF [#2 EQ #0] THEN #3000=101(B= WIDTH REQUIRED)
IF [#3 EQ #0] THEN #3000=102(C= DEPTH REQUIRED)
IF [#7 EQ #0] THEN #7=#18/3 (DEFAULT STEPOVER = R/3)
IF [#9 EQ #0] THEN #3000=103(F= FEEDRATE REQUIRED)
IF [#18 EQ #0] THEN #3000=104(R= TOOL DIAMETER REQUIRED)
(------------------------------------)
(CALCULATE PARAMETERS)
#100=#18/2 (TOOL RADIUS)
#101=#1-#18 (NET LENGTH AFTER TOOL COMP)
#102=#2-#18 (NET WIDTH AFTER TOOL COMP)
#103=FUP[ABS[#3]/#7] (NUMBER OF Z PASSES)
#104=#3/#103 (DEPTH PER PASS)
#105=FUP[#102/[#7*2]] (NUMBER OF WIDTH PASSES)
(------------------------------------)
(MACHINE THE POCKET)
#110=0 (CURRENT Z DEPTH)
WHILE [#110 GT #3] DO1
#110=#110-#104
IF [#110 LT #3] THEN #110=#3
G01 Z#110 F[#9/2]
(RASTER PASSES AT THIS LEVEL)
#111=-#102/2 (START Y)
WHILE [#111 LE #102/2] DO2
G01 X[#101/2] Y#111 F#9
G01 X[-#101/2]
#111=#111+#7
IF [#111 GT #102/2] THEN #111=#102/2
G01 X[-#101/2] Y#111
G01 X[#101/2]
#111=#111+#7
END2
END1
G00 Z5.0
M99

Worked Example - Bolt Hole Circle

O9101 (BOLT HOLE CIRCLE)
(G65 P9101 A[RADIUS] B[DEPTH] C[NUM HOLES] D[START ANGLE] F[FEED])
IF [#1 EQ #0] THEN #3000=100(A= RADIUS REQUIRED)
IF [#2 EQ #0] THEN #3000=101(B= DEPTH REQUIRED)
IF [#3 EQ #0] THEN #3000=102(C= NUMBER OF HOLES REQUIRED)
IF [#7 EQ #0] THEN #7=0 (DEFAULT START ANGLE = 0)
IF [#9 EQ #0] THEN #3000=103(F= FEED REQUIRED)
(------------------------------------)
#100=0 (HOLE COUNTER)
#101=360/#3 (ANGLE INCREMENT)
WHILE [#100 LT #3] DO1
#102=#1*COS[#7+#100*#101] (X POSITION)
#103=#1*SIN[#7+#100*#101] (Y POSITION)
G00 X#102 Y#103
G01 Z#2 F#9
G00 Z2.0
#100=#100+1
END1
G00 Z10.0
M99

Tips for Parametric Design

  • Start simple: parameterize one variable at a time, test, then add more
  • Use meaningful variable assignments: #100=TOOL_RADIUS is clearer than just using #18/2 everywhere
  • Always provide defaults where sensible (IF [#n EQ #0] THEN #n=default)
  • Document the argument interface in header comments
  • Test with extreme values (minimum size, maximum depth, zero step-over)
  • Keep the number of arguments manageable (6-10 is typical)

See also: Macro Structure for program organization, Macro Arithmetic for calculation functions, and Macro Control Flow for loops and branching.

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