Advertisement
Guest User

Untitled

a guest
Jun 15th, 2015
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.16 KB | None | 0 0
  1. ;; LinuxCNC
  2. ; ----- Updated by Library -----
  3. ; http://www.linuxcnc.org/index.php/english/forum/31-cad-cam/1307-solidcam-to-emc2-post-processor?start=10
  4. ; List of improvements over Robo-Dan's post processor (thanks to icizrt and spangledboy)
  5.  
  6. ; G33.1 rigid tapping support (must have mill setup to do rigid tapping).
  7. ; Clearer naming. Instead of Fanuc5a the controller is called LinuxCNC.
  8. ; Prints out a list of all the tools used in the job at the top of the gcode output including their descriptive names.
  9. ; Uses LinuxCNC DEBUG command to print out the tool needed at each tool change.
  10. ; Outputs gcode files with .ngc extension instead of .tap
  11. ; Increased precision which is especially handy with tapping and pockets
  12. ; General cleanup of all commented out areas
  13.  
  14. @init_post
  15. global string tool_diameter_f
  16. global numeric flag1 flag2 m_feed_flag
  17. global integer oword
  18. global integer owordnext
  19.  
  20. global integer loop_num
  21.  
  22. ; Non GPPL variables
  23. num_user_procs = 1
  24. line_labels = FALSE ; Jump to N...
  25.  
  26. ; GPPL variables
  27. pre_processor = 'LinuxCNC'
  28. numeric_def_f = '5.5' ; Need 5 digits precision so tap TPI are more accurate
  29. integer_def_f = '5.0(p)'
  30. gcode_f = '2.0(p)'
  31. mcode_f = '2.0(p)'
  32. xpos_f = '5.4'
  33. ypos_f = '5.4'
  34. zpos_f = '5.4'
  35. feed_f = '4.3(p)'
  36. tool_diameter_f = '5.4/1'
  37. blknum_f = '5.0(p)'
  38. blknum_gen = false
  39. blknum_exist = true
  40. blknum = 1
  41. blknum_delta = 1
  42. blknum_max = 32000
  43. ;trace 'all':5
  44. endp
  45.  
  46. ;-------------------
  47.  
  48. @start_of_file
  49. ; before tools definition
  50. {'%'}
  51. {nl, '(',g_file_name, ')'}
  52. {nl, '( MCV-OP )', ' (',DATE ')'}
  53.  
  54. oword = 501
  55. owordnext = 501
  56.  
  57. if rotate_used then
  58. gcode = 69
  59. {nb, 'G'gcode}
  60. endif
  61. if mirror_used then
  62. {nb, 'G50.1 X0 Y0'}
  63. endif
  64. {nb, '(SUBROUTINES: O'first_proc_number, ' .. O'last_proc_number, ')'}
  65. {nb, 'G92.1'}
  66. {nb, '(################################)'}
  67. {nb, '(Tools used in this file)'}
  68. flag2 = 0
  69. endp
  70.  
  71. ;-------------------
  72.  
  73. @start_program
  74. ; after tools definition
  75. {nb, '(################################)'}
  76. {nb, 'G80 G49 G40'}
  77. endp
  78.  
  79. ;-------------------
  80.  
  81. @end_program
  82. ;; Turn off coolant
  83. {nb, 'M9'}
  84. {nb, 'M30'}
  85. {nb, 'G92.1'}
  86. endp
  87.  
  88. ;-------------------
  89.  
  90. @end_of_file
  91. {nl, '%'}
  92. endp
  93.  
  94. ;-------------------
  95.  
  96. @relative_mode
  97. gcode = 91
  98. {nb, 'G'gcode, ' '}
  99. skipline = FALSE
  100. endp
  101.  
  102. ;-------------------
  103.  
  104. @absolute_mode
  105. gcode = 90
  106. {nb, 'G'gcode, ' '}
  107. skipline = FALSE
  108. endp
  109.  
  110. ;-------------------
  111.  
  112. @machine_plane
  113. if machine_plane eq XY
  114. gcode = 17
  115. endif
  116. if machine_plane eq YZ
  117. gcode = 18
  118. endif
  119. if machine_plane eq ZX
  120. gcode = 19
  121. endif
  122. {nb, 'G'gcode}
  123. endp
  124.  
  125. ;-------------------
  126.  
  127. @call_proc
  128. if active(parm1) then
  129. gcode = 65
  130. {nb, 'G'gcode, ' P'label}
  131.  
  132. {' A'parm1, [' B'parm2], [' C'parm3]}
  133. else
  134. {nb, 'M98 P'label}
  135. endif
  136. if proc_count gt 1 then
  137. {' L'proc_count}
  138. endif
  139. {[' ('message, ')']}
  140. endp
  141.  
  142. ;-------------------
  143.  
  144. @proc
  145. {nl, 'O'label}
  146. endp
  147.  
  148. ;-------------------
  149.  
  150. @end_proc
  151. if dely eq 1
  152. {' G64 '}
  153. endif
  154. {nb, 'M99'}
  155. endp
  156.  
  157. ;----------------
  158.  
  159. @loop
  160. local integer var_num
  161. var_num = loop_level + 20
  162. {nb, '#', var_num, ' = 0'}
  163. oword = owordnext
  164. ; {nb, '#<loop_level> = ', loop_level}
  165. ; {nb, '#<loop_count> = ', loop_count}
  166.  
  167. ;if oword eq owordnext then
  168. {nb, 'O',oword,' WHILE [#', var_num, ' LT ', loop_count, ']'}
  169. oword = oword + 1
  170. ;else
  171. ; {nb, 'O',owordnext,' WHILE [#', var_num, ' LT ', loop_count, ']'}
  172. ; oword = owordnext
  173. ;endif
  174. owordnext = owordnext +1
  175. endp
  176.  
  177. ;----------------
  178.  
  179. @end_loop
  180. local integer home_num
  181. local integer var_num
  182.  
  183. var_num = loop_level + 20
  184. ; {nb '(CODE TO END THE LOOP - START)'}
  185. {nb '#', var_num, ' = [#', var_num, ' + 1]'}
  186. loop_num = var_num
  187.  
  188. home_num = 53 + home_number
  189. {nb 'G'home_num}
  190.  
  191. oword = oword - 1
  192.  
  193.  
  194. {nb 'O',oword,' ENDWHILE'}
  195.  
  196. endp
  197.  
  198. ;----------------
  199.  
  200. @def_tool
  201. {nb, '(Tool Number=' tool_number ' Tool Diameter=' tool_diameter ' - ' tool_message ' - ' tool_user_type')'}
  202. endp
  203.  
  204. ;-------------------
  205.  
  206. @rapid_move
  207. {nb}
  208. gcode = 0
  209. if change(gcode) then
  210. {'G'gcode}
  211. else
  212. {' '}
  213. endif
  214. {[' X'xpos], [' Y'ypos], [' Z'zpos]}
  215.  
  216. endp
  217.  
  218. ;-------------------
  219.  
  220. @line
  221. {nb}
  222. gcode = 1
  223. if change(gcode) then
  224. {'G'gcode}
  225. else
  226. {' '}
  227. endif
  228. {[' X'xpos], [' Y'ypos], [' Z'zpos]}
  229. if m_feed_flag eq 1
  230. m_feed_flag = 0
  231. { ' F'feed}
  232. else
  233. { [' F'feed]}
  234. endif
  235. endp
  236.  
  237. ;-------------------
  238.  
  239. @arc
  240. {nb}
  241.  
  242. if arc_direction eq CCW then
  243. gcode = 3
  244. else ; CW
  245. gcode = 2
  246. endif
  247. if change(gcode) then
  248. {'G'gcode}
  249. else
  250. {' '}
  251. endif
  252. {[' X'xpos] [' Y'ypos] [' Z'zpos]}
  253.  
  254. if arc_size eq 360 then
  255. if arc_plane eq XY then
  256. {' I'xcenter_rel, ' J'ycenter_rel}
  257. endif
  258. if arc_plane eq YZ then
  259. {' J'xcenter_rel, ' K'ycenter_rel}
  260. endif
  261. if arc_plane eq ZX then
  262. {' K'xcenter_rel, ' I'ycenter_rel}
  263. endif
  264. else
  265. if arc_size >= 180 then
  266. radius = -radius
  267. endif
  268. {' R'radius}
  269. endif
  270. if m_feed_flag eq 1
  271. m_feed_flag = 0
  272. { ' F'feed}
  273. else
  274. { [' F'feed]}
  275. endif
  276.  
  277. endp
  278.  
  279. ;-------------------
  280.  
  281. @compensation
  282. if side eq COMP_LEFT then
  283. gcode = 41
  284. endif
  285. if side eq COMP_RIGHT then
  286. gcode = 42
  287. endif
  288. if side eq COMP_OFF then
  289. gcode = 40
  290. endif
  291. {nb, 'G'gcode, ' '}
  292. skipline = FALSE
  293. endp
  294.  
  295. ;-------------------
  296.  
  297. @delay
  298. gcode = 4
  299. {nb 'G'gcode, ' P'delay_period:integer_def_f}
  300. endp
  301.  
  302. ;-------------------
  303.  
  304. @change_ref_point
  305. ; Given in absolute mode
  306.  
  307. local integer var_num
  308. var_num = loop_level + 20
  309. {nb, 'G0 Z50'}
  310. {nb, 'G0 X0 Y0'}
  311.  
  312. endp
  313.  
  314. ;-------------------
  315.  
  316. @home_number
  317. gcode = 53 + home_number
  318. {nb, 'G'gcode}
  319. flag2 = 1
  320. endp
  321.  
  322. ;-------------------
  323.  
  324. @rotate
  325. ; Not exist in FANUC 6M
  326. if rotate_cancel then
  327. gcode = 69
  328. {nb, 'G'gcode}
  329. else
  330. gcode = 68
  331. {nb, 'G'gcode, ' X0 Y0 G91 R'angle}
  332. {nb, 'G90'}
  333. endif
  334. endp
  335.  
  336. ;-------------------
  337.  
  338. @fourth_axis
  339. gcode = 0
  340. {nb, 'G'gcode, ' A'angle}
  341. endp
  342.  
  343. ;-------------------
  344.  
  345. @change_tool
  346. {nb, 'G92.1'}
  347. {nb, 'G54'}
  348. {nb, 'G30'}
  349. if flag2 eq 0
  350. call @home_number
  351. endif
  352. flag2 = 1
  353. local logical save_blknum_gen
  354. {nb, '(######################################################)'}
  355. {nb, '(DEBUG, Change to ' tool_message ' - ' tool_user_type ' with diameter ' tool_diameter ' then click Resume)'}
  356. blknum_gen = true
  357. {nb, 'M6 T'tool_number}
  358. blknum_gen = FALSE
  359. if tool_type eq 0 then
  360. {nb, '( TOOL -'tool_number, '- DRILL DIA 'tool_diameter, ' inches )'}
  361. endif
  362. if tool_type eq 1 then
  363. {nb, '( TOOL -'tool_number, '- ROUGH DIA 'tool_diameter, ' inches )'}
  364. endif
  365. if tool_type eq 2 then
  366. {nb, '(TOOL -'tool_number, '- MILL DIA 'tool_diameter, ' R'corner_radius,' inches )'}
  367. endif
  368. ;{nb, 'G90 G00 G40 G'(53 + home_number)}
  369. label = first_user_proc
  370. save_blknum_gen = blknum_gen
  371.  
  372. ; ### Uncomment this to get tool length compensation working
  373. ;gcode = 43
  374. ;{nb, 'G'gcode, ' H'tool_number, ' '}
  375.  
  376. {nb, ' '}
  377. blknum_gen = save_blknum_gen
  378. xpos = xnext
  379. ypos = ynext
  380. zpos = znext
  381. skipline = FALSE
  382. call @rapid_move
  383. tool_direction = CCW
  384. call @start_tool
  385. if colent eq 0
  386. {nb, 'M8'}
  387. endif
  388. if colent eq 17
  389. {nb, 'M17'}
  390. endif
  391. if colent eq 18
  392. {nb, 'M18'}
  393. endif
  394.  
  395.  
  396. endp
  397.  
  398. ;-------------------
  399.  
  400. @message
  401. {nb, '(', message, ')'}
  402. endp
  403.  
  404. ;-------------------
  405.  
  406. @drill
  407. call @rapid_move
  408.  
  409. if drill_type eq drilling then
  410. gcode = 81
  411. endif
  412. if drill_type eq f_drill then
  413. gcode = 82
  414. endif
  415. if drill_type eq peck then
  416. gcode = 83
  417. endif
  418. if drill_type eq tapping then
  419. gcode = 33.1
  420. endif
  421. if drill_type eq boring then
  422. gcode = 85
  423. endif
  424. if drill_type eq r_boring then
  425. gcode = 86
  426. endif
  427. if drill_type eq f_boring then
  428. gcode = 89
  429. endif
  430. ;; Rigid tapping is special in linuxcnc - G33.1
  431. if drill_type eq tapping then
  432. {nb,'G98 G33.1 Z'drill_lower_z, ' K'feed_teeth}
  433. endif
  434. ;; Exclude rigid tapping since we already did that
  435. if drill_type ne tapping then
  436. {nb,'G98 G'gcode, ' Z'drill_lower_z, ' R'drill_upper_z}
  437.  
  438. if drill_type eq peck then
  439. {' Q'down_step}
  440. endif
  441. if drill_type eq f_drill
  442. {' P'delay:integer_def_f}
  443. endif
  444. {' F'feed}
  445. endif
  446.  
  447. endp
  448.  
  449. ;-------------------
  450.  
  451. @drill_point
  452. if not first_drill then
  453. ;;rigid tapping needs the G0 coordinates each line because it doesn't think G33.1 is a motion mode
  454. if drill_type eq tapping then
  455. {nb, ' '}
  456. {nb, 'G0'[' X'xpos], [' Y'ypos], [' Z'zpos]}
  457. {nb, 'G98 G33.1 Z'drill_lower_z, ' K'feed_teeth}
  458. endif
  459. if drill_type ne tapping then
  460. {nb, ' ', [' X'xpos], [' Y'ypos], [' Z'zpos]}
  461. endif
  462. endif
  463. endp
  464.  
  465. ;-------------------
  466.  
  467. @mirror
  468. if mirror_type eq MIRROR_OFF then
  469. {nb, 'G50.1 X0 Y0'}
  470. else
  471. {nb, 'G51.1 '}
  472. if mirror_type eq MIRROR_X then
  473. {'X1 Y0'}
  474. endif
  475. if mirror_type eq MIRROR_Y then
  476. {'X0 Y1'}
  477. endif
  478. if mirror_type eq MIRROR_XY then
  479. {'X1 Y1'}
  480. endif
  481. endif
  482. endp
  483.  
  484. ;-------------------
  485.  
  486. @end_drill
  487. gcode = 80
  488. {nb, 'G'gcode}
  489. endp
  490.  
  491. ;-------------------
  492.  
  493. @halt_program
  494. {' M0'}
  495. endp
  496.  
  497. ;--------------------
  498.  
  499. @round_comp
  500. ; NOP
  501. endp
  502.  
  503. ;--------------------
  504.  
  505. @start_of_job
  506. ;runs at the start of every machining operation
  507. if dely eq 1
  508. {nb, 'G61'}
  509. endif
  510. endp
  511.  
  512. ;--------------------
  513.  
  514. @end_of_job
  515. ; NOP
  516. endp
  517.  
  518. ;--------------------
  519.  
  520. @assign_axis
  521. ; TBD
  522. endp
  523.  
  524. ; =======================
  525. ; USER DEFINED PROCEDURES
  526. ; =======================
  527.  
  528. @call_simple_proc
  529. active(message) = FALSE
  530. active(parm1) = FALSE
  531. active(parm2) = FALSE
  532. active(parm3) = FALSE
  533. proc_count = 1
  534. call @call_proc
  535. endp
  536.  
  537. ;-------------------
  538.  
  539. @start_tool
  540. if tool_direction eq CW then
  541. mcode = 4
  542. else ; CCW
  543. mcode = 3
  544. endif
  545. {'S'spin:integer_def_f, ' M'mcode}
  546. endp
  547.  
  548.  
  549. ;-------------------
  550.  
  551. @m_feed_spin
  552. ; if tool_direction eq CW then
  553. ; mcode = 4
  554. ; else ; CCW
  555. ; mcode = 3
  556. ; endif
  557. ; if change(spin)
  558. ; {nb,'S'spin:integer_def_f, ' M'mcode}
  559. ; endif
  560. m_feed_flag = 1
  561. endp
  562.  
  563. ;-------------------
  564.  
  565. @stop_tool
  566. ; {' M5'}
  567. endp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement