1、Cimatron 后置处理技术* DEMO 3 axes Post Processor for FANUC *表示为注释文本,将不起作用* CIMATRON90 VER 9.0 * Last update : 23-FEB-1998 * * define private variables: *定义后置处理中需要用到的变量类型,通常不修改FORMAT (SEQUENCING) Seq SubSeq CNTRL_NUM NURBS_DEG count first deg ; FORMAT (TOOL) CutterComp FirstTool LastTool ; FORMAT (COORDIN
2、ATES) Xold Yold Zold DXcenter DYcenter DZcenter ; FORMAT (COORDINATES) Zinit Clear Depth CNTRL_X CNTRL_Y CNTRL_Z KNOT_ ; FORMAT (COORDINATES) Xhome Yhome Zhome ; FORMAT (COORDINATES) XfirstOrigin YfirstOrigin ZfirstOrigin ; FORMAT (USER_1) CurrSubNum ; FORMAT (coordinates) ORIGOLDI ORIGOLDJ ORIGOLDK
3、 ;* define private flags: FORMAT (USER_2) FlagSub FlagSeq FlagSpin; FORMAT (USER_2) FirstOriginChange FlagError Flagrotmac ; * define private constants: FORMAT (USER_2) YES NO ; * change the format of existing variables: FORMAT (USER_1) SUB_NUMBER ; * INTERACTION (USER_1) “MAIN-PROGRAM-NUMBER“ MainN
4、um = 100 ; INTERACTION (TOOL) “DIACOMP=TOOL+“ DiaComp = 50 ; INTERACTION (USER_1) “TOOL-CHANGE-PROGRAM“ ChangeTool = 8000 ; INTERACTION (CHARACTER) “SEQUENCING“ NumYN = “N“ ; INTERACTION (SEQUENCING) “SEQUENC-START“ SeqStart = 10 ; INTERACTION (SEQUENCING) “SEQUENC-INCR.“ SeqIncr = 10 ; INTERACTION
5、(CHARACTER) “SUBROUTINES“ Sub = “Y“ ; INTERACTION (USER_1) “SUB-PROGRAM-NUMBER“ StartSubNum = 1000 ; * INTERACTION 为交互内容,可以输入,即在后置处理对话框中出现的内容可以试着将里面的文字变为中文* NON_MODAL ALL_VAR; * MODAL 定义变量是否为模态,像 X_CURPOS这种坐标位置当然是随时都在变化的MODAL X_CURPOS Y_CURPOS Z_CURPOS ; MODAL LIN_MOV CIRC_MOV MCH_FEED SPIN_SPEED SP
6、IN_DIR MCH_COOL MCH_DWELL; MODAL CUTCOM_ON CUTCOM_OFF ; MODAL CYC_DEPTH CYC_PECK CYC_DWELL CYC_RETR CYC_CLEAR Depth Clear NURBS_MOV; IDENTICAL X_CURPOS X_ENDPT ; IDENTICAL Y_CURPOS Y_ENDPT ; * 每输出一行程序之前,调用一个新的值,即保持侦测状态* * NEW_LINE_IS $ ; * $ 为换行指令,这一段内容制定程序是如何换行的IF_SET (FlagSeq _EQ_ NO) $使用 IF.ELSE
7、语句判断,OUTPUT 表示输出OUTPUT J ; ELSE IF_SET (FlagSub _EQ_ NO) OUTPUT J “N“ Seq ; Seq = Seq + SeqIncr ; ELSE OUTPUT J “N“ SubSeq ; SubSeq = SubSeq + SeqIncr ; END_IF ; END_IF ; * BEGINNING OF TAPE: 程序头的指定YES = 1 ; NO = 0 ; Seq = SeqStart ; FlagSeq = NO ; FlagSub = NO ; IF_SET (NumYN _EQ_ “y“) FlagSeq = YE
8、S ; END_IF ; IF_SET (NumYN _EQ_ “Y“) FlagSeq = YES ; END_IF ; IF_SET (Sub _EQ_ “y“) Sub = “Y“ ; END_IF ; IF_SET (Sub _EQ_ “Y“) SET_OFF NO_SUBROUT ; ELSE SET_ON NO_SUBROUT ; END_IF ; *-Unit matrix (MUST be input in this order !) 指定 XYZ 轴的方向,绝对不能改ROT_MAT1 = 1.0 ; ROT_MAT2 = 0.0 ; ROT_MAT3 = 0.0 ; ROT_
9、MAT4 = 0.0 ; ROT_MAT5 = 1.0 ; ROT_MAT6 = 0.0 ; ROT_MAT7 = 0.0 ; ROT_MAT8 = 0.0 ; ROT_MAT9 = 1.0 ; *-shift all data according to the MCHINE ZERO indicated by the * user in the POSTPR interaction 如果指定为对刀点相对于编程原点偏移,设置坐标值如何转换TRANS_MATX = 0 - X_MACH ; TRANS_MATY = 0 - Y_MACH ; TRANS_MATZ = 0 - Z_MACH ; *
10、-shift the HOME according to the MCHINE ZERO indicated by the * user in the POSTPR interaction Xhome = X_HOME - X_MACH ; Yhome = Y_HOME - Y_MACH ; Zhome = Z_HOME - Z_MACH ; *-tool location is HOME 刀具原点Xold = X_HOME ; Yold = Y_HOME ; Zold = Z_HOME ; *-For 1st ORIGIN CHANGE FirstOriginChange = YES ; M
11、CH_FEED = 9999 ; *-output IF_SET (FlagSeq _EQ_ YES ) 换行后输出子程序号OUTPUT “%“ J “O“ MainNum ; ELSE OUTPUT “ %“ J “ O“ MainNum ; END_IF ; *-For the first origin changeORIGOLDI=0 ; ORIGOLDJ=0 ; ORIGOLDK=1 ;flagrotmac = no ;BEGINNING OF PROC: 程序开始段KEEP PROC_NAME ; SET_ON MCH_COOL ; FlagSub = NO ; SubSeq = S
12、eqStart ; END OF TAPE: 使用完一把刀具后IF_SET (FirstTool _NE_ LastTool) OUTPUT $ “ T“ NEXT_TOOL “ M98 P“ ChangeTool; END_IF ; OUTPUT $ “ M30 “ ; END OF FILE: 程序结束符IF_SET (FlagSeq _EQ_ YES ) OUTPUT J “%“ ; ELSE OUTPUT J “ %“ ; END_IF ; * FEED: KEEP MCH_FEED ; 如果 F 值没有改变,则此行程序不输出 F。后面为主轴转速、冷却液、刀补等SPIN: KEEP S
13、PIN_SPEED ; COOLANT: KEEP MCH_COOL ; DWELL: KEEP MCH_DWELL ; CUTTER COMPENSATION: KEEP CUTCOM_ON ; CUTTER COMPENSATION: COFF: KEEP CUTCOM_OFF ; * TOOL CHANGE: FIRST: SET_ON SPIN_SPEED SPIN_DIR ; *-save first tool number 保存刀具号FirstTool = CURR_TOOL ; LastTool = CURR_TOOL ; *-tool cutter compensation r
14、egister number 保存刀补号CutterComp = CURR_TOOL + DiaComp ; *-assuming 1st tool is in the spindle, there is no need * for tool change) 输出了 T01,如果没有换刀功能,删除后面几行OUTPUT $ “ T“ CURR_TOOL ; *-more then one tool in this run of the Post Processor IF_SET (NEXT_TOOL _NE_ CURR_TOOL) OUTPUT $ “ T“ NEXT_TOOL ; END_IF
15、 ; *-standard tool change commands. (assuming 1st tool is in * 程序头的标准语名,如果要增加 G54 等指令,可直接输入到这一位置OUTPUT $ “ G90 G80 G00 G17 G40 M23“ ; OUTPUT $ “ G43 H“ CURR_TOOL “ Z“ Zhome “ S“ SPIN_SPEED “ “ SPIN_DIR ; 产生类似于 G43 H1 Z50 S300 M3 的一行代码TOOL CHANGE: 加工过程中的换刀SET_ON SPIN_SPEED SPIN_DIR ; *-tool cutter co
16、mpensation register number CutterComp = CURR_TOOL + DiaComp ; *-tool change command (by using an internal tool change * subroutine) OUTPUT $ “ T“ CURR_TOOL “ M98 P“ ChangeTool ; OUTPUT $ “ T“ NEXT_TOOL ; *-standard tool change commands. (assuming 1st tool is in OUTPUT $ “ G90 G80 G00 G17 G40 M23“ ;
17、OUTPUT $ “ G43 H“ CURR_TOOL “ Z“ Zhome “ S“ SPIN_SPEED “ “ SPIN_DIR ; TOOL CHANGE: LAST: 最后换刀SET_ON SPIN_SPEED SPIN_DIR ; *-save last tool number LastTool = CURR_TOOL ; *-tool cutter compensation register number CutterComp = CURR_TOOL + DiaComp ; OUTPUT $ “ T“ CURR_TOOL “ M98 P“ ChangeTool ; *-the l
18、ast tool is the same as the first tool IF_SET (NEXT_TOOL _NE_ CURR_TOOL) OUTPUT $ “ T“ NEXT_TOOL ; END_IF ; *-standard tool change commands. (assuming 1st tool is in OUTPUT $ “ G90 G80 G00 G17 G40 M23“ ; OUTPUT $ “ G43 H“ CURR_TOOL “ Z“ Zhome “ S“ SPIN_SPEED “ “ SPIN_DIR ; * LINEAR MOTION: FAST: G00
19、 的输出格式FlagSpin = NO ; IF_SET (SPIN_SPEED) FlagSpin = YES ; END_IF ; IF_SET (SPIN_DIR) FlagSpin = YES ; END_IF ; IF_SET (FlagSpin _EQ_ YES) SET_ON SPIN_SPEED SPIN_DIR ; OUTPUT $ “ S“ SPIN_SPEED “ “ SPIN_DIR ; END_IF ; OUTPUT $ ; IF_SET (LIN_MOV) OUTPUT “ “ LIN_MOV ; END_IF ; IF_SET (X_CURPOS) OUTPUT
20、“ X“ X_CURPOS ; END_IF ; IF_SET (Y_CURPOS) OUTPUT “ Y“ Y_CURPOS ; END_IF ; IF_SET (Z_CURPOS) OUTPUT “ Z“ Z_CURPOS ; END_IF ; IF_SET (MCH_COOL) OUTPUT “ “ MCH_COOL ; END_IF ; SET_ON CIRC_MOV NURBS_MOV ; Xold = X_CURPOS ; Yold = Y_CURPOS ; Zold = Z_CURPOS ; LINEAR MOTION: G01 的输出格式FlagSpin = NO ; IF_S
21、ET (SPIN_SPEED) FlagSpin = YES ; END_IF ; IF_SET (SPIN_DIR) FlagSpin = YES ; END_IF ; IF_SET (FlagSpin _EQ_ YES) SET_ON SPIN_SPEED SPIN_DIR ; OUTPUT $ “ S“ SPIN_SPEED “ “ SPIN_DIR ; END_IF ; OUTPUT $ ; IF_SET (LIN_MOV) OUTPUT “ “ LIN_MOV ; END_IF ; IF_SET (CUTCOM_ON) OUTPUT “ “ CUTCOM_ON “ D“ Cutter
22、Comp ; END_IF ; IF_SET (CUTCOM_OFF) OUTPUT “ “ CUTCOM_OFF ; END_IF ; IF_SET (X_CURPOS) OUTPUT “ X“ X_CURPOS ; END_IF ; IF_SET (Y_CURPOS) OUTPUT “ Y“ Y_CURPOS ; END_IF ; IF_SET (Z_CURPOS) OUTPUT “ Z“ Z_CURPOS ; END_IF ; IF_SET (MCH_FEED) OUTPUT “ F“ MCH_FEED ; END_IF ; IF_SET (MCH_COOL) OUTPUT “ “ MC
23、H_COOL ; END_IF ; SET_ON CIRC_MOV NURBS_MOV; Xold = X_CURPOS ; Yold = Y_CURPOS ; Zold = Z_CURPOS ; * CIRCULAR MOTION: 圆弧运动的输出格式FlagSpin = NO ; IF_SET (SPIN_SPEED) FlagSpin = YES ; END_IF ; IF_SET (SPIN_DIR) FlagSpin = YES ; END_IF ; IF_SET (FlagSpin _EQ_ YES) SET_ON SPIN_SPEED SPIN_DIR ; OUTPUT $ “
24、S“ SPIN_SPEED “ “ SPIN_DIR ; END_IF ; DXcenter = X_CENTER - Xold ; DYcenter = Y_CENTER - Yold ; DZcenter = Z_CENTER - Zold ; OUTPUT $ ; IF_SET (CIRC_MOV) OUTPUT “ “ CIRC_MOV ; END_IF ; IF_SET (X_CURPOS) OUTPUT “ X“ X_ENDPT ; END_IF ; IF_SET (Y_CURPOS) OUTPUT “ Y“ Y_ENDPT ; END_IF ; IF_SET (Z_CURPOS)
25、 OUTPUT “ Z“ Z_ENDPT ; END_IF ; IF_SET (DXcenter _NE_ 0.0) OUTPUT “ I“ DXcenter ; END_IF ; IF_SET (DYcenter _NE_ 0.0) OUTPUT “ J“ DYcenter ; END_IF ; IF_SET (DZcenter _NE_ 0.0) OUTPUT “ K“ DZcenter ; END_IF ; IF_SET (MCH_FEED) OUTPUT “ F“ MCH_FEED ; END_IF ; IF_SET (MCH_COOL) OUTPUT “ “ MCH_COOL ; E
26、ND_IF ; SET_ON LIN_MOV NURBS_MOV ; Xold = X_CURPOS ; Yold = Y_CURPOS ; Zold = Z_CURPOS ; * NURBS MOTION: START:OUTPUT $ NURBS_MOV “P“ NURBS_DEG ;count = 0;first = 1;SET_ON MCH_FEED;NURBS MOTION:IF_SET (first _EQ_ 1)OUTPUT “K“ KNOT_ “X“ CNTRL_X “Y“ CNTRL_Y “Z“ CNTRL_Z “F“ MCH_FEED;END_IF;IF_SET (firs
27、t _EQ_ 0)OUTPUT $ “K“ KNOT_ “X“ CNTRL_X “Y“ CNTRL_Y “Z“ CNTRL_Z;END_IF;first = 0;NURBS MOTION: END:deg = NURBS_DEG ;REPEATcount = count + 1 ;OUTPUT $ “K“ KNOT_ ;UNTIL (count _EQ_ deg) ;SET_ON LIN_MOV CIRC_MOV MCH_FEED;*INSERT WITH: OUTPUT $ INS_STR ; INSERT WITHOUT: OUTPUT J INS_STR ; MESSAGE: OUTPU
28、T $ “( “ MESS_STR “ )“ ; * CYCLE: ON: 钻孔循环的输出格式FlagSpin = NO ; IF_SET (SPIN_SPEED) FlagSpin = YES ; END_IF ; IF_SET (SPIN_DIR) FlagSpin = YES ; END_IF ; IF_SET (FlagSpin _EQ_ YES) SET_ON SPIN_SPEED SPIN_DIR ; OUTPUT $ “ S“ SPIN_SPEED “ “ SPIN_DIR ; END_IF ; SET_ON X_CURPOS Y_CURPOS Z_CURPOS ; SET_ON
29、 CYC_DEPTH CYC_RETR CYC_CLEAR MCH_FEED MCH_COOL ; SET_ON Zinit Depth Clear ; Zinit = Z_CURPOS + CYC_DZINIT ; Depth = Z_CURPOS - CYC_DEPTH ; Clear = Z_CURPOS + CYC_CLEAR ; IF_SET (Zold _LT_ Zinit) OUTPUT $ “ Z“ Zinit ; ELSEOUTPUT $ “ Z“ Zold ; END_IF ;OUTPUT $ ; OUTPUT “ “ CYC_RETR ; OUTPUT “ “ CYC_C
30、ODE ; OUTPUT “ X“ X_CURPOS ; OUTPUT “ Y“ Y_CURPOS ; OUTPUT “ Z“ Depth ; OUTPUT “ R“ Clear ; IF_SET (CYC_PECK) OUTPUT “ Q“ CYC_PECK ; END_IF ; IF_SET (CYC_DWELL) OUTPUT “ P“ CYC_DWELL ; END_IF ; IF_SET (CYC_XSHFT) OUTPUT “ I“ CYC_XSHFT ; END_IF ; IF_SET (CYC_YSHFT) OUTPUT “ J“ CYC_YSHFT ; END_IF ; OU
31、TPUT “ F“ MCH_FEED ; OUTPUT “ “ MCH_COOL ; SET_ON LIN_MOV CIRC_MOV ; SET_OFF CYC_DEPTH CYC_CLEAR; Xold = X_CURPOS ; Yold = Y_CURPOS ; Zold = Z_CURPOS ; CYCLE: Depth = Z_CURPOS - CYC_DEPTH ; Clear = Z_CURPOS + CYC_CLEAR ; OUTPUT $ ; IF_SET (CYC_RETR) OUTPUT “ “ CYC_RETR ; END_IF ; IF_SET (X_CURPOS) O
32、UTPUT “ X“ X_CURPOS ; END_IF ; IF_SET (Y_CURPOS) OUTPUT “ Y“ Y_CURPOS ; END_IF ; IF_SET (Depth) OUTPUT “ Z“ Depth ; END_IF ; IF_SET (Clear) OUTPUT “ R“ Clear ; END_IF ; IF_SET (CYC_PECK) OUTPUT “ Q“ CYC_PECK ; END_IF ; IF_SET (CYC_DWELL) OUTPUT “ P“ CYC_DWELL ; END_IF ; IF_SET (CYC_XSHFT) OUTPUT “ I
33、“ CYC_XSHFT ; END_IF ; IF_SET (CYC_YSHFT) OUTPUT “ J“ CYC_YSHFT ; END_IF ; IF_SET (SPIN_SPEED) OUTPUT “ S“ SPIN_SPEED ; END_IF ; IF_SET (SPIN_DIR) OUTPUT “ “ SPIN_DIR ; END_IF ; IF_SET (MCH_FEED) OUTPUT “ F“ MCH_FEED ; END_IF ; IF_SET (MCH_COOL) OUTPUT “ “ MCH_COOL ; END_IF ; SET_ON LIN_MOV CIRC_MOV
34、 ; SET_OFF CYC_DEPTH CYC_CLEAR; Xold = X_CURPOS ; Yold = Y_CURPOS ; Zold = Z_CURPOS ; CYCLE: OFF: OUTPUT $ “ G80 Z“ Zinit ; SET_ON LIN_MOV CIRC_MOV ; Zold = Zinit ; * ORIGIN CHANGE: 如果有多个编程原点,将进行坐标位置的转换*-Save the first origin data for later use IF_SET (FirstOriginChange _EQ_ YES ) XfirstOrigin = X_O
35、RIGIN ; YfirstOrigin = Y_ORIGIN ; ZfirstOrigin = Z_ORIGIN ; FirstOriginChange = NO ; END_IF ; *.distance between the rotation center and the ORIGIN TRANS_MATX = X_ORIGIN - XfirstOrigin - X_MACH ; TRANS_MATY = Y_ORIGIN - YfirstOrigin - Y_MACH ; TRANS_MATZ = Z_ORIGIN - ZfirstOrigin - Z_MACH ; *.check
36、for change in orientation ( 4,5 axis positioining ) 坐标轴原点检测,超过 3 轴将输出一些报错信息FlagError = NO ; Flagrotmac = no ;IF_SET ( I_ORIGIN _NE_ ORIGOLDI ) FLAGROTMAC = YES ; END_IF ;IF_SET ( J_ORIGIN _NE_ ORIGOLDJ ) FLAGROTMAC = YES ; END_IF ;IF_SET ( K_ORIGIN _NE_ ORIGOLDK ) FLAGROTMAC = YES ; END_IF ;IF_SET (
37、 FLAGROTMAC _EQ_ YES ) FlagError = YES ; END_IF ;IF_SET (FlagError _EQ_ YES) PRINT J “Error: ucs rotation was found in:“ ; PRINT J “ TP=“ TP_NAME “ PROC=“ PROC_NUM “ (“ PROC_NAME “)“ ; PRINT J “Error: Cannot post ucs rotaion toolpaths“ ; OUTPUT J “ M00 (Error: ucs rotation was found)“ ; OUTPUT J “ M
38、00 (TP=“ TP_NAME “ PROC=“ PROC_NUM “ - “ PROC_NAME “)“ ; END_IF ;ORIGOLDI = I_ORIGIN ;ORIGOLDJ = J_ORIGIN ;ORIGOLDK = K_ORIGIN ;* AXISCHANGE: FlagError = NO ; IF_SET (AXIS_NUM _GT_ 3) FlagError = YES ; END_IF ; IF_SET (FlagError _EQ_ YES) PRINT J “Error: 4/5 axes motion was found in:“ ; PRINT J “ TP
39、=“ TP_NAME “ PROC=“ PROC_NUM “ (“ PROC_NAME “)“ ; PRINT J “Error: Cannot post 5 axes toolpaths“ ; OUTPUT J “ M00 (Error: 4/5 axes motion was found)“ ; OUTPUT J “ M00 (TP=“ TP_NAME “ PROC=“ PROC_NUM “ - “ PROC_NAME “)“ ; END_IF ; * SUBROUTINE CALL: 子程序调用CurrSubNum = SUB_NUMBER + StartSubNum ; OUTPUT
40、$ “ M98 P“ CurrSubNum ; BEGINNING OF SUB: 子程序头SET_ON MCH_FEED MCH_COOL LIN_MOV CIRC_MOV ; FlagSub = YES ; OUTPUT J “ “ ; IF_SET (FlagSeq _EQ_ YES) OUTPUT J “O“ CurrSubNum ; ELSE OUTPUT J “ O“ CurrSubNum ; END_IF ; END OF SUB: 子程序结束符OUTPUT $ “ M99“ ; FlagSub = NO ; SUBROUTINE RETURN: 原点复归SET_ON LIN_M
41、OV CIRC_MOV X_CURPOS Y_CURPOS Z_CURPOS; * 对于常见的只使用一把刀具进行加工的情况,并希望在程序头加工上注释语句,只需要修改 TOOL CHANGE:FIRST 中的段落即可,以下所示为对这一部分段落的修改TOOL CHANGE: FIRST: SET_ON SPIN_SPEED SPIN_DIR ; *-save first tool number 保存刀具号FirstTool = CURR_TOOL ; LastTool = CURR_TOOL ; *-tool cutter compensation register number 保存刀补号Cut
42、terComp = CURR_TOOL + DiaComp ; *-assuming 1st tool is in the spindle, there is no need * for tool change) 输出了 T01,如果没有换刀功能,删除后面几行OUTPUT $ “ T“ CURR_TOOL ; *-more then one tool in this run of the Post Processor IF_SET (NEXT_TOOL _NE_ CURR_TOOL) OUTPUT $ “ T“ NEXT_TOOL ; END_IF ; *-standard tool chan
43、ge commands. (assuming 1st tool is in * 程序头的标准语名,如果要增加 G54 等指令,可直接输入到这一位置OUTPUT $ “ G90 G80 G00 G17 G40 M23“ ; * 修改为:OUTPUT $ “ G17 G40 G49 G80 G90 G54 G00 X0 Y0“OUTPUT $ “ G43 H“ CURR_TOOL “ Z“ Zhome “ S“ SPIN_SPEED “ “ SPIN_DIR ; 产生类似于 G43 H1 Z50 S300 M3 的一行代码将修改后的 EXF 文件保存为 NC.EXF。在 cimatron 打开控制面板,在 NC菜单中选择 Dfexf 功能,则系统弹出一个 DOS 窗口,如图所示,输入 NC,并按 ENTER 键,即可生成 NC.EXF 。在复制 demo.def,并命名为 NC.DEF。在后处理器生成的程序文件对比。