Advertisement
Guest User

Untitled

a guest
Nov 7th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.46 KB | None | 0 0
  1. (info: Quadrilateral pocketing using cutter radius compensation)
  2.  
  3. ; Use with care, test in simulator first.
  4.  
  5. ; Notes:
  6. ; Defaults herein are inch based
  7. ; Uses tool diameter from tool table for cutter radius compensation
  8. ; Supports conventional or climb milling
  9. ; Ramps to depth for each z increment
  10. ; Mirror about x axis for negative scale
  11.  
  12. ; Works for most rectangles and parallelograms but may require some care
  13. ; for specifying:
  14. ; point ordering (see entry move notes below)
  15. ; tool diameter (in tool table)
  16. ; stepover
  17.  
  18. ; Entry moves:
  19. ; Input point ordering Requested Direction Entry line
  20. ; -------------------- ------------------------ ------------------
  21. ; 1234 == CW 2 == CW == Conventional point1 --> point2
  22. ; 1234 == CW 3 == CCW == Climb point1 --> point4
  23.  
  24. ; 1234 == CCW 2 == CW == Conventional point1 --> point4
  25. ; 1234 == CCW 3 == CCW == Climb point1 --> point2
  26.  
  27. ; To accomodate the widest range of tool diameters, order the point sequence
  28. ; (1234) so that the entry move is not directed towards an acute angle.
  29.  
  30. ; Scaling, rotations, and offsets are supported.
  31. ; Scaling is applied first.
  32. ; Rotation is then applied (with respect to origin). It is often simplest
  33. ; to specify the feature so that it is centered at the origin.
  34. ; Offsets are applied last.
  35.  
  36. ;----------------------------------------------------------------------
  37. ; Copyright: 2012
  38. ; Author: Dewey Garrett <dgarrett@panix.com>
  39. ;
  40. ; This program is free software; you can redistribute it and/or modify
  41. ; it under the terms of the GNU General Public License as published by
  42. ; the Free Software Foundation; either version 2 of the License, or
  43. ; (at your option) any later version.
  44. ;
  45. ; This program is distributed in the hope that it will be useful,
  46. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  47. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  48. ; GNU General Public License for more details.
  49. ;
  50. ; You should have received a copy of the GNU General Public License
  51. ; along with this program; if not, write to the Free Software
  52. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  53. ;----------------------------------------------------------------------
  54.  
  55. o<qpocket> sub
  56.  
  57. #<toolno> = #1 (=1)
  58. #<rpm> = #2 (=1000)
  59. #<dir> = #3 (=2 2conv|3climb) ; conventional=cw, climb=ccw
  60. #<feedrate> = #4 (=10)
  61. #<cutdepth> = #5 (=0.1)
  62. #<zincr> = #6 (=0.02)
  63. #<zsafe> = #7 (=0.2)
  64. #<zstart> = #8 (=0)
  65.  
  66. #<x1> = #9
  67. #<y1> = #10
  68. #<x2> = #11
  69. #<y2> = #12
  70. #<x3> = #13
  71. #<y3> = #14
  72. #<x4> = #15
  73. #<y4> = #16
  74.  
  75. #<scale> = #17 (=1) ; use neg value for mirroring
  76. #<rotate> = #18 (=0) ; angle in degrees
  77. #<xoff> = #19 (=0)
  78. #<yoff> = #20 (=0)
  79. #<stepover> = #21 (=0.5) ; tooldiameter fraction
  80. #<g64tol> = #22 (=0.002)
  81. #<spin_notify> = #23 (=1) ; 1 == prompt user
  82. #<verbose> = #24 (=0)
  83.  
  84. #<depthpasslimit> = 100 ; outer loop
  85. #<outlinepasslimit> = 100 ; inner loop
  86. #<tdelta> = 0.0001 ; small increment to tool diameter
  87. #<cutdepth> = [0 - #<cutdepth>]
  88. #<zincr> = [0 - #<zincr>]
  89.  
  90. g40 ; make sure cutter radius compensation off at start
  91. g64 p #<g64tol> ; path tolerance
  92.  
  93. o<if10> if [#<scale> EQ 0]
  94. (print, qpocket: zero scale #<scale> - EXITING)
  95. (debug, qpocket: zero scale #<scale> - EXITING)
  96. (AXIS,notify, qpocket: zero scale - EXITING)
  97. m2
  98. o<if10> endif
  99.  
  100. o<if11> if [#<scale> LT 0]
  101. (print, qpocket: MIRROR about x axis for negative scale #<scale>)
  102. (debug, qpocket: MIRROR about x axis for negative scale #<scale>)
  103. (AXIS,notify, qpocket: MIRROR about x axis for negative scale)
  104. o<if11> endif
  105. #<x1> = [#<scale> * #<x1>]
  106. #<x2> = [#<scale> * #<x2>]
  107. #<x3> = [#<scale> * #<x3>]
  108. #<x4> = [#<scale> * #<x4>]
  109.  
  110. #<scale> = [ABS[#<scale>]]
  111. #<y1> = [#<scale> * #<y1>]
  112. #<y2> = [#<scale> * #<y2>]
  113. #<y3> = [#<scale> * #<y3>]
  114. #<y4> = [#<scale> * #<y4>]
  115.  
  116. #<scale> = 1
  117.  
  118. o<if20> if [[#<stepover> GT 1] OR [#<stepover> LE 0]]
  119. (print, qpocket: invalid stepover=#<stepover> - EXITING)
  120. (debug, qpocket: invalid stepover=#<stepover> - EXITING)
  121. (AXIS,notify, qpocket: invalid stepover - EXITING)
  122. m2
  123. o<if20> endif
  124.  
  125. o<if30> if [[#<dir> NE 2] AND [#<dir> NE 3]]
  126. (print, qpocket:bad dir=#<dir> - EXITING)
  127. (debug, qpocket:bad dir=#<dir> - EXITING)
  128. (AXIS,notify, qpocket:bad dir - EXITING)
  129. m2
  130. o<if30> endif
  131.  
  132. ;compute direction eg 2==cw,3==ccw for points as ordered:
  133. o<dir> call [4][#<x1>][#<y1>][#<x2>][#<y2>][#<x3>][#<y3>][#<x4>][#<y4>]
  134. #<pointsdir> = #<_dir:> ; direction of input points 2==cw
  135. #<xctr> = #<_dir:cx> ; centroid
  136. #<yctr> = #<_dir:cy> ; centroid
  137.  
  138. o<ifdir1> if [#<pointsdir> LE 0]
  139. ; failed to get direction -- pathological case
  140. (print, failed to compute direction - EXITING)
  141. (debug, failed to compute direction - EXITING)
  142. (AXIS,notify, failed to compute direction - EXITING)
  143. m2
  144. o<ifdir1> endif
  145.  
  146. ; Get data for x,y points
  147. #<npoints> = 4
  148. o<pointsdata> call [#<npoints>] [#<x1>][#<x2>][#<x3>][#<x4>]
  149. #<xc> = #<_pointsdata:ctr>
  150. #<xmin> = [#<_pointsdata:min> - #<xctr>]
  151. #<xmax> = [#<_pointsdata:max> - #<xctr>]
  152. o<pointsdata> call [#<npoints>] [#<y1>][#<y2>][#<y3>][#<y4>]
  153. #<yc> = #<_pointsdata:ctr>
  154. #<ymin> = [#<_pointsdata:min> - #<yctr>]
  155. #<ymax> = [#<_pointsdata:max> - #<yctr>]
  156.  
  157. ; Respecify input points about the x,y centroid
  158. o<ifv0> if [#<verbose> GT 0]
  159. (debug, centroid: #<xctr> #<yctr>)
  160. o<ifv0> endif
  161.  
  162. #<x1> = [#<x1> - #<xctr>]
  163. #<x2> = [#<x2> - #<xctr>]
  164. #<x3> = [#<x3> - #<xctr>]
  165. #<x4> = [#<x4> - #<xctr>]
  166.  
  167. #<y1> = [#<y1> - #<yctr>]
  168. #<y2> = [#<y2> - #<yctr>]
  169. #<y3> = [#<y3> - #<yctr>]
  170. #<y4> = [#<y4> - #<yctr>]
  171.  
  172. ; make order of points agree with input direction request
  173. o<if40> if [#<pointsdir> NE #<dir>]
  174. o<ifv1> if [#<verbose> GT 0]
  175. (debug, reversing input point sequence: 1-4-3-2)
  176. o<ifv1> endif
  177. ; swap points ordering: 1234 --> 1432
  178. #<xt> = #<x2>
  179. #<yt> = #<y2>
  180. #<x2> = #<x4>
  181. #<y2> = #<y4>
  182. #<x4> = #<xt>
  183. #<y4> = #<yt>
  184. o<if40> endif
  185.  
  186. ; determine min size for first outline pass
  187. o<if50> if [[#<xmax>-#<xmin>] GT [#<ymax>-#<ymin>]]
  188. #<minor> = [ABS[#<ymax>-#<ymin>]/2]
  189. o<if50> else
  190. #<minor> = [ABS[#<xmax>-#<xmin>]/2]
  191. o<if50> endif
  192.  
  193. ; load tool and establish scaling for first outline pass
  194. o<loadtool> call [#<toolno>]
  195. #<thetooldiam> = #5410
  196. #<tooldiam> = [#5410 + #<tdelta>]
  197. #<r> = [#<tooldiam> / 2]
  198. #<sizei> = [#<tooldiam> / #<minor>]
  199. #<qscalei> = [#<scale> * #<sizei>]
  200.  
  201. o<ifsc> if [#<qscalei> GE #<scale>]
  202. (print, qpocket: tooldiam is too big #<thetooldiam> - EXITING)
  203. (debug, qpocket: tooldiam is too big #<thetooldiam> - EXITING)
  204. (AXIS,notify, qpocket: tooldiam is too big - EXITING)
  205. m2
  206. o<ifsc> endif
  207.  
  208. ; scale the centered feature and translate to original position
  209. o<move> call [#<x1>][#<y1>][0][#<qscalei>][#<xctr>][#<yctr>]
  210. #<x1i> = #<_move:x>
  211. #<y1i> = #<_move:y>
  212. o<move> call [#<x2>][#<y2>][0][#<qscalei>][#<xctr>][#<yctr>]
  213. #<x2i> = #<_move:x>
  214. #<y2i> = #<_move:y>
  215. o<move> call [#<x3>][#<y3>][0][#<qscalei>][#<xctr>][#<yctr>]
  216. #<x3i> = #<_move:x>
  217. #<y3i> = #<_move:y>
  218. o<move> call [#<x4>][#<y4>][0][#<qscalei>][#<xctr>][#<yctr>]
  219. #<x4i> = #<_move:x>
  220. #<y4i> = #<_move:y>
  221. ; xni,yni are the initial points at the smallest scaling
  222.  
  223. ; apply input rotation and offset
  224. o<move> call [#<x1i>][#<y1i>][#<rotate>][1][#<xoff>][#<yoff>]
  225. #<x1i> = #<_move:x>
  226. #<y1i> = #<_move:y>
  227. o<move> call [#<x2i>][#<y2i>][#<rotate>][1][#<xoff>][#<yoff>]
  228. #<x2i> = #<_move:x>
  229. #<y2i> = #<_move:y>
  230. o<move> call [#<x3i>][#<y3i>][#<rotate>][1][#<xoff>][#<yoff>]
  231. #<x3i> = #<_move:x>
  232. #<y3i> = #<_move:y>
  233. o<move> call [#<x4i>][#<y4i>][#<rotate>][1][#<xoff>][#<yoff>]
  234. #<x4i> = #<_move:x>
  235. #<y4i> = #<_move:y>
  236.  
  237. ;get angles for connecting lines
  238. o<line> call [#<x1i>][#<y1i>][#<x2i>][#<y2i>]
  239. #<cos12> = #<_line:cos>
  240. #<sin12> = #<_line:sin>
  241. o<line> call [#<x2i>][#<y2i>][#<x3i>][#<y3i>]
  242. #<cos23> = #<_line:cos>
  243. #<sin23> = #<_line:sin>
  244. o<line> call [#<x3i>][#<y3i>][#<x4i>][#<y4i>]
  245. #<cos34> = #<_line:cos>
  246. #<sin34> = #<_line:sin>
  247. o<line> call [#<x4i>][#<y4i>][#<x1i>][#<y1i>]
  248. #<cos41> = #<_line:cos>
  249. #<sin41> = #<_line:sin>
  250.  
  251. ;compute angles at line interesctions:
  252. o<dot> call [#<x1i>][#<y1i>][#<x2i>][#<y2i>][#<x3i>][#<y3i>]
  253. #<ang123> = #<_dot:ang>
  254. o<dot> call [#<x2i>][#<y2i>][#<x3i>][#<y3i>][#<x4i>][#<y4i>]
  255. #<ang234> = #<_dot:ang>
  256. o<dot> call [#<x3i>][#<y3i>][#<x4i>][#<y4i>][#<x1i>][#<y1i>]
  257. #<ang341> = #<_dot:ang>
  258. o<dot> call [#<x4i>][#<y4i>][#<x1i>][#<y1i>][#<x2i>][#<y2i>]
  259. #<ang412> = #<_dot:ang>
  260.  
  261. f #<feedrate>
  262. s #<rpm> m3 ;spindle cw
  263. o<if60> if [#<spin_notify> GT 0]
  264. o<spin> call [#<rpm>] ; optionally prompt user
  265. o<if60> endif
  266. g0 z#<zsafe>
  267.  
  268. ; depth loop (outer)
  269. #<zcurrent> = #<zstart>
  270. #<depthpass> = 1
  271. o<wh10> while [#<zcurrent> GT #<cutdepth>]
  272. #<zlast> = #<zcurrent>
  273. #<zcurrent> = [#<zcurrent> + #<zincr>]
  274. o<wh11> if [#<zcurrent> LT #<cutdepth>]
  275. #<zcurrent> = #<cutdepth>
  276. o<wh11> endif
  277. o<wh12> if [#<depthpass> GT #<depthpasslimit>]
  278. (print, qpocket: depthpasslimit exceeded #<depthpasslimit> - EXITING)
  279. (debug, qpocket: depthpasslimit exceeded #<depthpasslimit> - EXITING)
  280. (AXIS,notify, qpocket: depthpasslimit exceeded - EXITING)
  281. m2
  282. o<wh12> endif
  283.  
  284. o<pas1> if [#<depthpass> EQ 1]
  285. ;entry point:
  286. ;go along the 1-->2 line to enter at a point where tool will fit
  287.  
  288. #<elen12> = [ #<r> / [TAN[#<ang412>/2]]]
  289. #<k12> = [#<elen12> / #<r>]
  290. ;(print, entry 12 k=#<k12> elen12=#<elen12> angle=#<angle>)
  291. #<xentry> = [#<x1i> + #<elen12> * #<cos12>]
  292. #<yentry> = [#<y1i> + #<elen12> * #<sin12>]
  293. ;compute pre-entry points:
  294. o<dir00> if [#<dir> EQ 2] ; dir EQ 2 CW (conventional)
  295. #<prex2> = [#<xentry> + #<r> * #<sin12> - #<r> * #<cos12>]
  296. #<prey2> = [#<yentry> - #<r> * #<cos12> - #<r> * #<sin12>]
  297. #<prex1> = [#<prex2> + #<r> * #<cos12>]
  298. #<prey1> = [#<prey2> + #<r> * #<sin12>]
  299. #<vx> = [ #<r> * #<cos12>]
  300. #<vy> = [ #<r> * #<sin12>]
  301. o<dir00> else ;dir EQ 3 CCW (climb)
  302. #<prex2> = [#<xentry> - #<r> * #<sin12> - #<r> * #<cos12>]
  303. #<prey2> = [#<yentry> + #<r> * #<cos12> - #<r> * #<sin12>]
  304. #<prex1> = [#<prex2> + #<r> * #<cos12>]
  305. #<prey1> = [#<prey2> + #<r> * #<sin12>]
  306. #<vx> = [ #<r> * #<cos12>]
  307. #<vy> = [ #<r> * #<sin12>]
  308. o<dir00> endif
  309. g0 x #<prex1> y #<prey1> ;preentry 1
  310. g0 x #<prex2> y #<prey2> ;preentry 2
  311. o<dir10> if [#<dir> EQ 2] ; CW
  312. / g42 ;cutter radius comp right of path
  313. g2 x #<xentry> y #<yentry> i #<vx> j #<vy> ;arc entry
  314. o<dir10> else ;dir EQ 3 CCW
  315. / g41 ;cutter radius comp left of path
  316. g3 x #<xentry> y #<yentry> i #<vx> j #<vy> ;arc entry
  317. o<dir10> endif
  318. g1 z #<zstart> ;plunge to start height from zsafe
  319. o<pas1> else
  320. ; depthpass GT 1: return to interior entry point
  321. g1 x #<xentry> y #<yentry> z#<zlast> ; use zlast
  322. o<pas1> endif
  323.  
  324. ; outline loop (inner)
  325. #<outlinepass> = 1
  326. #<qscale> = #<qscalei>
  327. #<size> = #<sizei>
  328. o<wh20> do
  329. o<wh22> if [#<outlinepass> GT #<outlinepasslimit>]
  330. (print, qpocket: outlinepasslimit exceeded #<outlinepasslimit> - EXITING)
  331. (debug, qpocket: outlinepasslimit exceeded #<outlinepasslimit> - EXITING)
  332. (AXIS,notify,qpocket: outlinepasslimit exceeded - EXITING)
  333. m2
  334. o<wh22> endif
  335.  
  336. #<seq> = [#<outlinepass> mod 4]
  337. o<wh23> if [#<outlinepass> EQ 1]
  338. ; move through smallest interior outline
  339. g1 x #<x2i> y #<y2i> z#<zcurrent> ;ramp down to zcurrent
  340. x #<x3i> y #<y3i>
  341. x #<x4i> y #<y4i>
  342. x #<x1i> y #<y1i>
  343. x #<x2i> y #<y2i>
  344. #<outlinepass> = [#<outlinepass> + 1]
  345. o<wh23> else
  346. ; increasingly larger outlines
  347. #<size> = [#<size> + #<stepover> * #<tooldiam>]
  348. #<qscale> = [#<scale> * #<size>]
  349. #<outlinepass> = [#<outlinepass> + 1]
  350. o<wh24> if [#<qscale> GE #<scale>]
  351. #<qscale> = #<scale>
  352. #<outlinepass> = 0 ;terminate after this pass
  353. o<wh24> endif
  354. ; scale the centered feature and translate to original position
  355. o<move> call [#<x1>][#<y1>][0][#<qscale>][#<xctr>][#<yctr>]
  356. #<x1t> = #<_move:x>
  357. #<y1t> = #<_move:y>
  358. o<move> call [#<x2>][#<y2>][0][#<qscale>][#<xctr>][#<yctr>]
  359. #<x2t> = #<_move:x>
  360. #<y2t> = #<_move:y>
  361. o<move> call [#<x3>][#<y3>][0][#<qscale>][#<xctr>][#<yctr>]
  362. #<x3t> = #<_move:x>
  363. #<y3t> = #<_move:y>
  364. o<move> call [#<x4>][#<y4>][0][#<qscale>][#<xctr>][#<yctr>]
  365. #<x4t> = #<_move:x>
  366. #<y4t> = #<_move:y>
  367.  
  368. ; apply input rotation and offset
  369. o<move> call [#<x1t>][#<y1t>][#<rotate>][1][#<xoff>][#<yoff>]
  370. #<x1s> = #<_move:x>
  371. #<y1s> = #<_move:y>
  372. o<move> call [#<x2t>][#<y2t>][#<rotate>][1][#<xoff>][#<yoff>]
  373. #<x2s> = #<_move:x>
  374. #<y2s> = #<_move:y>
  375. o<move> call [#<x3t>][#<y3t>][#<rotate>][1][#<xoff>][#<yoff>]
  376. #<x3s> = #<_move:x>
  377. #<y3s> = #<_move:y>
  378. o<move> call [#<x4t>][#<y4t>][#<rotate>][1][#<xoff>][#<yoff>]
  379. #<x4s> = #<_move:x>
  380. #<y4s> = #<_move:y>
  381.  
  382. ; move through scaled interior outline
  383. o<seq0> if [#<seq> EQ 0]
  384. g1 x #<x1s> y #<y1s> z #<zcurrent>
  385. x #<x2s> y #<y2s>
  386. x #<x3s> y #<y3s>
  387. x #<x4s> y #<y4s>
  388. x #<x1s> y #<y1s>
  389. o<seq0> endif
  390. o<seq1> if [#<seq> EQ 1]
  391. g1 x #<x2s> y #<y2s> z #<zcurrent>
  392. x #<x3s> y #<y3s>
  393. x #<x4s> y #<y4s>
  394. x #<x1s> y #<y1s>
  395. x #<x2s> y #<y2s>
  396. o<seq1> endif
  397. o<seq2> if [#<seq> EQ 2]
  398. g1 x #<x3s> y #<y3s> z #<zcurrent>
  399. x #<x4s> y #<y4s>
  400. x #<x1s> y #<y1s>
  401. x #<x2s> y #<y2s>
  402. x #<x3s> y #<y3s>
  403. o<seq2> endif
  404. o<seq3> if [#<seq> EQ 3]
  405. g1 x #<x4s> y #<y4s> z #<zcurrent>
  406. x #<x1s> y #<y1s>
  407. x #<x2s> y #<y2s>
  408. x #<x3s> y #<y3s>
  409. x #<x4s> y #<y4s>
  410. o<seq3> endif
  411.  
  412. o<wh23> endif
  413.  
  414. o<wh20> while [#<outlinepass> GT 0]
  415. #<depthpass> = [#<depthpass> + 1]
  416. o<wh10> endwhile
  417.  
  418. ; after finishing at input scale, need to turn corner
  419. ; and go along the next line enough to turn off compensation
  420. o<fin0> if [#<seq> EQ 0] ;end at pt 1
  421. #<xfinal_a> = #<x1s>
  422. #<yfinal_a> = #<y1s>
  423. #<elen12> = [#<r> / [TAN[#<ang412>/2]]]
  424. #<xfinal_b> = [#<x1s> + #<elen12> * #<cos12>]
  425. #<yfinal_b> = [#<y1s> + #<elen12> * #<sin12>]
  426. o<fin0> endif
  427. o<fin1> if [#<seq> EQ 1] ;end at pt 2
  428. #<xfinal_a> = #<x2s>
  429. #<yfinal_a> = #<y2s>
  430. #<elen23> = [#<r> / [TAN[#<ang123>/2]]]
  431. #<xfinal_b> = [#<x2s> + #<elen23> * #<cos23>]
  432. #<yfinal_b> = [#<y2s> + #<elen23> * #<sin23>]
  433. o<fin1> endif
  434. o<fin2> if [#<seq> EQ 2] ;end at pt 3
  435. #<xfinal_a> = #<x3s>
  436. #<yfinal_a> = #<y3s>
  437. #<elen34> = [#<r> / [TAN[#<ang234>/2]]]
  438. #<xfinal_b> = [#<x3s> + #<elen34> * #<cos34>]
  439. #<yfinal_b> = [#<y3s> + #<elen34> * #<sin34>]
  440. o<fin2> endif
  441. o<fin3> if [#<seq> EQ 3] ;end at pt 4
  442. #<xfinal_a> = #<x4s>
  443. #<yfinal_a> = #<y4s>
  444. #<elen41> = [#<r> / [TAN[#<ang341>/2]]]
  445. #<xfinal_b> = [#<x4s> + #<elen41> * #<cos41>]
  446. #<yfinal_b> = [#<y4s> + #<elen41> * #<sin41>]
  447. o<fin3> endif
  448.  
  449. g1 x #<xfinal_a> y #<yfinal_a>
  450. g1 x #<xfinal_b> y #<yfinal_b>
  451.  
  452. g0 z #<zsafe>
  453. g40 ;cutter radius compensation off
  454.  
  455. o<qpocket> endsub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement