Parametric Code Examples for CNC

Other Versions
Spanish
CNC beginner gets help on coding parametric data. March 17, 2005

Question
I was wondering if anyone had a sample CNC program that uses parametric programming. I have ordered a new Biesse CNC router and I'm currently learning CNC programming from a book. Unfortunaetly it does not have any parametric code and this is one of the things that I'm interested in. Does anyone have any sample code or links to sites that have sample code?

Forum Responses
(CNC Forum)
From contributor A:
Parametric is not code. It is simple math formulas. If you did buy a new machine from Biesse you will have training in North Carolina where they will teach you this. Which machine did you buy?



From the original questioner:
I understand that parametric programming is not code but part of the ISO standard. I have purchased the Rover B FT. I am based in Ireland and as such there is no structured training. There will be training provided once the machine arrives but I do not wish to wait till it arrives to start to learn the basics of parametric programming.

Imagine - I have no machine and a book teaching CNC programming based on the ISO format (with no parametric code or samples). Once I have this book mastered I then want to introduce myself to parametric CNC programming. Can anyone provide some samples (don't care about the result - just want to see the formulas used) or references to web sites that show examples or the basics for this type of CNC programming? Thanks in advance for any help.



From contributor C:
As stated, mathematical formulas are the basis for parametrics. For example: If you needed to perform an operation at x =1000 on a DX=1220 size material you could, instead, write x = DX-220. You could then use this program on a different size material and, by changing the DX value at the header, maintain the operation at DX-220 without going into the program to modify absolute values, i.e. if DX = 820 then the operation would get performed at x = 600.

I hope that makes sense to someone other than me. This example is as basic as it gets, but the possibilities are endless.



From the original questioner:
I found this sample on a couple of sites. It seems to be a good simple example but should help anyone else like me who would like to find out more on parametric programming.

O0001 (Program number)
#100=1. (Diameter of end mill)
#101=3.0 (X position of hole)
#102=1.5 (Y position of hole)
#103=.5 (Depth of counterbored hole)
#104=400 (Speed in RPM)
#105=3.5 (Feedrate in IPM)
#106=3. (Tool length offset number)
#107=2.0 (Diameter of counterbored hole)
G90 G54 S#104 M03 (Select abs mode, coordinate system, start spindle)
G00 X#101 Y#102 (Rapid to hole center)
G43 H#106 Z.1 (Instate tool length compensation, rapid to approach Z position)
G01 Z-#103 F[#105 / 2]
Y[#102 + #107 / 2 - #100 / 2] F#105
G02 J-[#107 / 2 - #100 / 2]
G01 Y#102
G00 Z.1
M30

If people continue to add examples to this post it could become a helpful reference for people who want to learn a bit of parametric CNC programming, as there seems to be a lack of available sample code.



From contributor D:
This is an example of a basic parametric program for a Biesse Rover FT with an XNC control. (Note the leading and trailing lines have been removed for clarity.)

N10 G70 HC=1 LY=20 PLPZ=0.75 FIL=0 BLO=0 ACC=0 RUO=0 PRS=1 PRL=1 Z=PRK KA=0.000 LZ=0.750 LX=80
N30 RR=6 TX=4 TY=3
N40 PAN=1 ST1="CC" ST2="NULL" L=PCUA
N50 X97.25 Y-0.5 TP=1 PRF=0.752 L=PON F=22.9 VF=3. S=18000 G41 G46 TRZ=0 M55
N60 G1 X97 Y-0.25 F22.9
N70 X.25 G1
N80 Y=LPY-TY-.25 G1
N90 X=TX+.25


N100 Y=LPY-.25
N90 X=LPX-RR+.25 G1
N100 X=LPX+.25 Y=LPY-RR-.25 I=LPX-RR+.25 J=LPY-RR-.25 G2
N110 X=LPX+.25 Y-.25 G1
N120 G1 G40 X=LPX+.5 Y-.5 ZI0.
N130 G0 L=PSU
N140 G0 L=POFF

LPX = Panel X
LPY = Panel Y
RR = Radius
TX = Toe Notch X
TY = Toe Notch Y

This program will adjust the program according to the panel size. Also the parameters are for the radius corner and toe notch.



From contributor E:
Here's an old macro subprogram (note the date) for routing holes. It will rout just the diameter of the hole or it will hog the entire center before finishing the hole depending on the value of "H". It assumes the tool is turning and centered over the hole when called from the main. It was written for a Fanuc 11M control.

O4028(HOLE BORING)
(VERSION 1.2 - 08/19/89 - HOGS OUT CENTER OF CIRCLE)
(TO HOG OUT CENTER OF HOLE SET H TO 1 WHEN CALLING MACRO)
(START POS SHOULD BE OVER CENTER OF HOLE)
(A=#1=DIAMETER ADJUSTMENT)
(D=#7=DIAMETER OF HOLE)
(F=#9=FEEDRATE)
(H=#11=SET TO 1 TO HOG CENTER)
(R=#18=RAPID TRAVEL DIST TO WORK SURFACE)
(T=#20=OFFSET # FOR TOOL RADIUS)
(Z=#26=DEPTH OF HOLE FROM WORK SURFACE)
#2=#5001(X START POS)
#3=#5002(X START POS)


#4=#5003(X START POS)
#12=#[2000.+#20](READ DIA OFFSET)
#10=[#7/2-#12]+[#1/2](CALC RAD AND ADD ADJUSTMENT)
IF[#11EQ1.]GOTO100(HOG CENTER?)
G91G00X[#10-.03]Z-[ABS[#18]]
G02I-[#10-.03]Z-[ABS[#26]]F#9
G01X.03
G02I-#10
X-[#10*2]I-#10Z[ABS[#26]]
G90G01Z#4
X#2Y#3
GOTO500
N100#21=[#12*.9]
G91G00X#21Z-[ABS[#18]]
G02I-#21Z-[ABS[#26]]F#9
I-#21
#23=#21
#22=#21*2
WHILE[#22LT#10]DO1
G01X#21
G02I-#22
#23=#22
#22=#22+#21
END1
G01X-[#10-#23]
G02I-#10
X-#10Y#10I-#10
X-[#10*.9]Y-[#10*.9]J-[#10*.9]Z[ABS[#26]]
G90G01X#2Y#3Z#4
N500M99


From the original questioner:
These sample code snippets are absolutely ideal and really show just how to start parametric programming. Thanks to all contributors and keep it up.


From contributor F:
There is a book on parametric programming for CNC machines - you can get it from Amazon - the code is ISBN: 0872634817.


From contributor I:
Does your software support VBA? Now that's some real parametrics!


From contributor G:
As someone said above, parametrics isn't necessarily code, it's the math. We machine our entry doors on a Rover30 using parametric sub routines. The XNC language has a set of built in functions for assign values to variables that are the result of equations, as well as values from the machine's tooling database. If you received a manual on the XNC language with your machine there should be a section on all of these functions and their use.

The code below is used to machine the mortise for a lock faceplate on the beveled edge of a door. The parameters are passed to the sub and regardless of the length, width or thickness of the faceplate, or the thickness of the door or edge (Y+, Y-) it is machined correctly (or as the parameters were passed, no one said those were right). You can see that no actual machine code is in this mess of text until N480.

The code below is an old version I have sitting on my drive here at home. So if you want to pick it apart and find my math errors don't fret too much, I'm sure I've re-written the routine on the machine.

;SUBROUTINE FOR MORTISE LOCK FACEPLATES
;WILL COMPENSATE IN Y AND Z FOR BEVELED EDGE (VALUE PASSED IN QEG SHOULD BE TRUE EDGE OF DOOR)
;BE CERTAIN BEVEL DIMENSION PASSED MATCHES DATIMACC ANGLE SETTING FOR AGGREGATE USED
;FACEPLATE WILL CENTER IN Z AND CENTER ON THE MORTISE POCKET IN X
;TOOL CHANGE MADE BEFORE CALL TO SUB
;----------------------------------------------------------
;[PARAMETERS]
; QBV=BEVEL
; QEG=EDGE REF
; HCL=SPINDLE CL IN X
; QOC=OFFSET TO CL OF MORTISE FROM HCL
; QFW=FACEPLATE WIDTH
; QFL=FACEPLATE LENGTH
; QFD=FACEPLATE DEPTH
;----------------------------------------------------------
;[EXAMPLE]
;N90 PAN=2 ST1="AGGRE1" ST2="NULL" L=PCUA
;N100 QBV=3.58 QEG=0.00 QOC=31.75 HCL=889.0 QFW=31.8 QFL=203.5 QFD=5.60 L=S23 G0
;----------------------------------------------------------
;VERIFICATION (FAILED CHECKS EXIT AT :1)
;EQUIPPED TOOLING (OUR AGGREAGTE TOOLS ALL BEGIN WITH "A")
N20 ST1=RDM("ATTREZZAGGIO","TP"+$S(2),"UTE")
N30 JM($L(ST1,1) $C(65)):1
;SPINDLE ANGLE
N40 SA=RDM("MANDAGGR"+$S(1),ST1,"ANGZ")
N50 JM!($S(SA)=$S(QBV)):1
;TOOL NAME
N60 ST2=RDM("MANDAGGR"+$S(1),ST1,"UTE")
;AGGRE TOOL TYPE
N70 ST3=RDM("PUNTA",ST2,"TIPO")
N80 JM(ST3 $C(80)):1
;CUTTING DIAM
N90 ATD=RDM("PUNTA",ST2,"DIAM")
;CUTTING RADIUS
N100 ATR=ATD/2
;TRIG CORRECTIONS
;MOVEMENT COMP (Z)
N110 ACR=((_C(QBV))*ATD)/2
;MOVEMENT COMP Y
N130 ACY=_T(QBV*ATD)
;CENTER POINT IN X
N140 PCX=HCL+QOC
;EDGE DETERMINATION AND CONDITIONAL VAR DECLARATIONS
N150 JM(QEG (LY/2)):6
;BOTTOM OF MORTISE IN Y
N390 BMY=(AMP-DCIY)-ACHY
;TOP OF MORTISE IN Y
N400 TMY=(AMP+DCIY)+ACHY
N410 JM:7
:6
;BOTTOM OF MORTISE IN Y
N420 BMY=(AMP+DCIY)+ACHY
;TOP OF MORTISE IN Y
N430 TMY=(AMP-DCIY)-ACHY
:7
N440 API=AMP
N450 APO=API
N460 APU=CMZ
N470 APD=APU
N480 PAN=2 UT=1 ORX=PCX ORY=ASY MO=0 AN1=AAN QZ=-6.36 PRF=0 ANG=QBV USC=1 RES=1 Z=PRK PCT=0 PG40=1 PRC=0 L=G100
N490 Z=CMZ G1
N500 Y=EDY G1
N510 Y=API Z=CMZ G1
N520 X=ASX G1
N530 X=AEX G1
:4
N540 APD=APD+ACD
N550 JM(APD=>BMZ):5
N560 APU=APU-ACD
N570 API=API+ACY
N580 APO=APO-ACY
N590 Y=API Z=APU G1
N600 X=ASX G1
N610 Y=APO Z=APD G1
N620 X=AEX G1
N630 Y=API Z=APU G1
N640 JM:4
:5
N650 Y=TMY Z=TMZ G1
N660 X=ASX G1
N670 Y=BMY Z=BMZ G1
N680 X=AEX G1
N690 Y=TMY Z=TMZ G1
N700 X=PCX G1
N710 Y=ASY G1
N720 L=PSU
N730 L=POFF
;CLEAR VARS HERE BEFORE EXIT
:1
N770 ST1="" ST2="" ST3="" QEG=NIL QFW=NIL QFL=NIL QFD=NIL
%
[FORATURA01]
%
[TABELLEFORI01]
%
[LABELC01]
2=1850
3=2054
6=2503
7=2601
4=2844
5=3033
1=3392
%



From contributor H:
This is an example of a pocket clearing template I made using parametric macro variables. Hope it helps someone.

(POCKET CLEARING)

#100=(FINAL RADIUS------->) 2.6
#101=(WIDTH OF CUT------->) .2
#102=(FEED RATE---------->)100
#103=(Z RETURN CLEARANCE->)1
#104=(FINAL PASS FEEDRATE>) 50
#105=(CLOCKWISE RPM------>) 10000
#106=(DEPTH OF CUT------->) -.5
#107=(X POCKET CENTER---->)0
#108=(Y POCKET CENTER---->)0
T1M6
M8
N1M98P1
G0G54G43H1Z.1X#107Y#108S#105M3
F#102
G1Z#106
G3R#101 X#101
G3X#100Y0.0I-#101Q#101F#102
G3I-#100
G3R#100X0
G0Z#103
M30



The comments below were added after this Forum discussion was archived as a Knowledge Base article (add your comment).

Comment from contributor J:
Parametric programming is useful when used as an extension of the programmer. For instance, let’s say that you have arcs and straight lines in your program. It can be useful to control feed-rate based on formulas that calculate chip load in a turn verses chipload on a straight line move.

Instead of programming different feed-rates, it is possible to have the control calculate feed on the fly. At the top of the program there is a list of variables for feed and rpm. Make subprogram to calculate feed-rate based on size of arc. If move is straight then make feed a specific sfm (surface feed per min). Tool companies list formulas for their tools. Remember that imagination is the key. See it and then sketch your point of logic path you want to accomplish and finally program it.

Example; #100=85;sfm

#101=.005;chipload per tooth

#102=4;number of flutes

#103=.375;tool diameter

#104=(85*3.82/#103);rpm

#105=(#104*#101*#102);feed

This program becomes fun to the operator if he wants to experiment with tool life. Also these macros can be installed in posts to solve tool changer problems etc. I have even installed a macro in a post that automatically inserted tool comp and had a line of code that the operator could edit so he never had to go to his off-set page.