Advertisement
Guest User

Untitled

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