由於車削方中球時,需要做一個圓中帶方的夾具,
才能將正方塊的工件夾在車床上切削,
雖然車削的方法速度很快(一個孔加工約1.5分鐘),
但夾具的製作難度有點高,
所以今天就來寫個用銑床銑削方中球的方法,
不過,用銑床銑削可能要多花6倍以上的時間..
銑削方中球用的球刀
以前曾用過直徑2mm的的平底端銑刀,但銑起來表面光度不好,
所以這次改成直徑2mm的球刀,但刀刃要長,
可銑削深度至10mm的才行,如下圖所示
方中球的算法:
假設球體直徑為D,挖孔直徑為d,挖孔深度為S,
正方塊的邊長為L,正方塊的對角線長為(√3)L,則
(√3)L = D + 2*(√3)S,
若將L及D設為已知條件,代入上式則可解出:
挖孔深度S = [(√3)L - D ]/ (2*(√3);
挖孔直徑d = 2*(√2)K = 2*(√2)(L/2 - S)。
xEnd = 0.5*d + r1*( d / D );
zEnd = -S - r1*( (0.5*L-S )/ (0.5*D) ) + r1 ;
方中球的CNC車床程式大約三十多個單節即可,
不過,若改為CNC銑床,因為球面要銑的細緻,
則程式大約三百個單節,這用人工來寫太麻煩了,
所以我打算用lisp來寫CNC銑床程式,
這樣一來不但省事,將來如果要改方中球的尺寸,
也不必再重寫lisp,
只需將球刀的直徑、方中球的球徑、正方塊的邊長輸入即可。
用AutoLisp來畫銑削方中球的刀具路徑
(defun c:kk()
(setq rTool 1.0 dSph 23.0 dHole 0.0 deep 0.0)
(setq rTool (/ (getreal "Enter the tool diameter. ") 2) )
(setq rSph (/ (getreal "Enter the sphere diameter. ") 2) )
(setq lenCubic (/ (getreal "Enter the length of cubic. ") 2) )
(command "color" "bylayer" )
(setq rTool 1.0 dSph 23.0 dHole 0.0 deep 0.0)
(setq rTool (/ (getreal "Enter the tool diameter. ") 2) )
(setq rSph (/ (getreal "Enter the sphere diameter. ") 2) )
(setq lenCubic (/ (getreal "Enter the length of cubic. ") 2) )
(command "color" "bylayer" )
;;;;;;PRE-CHK for feasibility;;;;;;;;;;;;;;;;
(setq deep (/ (- (* (sqrt 3.0) lenCubic ) rSph ) (sqrt 3.0) ))
(setq rHole (* (sqrt 2) (- lenCubic deep) ))
(if (> rHole rSph )
(progn
(alert "The diameter of sphere is larger than the diameter of cubic! ")
(exit)
)
)
(setq deep (/ (- (* (sqrt 3.0) lenCubic ) rSph ) (sqrt 3.0) ))
(setq rHole (* (sqrt 2) (- lenCubic deep) ))
(if (> rHole rSph )
(progn
(alert "The diameter of sphere is larger than the diameter of cubic! ")
(exit)
)
)
(setvar "osmode" 0)
(setq xEnd (+ rHole (* rTool (/ rHole rSph) )))
(setq zEnd (- (* -1 deep) (* rTool (/ (- lenCubic deep) rSph) )))
(setq rBall (+ 0.2 rsph rTool))
(setq x2 0.0 z2 (- rBall lenCubic ) )
(setq xEnd (+ rHole (* rTool (/ rHole rSph) )))
(setq zEnd (- (* -1 deep) (* rTool (/ (- lenCubic deep) rSph) )))
(setq rBall (+ 0.2 rsph rTool))
(setq x2 0.0 z2 (- rBall lenCubic ) )
;;;;;;milling inside out;;;;;;;;;;;;;;;;;;;;;;
(setq num (+ 1 (fix (/ xEnd (* 2 rTool)))))
(setq stepOver (/ xEnd num) )
(setq xmill stepOver)
(while (< xmill (+ xEnd 0.1))
(command "circle" (list 0 0 (- z2 rTool -0.2)) xmill )
(setq xmill (+ xmill stepOver) z2 (- z2 0.4))
)
(setq num (+ 1 (fix (/ xEnd (* 2 rTool)))))
(setq stepOver (/ xEnd num) )
(setq xmill stepOver)
(while (< xmill (+ xEnd 0.1))
(command "circle" (list 0 0 (- z2 rTool -0.2)) xmill )
(setq xmill (+ xmill stepOver) z2 (- z2 0.4))
)
(command "zoom" "E" "")
(command "Vpoint" (list 1 1 1))
;;;;;roughing;;;;;;;;;;;;;;;;;;;
(setq rBall (+ 0.2 rsph rTool))
(setq totalAng (+ 0.1 (/ (* 180.0 (atan (/ rHole (- lenCubic deep)))) 3.1415926)))
(setq stepAng 5.0 totalAng (- totalAng 1.1) )
(command "color" "green" )
(millBall)
(command "Vpoint" (list 1 1 1))
;;;;;roughing;;;;;;;;;;;;;;;;;;;
(setq rBall (+ 0.2 rsph rTool))
(setq totalAng (+ 0.1 (/ (* 180.0 (atan (/ rHole (- lenCubic deep)))) 3.1415926)))
(setq stepAng 5.0 totalAng (- totalAng 1.1) )
(command "color" "green" )
(millBall)
;;;;;finishing;;;;;;;;;;;;;;;;;;;
(setq rBall (+ rsph rTool))
(setq stepAng 1.0 totalAng (+ totalAng 1.0) )
(command "color" "blue" )
(millBall)
(setq rBall (+ rsph rTool))
(setq stepAng 1.0 totalAng (+ totalAng 1.0) )
(command "color" "blue" )
(millBall)
(setvar "osmode" 1)
)
(defun millBall()
(setq num (fix (/ totalAng stepAng) ))
(setq stepAng (/ totalAng num) )
(setq wkAng stepAng angToRad (/ 3.1415926 180.0))
(while (< wkAng (+ 0.1 totalAng) )
(setq z2 (- (* rBall (cos (* angToRad wkAng) )) lenCubic))
(setq x2 (* rBall (sin (* angToRad wkAng) )) )
(command "circle" (list 0 0 (- z2 rTool)) x2 "")
(setq wkAng (+ wkAng stepAng) )
)
)
下圖是方中球的刀具路徑,黑色和綠色是粗銑路徑,
藍色則是最後的精銑刀具路徑。
如果忘了AutoLisp的語法,請參考
(本文的加工參數以塑膠類的軟材為主)
(defun c:bc()
(setq rTool 1.0 dSph 23.0 dHole 0.0 deep 0.0)
(setq rTool (/ (getreal "Enter the tool diameter. ") 2) )
(setq rSph (/ (getreal "Enter the sphere diameter. ") 2) )
(setq lenCubic (/ (getreal "Enter the length of cubic. ") 2) )
(command "color" "bylayer" )
(setq rTool 1.0 dSph 23.0 dHole 0.0 deep 0.0)
(setq rTool (/ (getreal "Enter the tool diameter. ") 2) )
(setq rSph (/ (getreal "Enter the sphere diameter. ") 2) )
(setq lenCubic (/ (getreal "Enter the length of cubic. ") 2) )
(command "color" "bylayer" )
;;;;;;PRE-CHK for feasibility;;;;;;;;;;;;;;;;
(setq deep (/ (- (* (sqrt 3.0) lenCubic ) rSph ) (sqrt 3.0) ))
(setq rHole (* (sqrt 2) (- lenCubic deep) ))
(if (> rHole rSph )
(progn
(alert "The diameter of sphere is larger than the diameter of cubic! ")
(exit) ))
(setq deep (/ (- (* (sqrt 3.0) lenCubic ) rSph ) (sqrt 3.0) ))
(setq rHole (* (sqrt 2) (- lenCubic deep) ))
(if (> rHole rSph )
(progn
(alert "The diameter of sphere is larger than the diameter of cubic! ")
(exit) ))
(setvar "osmode" 0)
(setq file01 (open "c:\\test.nc" "w"))
(princ "%\n" file01)
(princ "O0001\n" file01)
(princ "G0G17G40G49G80G90F300\n" file01)
(princ "G54 G0 X0 Y0\n")
(princ "S2800M03\n" file01)
(princ "G43 Z20. H01\n" file01)
(princ "G0 Z3.\n" file01)
(setq file01 (open "c:\\test.nc" "w"))
(princ "%\n" file01)
(princ "O0001\n" file01)
(princ "G0G17G40G49G80G90F300\n" file01)
(princ "G54 G0 X0 Y0\n")
(princ "S2800M03\n" file01)
(princ "G43 Z20. H01\n" file01)
(princ "G0 Z3.\n" file01)
(setq xEnd (+ rHole (* rTool (/ rHole rSph) )))
(setq zEnd (- (* -1 deep) (* rTool (/ (- lenCubic deep) rSph) )))
(setq rBall (+ 0.2 rsph rTool))
(setq x2 0.0 z2 (- rBall lenCubic ) )
(princ "G1 Z" file01)
(princ (- z2 rTool) file01)
(princ " F120\n" file01)
(setq x2 0.0 z2 (- rBall lenCubic ) )
(princ "G1 Z" file01)
(princ (- z2 rTool) file01)
(princ " F120\n" file01)
;;;;;;milling inside out;;;;;;;;;;;;;;;;;;;;;;
(setq num (+ 1 (fix (/ xEnd (* 2 rTool)))))
(setq stepOver (/ xEnd num) )
(setq xmill stepOver)
(while (< xmill (+ xEnd 0.1))
(setq xp xmill zp z2 brk 0)
(pOutLile)
(command "circle" (list 0 0 (- z2 rTool -0.2)) xmill )
(if (and (> xmill 5 ) (< xmill 7 ))
(princ " F80\n" file01) )
(setq xp (* -1.0 xmill) rp xmill)
(pOutArc)
(setq xp xmill)
(pOutArc)
(setq num (+ 1 (fix (/ xEnd (* 2 rTool)))))
(setq stepOver (/ xEnd num) )
(setq xmill stepOver)
(while (< xmill (+ xEnd 0.1))
(setq xp xmill zp z2 brk 0)
(pOutLile)
(command "circle" (list 0 0 (- z2 rTool -0.2)) xmill )
(if (and (> xmill 5 ) (< xmill 7 ))
(princ " F80\n" file01) )
(setq xp (* -1.0 xmill) rp xmill)
(pOutArc)
(setq xp xmill)
(pOutArc)
(setq xmill (+ xmill stepOver) z2 (- z2 0.5))
)
)
;;;;;;;raising tool;;;;;;;;;;;;
(princ "G0 Z0\n" file01)
(princ " X1.\n" file01)
(princ "G0 Z0\n" file01)
(princ " X1.\n" file01)
(command "zoom" "E" "")
(command "Vpoint" (list 1 1 1))
;;;;;roughing;;;;;;;;;;;;;;;;;;;
(setq rBall (+ 0.2 rsph rTool))
(setq totalAng (+ 0.1 (/ (* 180.0 (atan (/ rHole (- lenCubic deep)))) 3.1415926)))
(setq stepAng 5.0 totalAng (- totalAng 1.1) fx 80)
(command "color" "green" )
(princ " F100\n" file01)
(millBall)
(command "Vpoint" (list 1 1 1))
;;;;;roughing;;;;;;;;;;;;;;;;;;;
(setq rBall (+ 0.2 rsph rTool))
(setq totalAng (+ 0.1 (/ (* 180.0 (atan (/ rHole (- lenCubic deep)))) 3.1415926)))
(setq stepAng 5.0 totalAng (- totalAng 1.1) fx 80)
(command "color" "green" )
(princ " F100\n" file01)
(millBall)
;;;;;finishing;;;;;;;;;;;;;;;;;;;
(setq rBall (+ rsph rTool))
(setq stepAng 1.2 totalAng (+ totalAng 1.0) )
(command "color" "blue" )
(princ " F200\n" file01)
(millBall)
(setq rBall (+ rsph rTool))
(setq stepAng 1.2 totalAng (+ totalAng 1.0) )
(command "color" "blue" )
(princ " F200\n" file01)
(millBall)
;;;;;ending CNC file;;;;;;;;;;;;;;;;;;;
(princ "G0 Z20.\n" file01)
(princ " X0Y0\n" file01)
(princ "M99\n" file01)
(princ "%" file01)
(princ "G0 Z20.\n" file01)
(princ " X0Y0\n" file01)
(princ "M99\n" file01)
(princ "%" file01)
(close file01)
(setvar "osmode" 1)
)
(setvar "osmode" 1)
)
;;;;;;;;;;;sub-program;;;;;;;;;;;;;;;;;;;;;;;;
(defun millBall()
(setq num (fix (/ totalAng stepAng) ))
(setq stepAng (/ totalAng num) brk 1)
(setq wkAng stepAng angToRad (/ 3.1415926 180.0))
(while (< wkAng (+ 0.1 totalAng) )
(setq z2 (- (* rBall (cos (* angToRad wkAng) )) lenCubic))
(setq x2 (* rBall (sin (* angToRad wkAng) )) )
(setq xp x2 zp (- z2 rTool) )
(pOutLile)
(command "circle" (list 0 0 (- z2 rTool)) x2 "")
(setq xp (* -1.0 x2) rp x2)
(pOutArc)
(setq xp x2 )
(pOutArc)
(setq wkAng (+ wkAng stepAng) )
)
(defun millBall()
(setq num (fix (/ totalAng stepAng) ))
(setq stepAng (/ totalAng num) brk 1)
(setq wkAng stepAng angToRad (/ 3.1415926 180.0))
(while (< wkAng (+ 0.1 totalAng) )
(setq z2 (- (* rBall (cos (* angToRad wkAng) )) lenCubic))
(setq x2 (* rBall (sin (* angToRad wkAng) )) )
(setq xp x2 zp (- z2 rTool) )
(pOutLile)
(command "circle" (list 0 0 (- z2 rTool)) x2 "")
(setq xp (* -1.0 x2) rp x2)
(pOutArc)
(setq xp x2 )
(pOutArc)
(setq wkAng (+ wkAng stepAng) )
)
;;;;;;;raising tool;;;;;;;;;;;;
(princ "G0 Z0.\n" file01)
(princ " X1. Y0.\n" file01)
)
(princ "G0 Z0.\n" file01)
(princ " X1. Y0.\n" file01)
)
(defun pOutLile()
(setq pxs(rtos xp 2 3) pzs(rtos zp 2 3))
(setq pxl(strlen pxs) pzl(strlen pzs))
(setq pxn(- 7 pxl) pzn(- 7 pzl))
(princ "G1 X" file01)
(princ pxs file01)
(repeat pxn (princ " " file01))
(if (= brk 1)
(princ "\n" file01) )
(princ "\n" file01) )
(princ " " file01)
(princ "Z" file01)
(princ pzs file01)
(princ "\n" file01)
)
(princ "Z" file01)
(princ pzs file01)
(princ "\n" file01)
)
(defun pOutArc()
(setq pxs(rtos xp 2 3) prs(rtos rp 2 3))
(setq pxl(strlen pxs) prl(strlen prs))
(setq pxn(- 7 pxl) prn(- 7 pzl))
(princ "G2 X" file01)
(princ pxs file01)
(repeat pxn (princ " " file01))
(princ " " file01)
(princ "R" file01)
(princ prs file01)
(princ "\n" file01)
)
(setq pxs(rtos xp 2 3) prs(rtos rp 2 3))
(setq pxl(strlen pxs) prl(strlen prs))
(setq pxn(- 7 pxl) prn(- 7 pzl))
(princ "G2 X" file01)
(princ pxs file01)
(repeat pxn (princ " " file01))
(princ " " file01)
(princ "R" file01)
(princ prs file01)
(princ "\n" file01)
)
銑削方中球的刀具路徑模擬
將AutoLisp產出的CNC程式,用FGcam讀入,便可得到下列的刀具路徑,然後一估加工時間,嚇了一跳,居然要12分鐘,原來精車時,每隔1.2度銑一圈,會是這麼耗時。
將AutoLisp產出的CNC程式,也可用Mastercam讀入,轉成刀具路徑後(NCI),也可預估加工時間,如下圖所示,不過在Mastercam下所估的加工時間是 14分鐘,如下圖所示。
留言
張貼留言