Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; LinuxCNC
- ; ----- Updated by Library -----
- ; http://www.linuxcnc.org/index.php/english/forum/31-cad-cam/1307-solidcam-to-emc2-post-processor?start=10
- ; List of improvements over Robo-Dan's post processor (thanks to icizrt and spangledboy)
- ; G33.1 rigid tapping support (must have mill setup to do rigid tapping).
- ; Clearer naming. Instead of Fanuc5a the controller is called LinuxCNC.
- ; Prints out a list of all the tools used in the job at the top of the gcode output including their descriptive names.
- ; Uses LinuxCNC DEBUG command to print out the tool needed at each tool change.
- ; Outputs gcode files with .ngc extension instead of .tap
- ; Increased precision which is especially handy with tapping and pockets
- ; General cleanup of all commented out areas
- @init_post
- global string tool_diameter_f
- global numeric flag1 flag2 m_feed_flag
- global integer oword
- global integer owordnext
- global integer loop_num
- ; Non GPPL variables
- num_user_procs = 1
- line_labels = FALSE ; Jump to N...
- ; GPPL variables
- pre_processor = 'LinuxCNC'
- numeric_def_f = '5.5' ; Need 5 digits precision so tap TPI are more accurate
- integer_def_f = '5.0(p)'
- gcode_f = '2.0(p)'
- mcode_f = '2.0(p)'
- xpos_f = '5.4'
- ypos_f = '5.4'
- zpos_f = '5.4'
- feed_f = '4.3(p)'
- tool_diameter_f = '5.4/1'
- blknum_f = '5.0(p)'
- blknum_gen = false
- blknum_exist = true
- blknum = 1
- blknum_delta = 1
- blknum_max = 32000
- ;trace 'all':5
- endp
- ;-------------------
- @start_of_file
- ; before tools definition
- {'%'}
- {nl, '(',g_file_name, ')'}
- {nl, '( MCV-OP )', ' (',DATE ')'}
- oword = 501
- owordnext = 501
- if rotate_used then
- gcode = 69
- {nb, 'G'gcode}
- endif
- if mirror_used then
- {nb, 'G50.1 X0 Y0'}
- endif
- {nb, '(SUBROUTINES: O'first_proc_number, ' .. O'last_proc_number, ')'}
- {nb, 'G92.1'}
- {nb, '(################################)'}
- {nb, '(Tools used in this file)'}
- flag2 = 0
- endp
- ;-------------------
- @start_program
- ; after tools definition
- {nb, '(################################)'}
- {nb, 'G80 G49 G40'}
- endp
- ;-------------------
- @end_program
- ;; Turn off coolant
- {nb, 'M9'}
- {nb, 'M30'}
- {nb, 'G92.1'}
- endp
- ;-------------------
- @end_of_file
- {nl, '%'}
- endp
- ;-------------------
- @relative_mode
- gcode = 91
- {nb, 'G'gcode, ' '}
- skipline = FALSE
- endp
- ;-------------------
- @absolute_mode
- gcode = 90
- {nb, 'G'gcode, ' '}
- skipline = FALSE
- endp
- ;-------------------
- @machine_plane
- if machine_plane eq XY
- gcode = 17
- endif
- if machine_plane eq YZ
- gcode = 18
- endif
- if machine_plane eq ZX
- gcode = 19
- endif
- {nb, 'G'gcode}
- endp
- ;-------------------
- @call_proc
- if active(parm1) then
- gcode = 65
- {nb, 'G'gcode, ' P'label}
- {' A'parm1, [' B'parm2], [' C'parm3]}
- else
- {nb, 'M98 P'label}
- endif
- if proc_count gt 1 then
- {' L'proc_count}
- endif
- {[' ('message, ')']}
- endp
- ;-------------------
- @proc
- {nl, 'O'label}
- endp
- ;-------------------
- @end_proc
- if dely eq 1
- {' G64 '}
- endif
- {nb, 'M99'}
- endp
- ;----------------
- @loop
- local integer var_num
- var_num = loop_level + 20
- {nb, '#', var_num, ' = 0'}
- oword = owordnext
- ; {nb, '#<loop_level> = ', loop_level}
- ; {nb, '#<loop_count> = ', loop_count}
- ;if oword eq owordnext then
- {nb, 'O',oword,' WHILE [#', var_num, ' LT ', loop_count, ']'}
- oword = oword + 1
- ;else
- ; {nb, 'O',owordnext,' WHILE [#', var_num, ' LT ', loop_count, ']'}
- ; oword = owordnext
- ;endif
- owordnext = owordnext +1
- endp
- ;----------------
- @end_loop
- local integer home_num
- local integer var_num
- var_num = loop_level + 20
- ; {nb '(CODE TO END THE LOOP - START)'}
- {nb '#', var_num, ' = [#', var_num, ' + 1]'}
- loop_num = var_num
- home_num = 53 + home_number
- {nb 'G'home_num}
- oword = oword - 1
- {nb 'O',oword,' ENDWHILE'}
- endp
- ;----------------
- @def_tool
- {nb, '(Tool Number=' tool_number ' Tool Diameter=' tool_diameter ' - ' tool_message ' - ' tool_user_type')'}
- endp
- ;-------------------
- @rapid_move
- {nb}
- gcode = 0
- if change(gcode) then
- {'G'gcode}
- else
- {' '}
- endif
- {[' X'xpos], [' Y'ypos], [' Z'zpos]}
- endp
- ;-------------------
- @line
- {nb}
- gcode = 1
- if change(gcode) then
- {'G'gcode}
- else
- {' '}
- endif
- {[' X'xpos], [' Y'ypos], [' Z'zpos]}
- if m_feed_flag eq 1
- m_feed_flag = 0
- { ' F'feed}
- else
- { [' F'feed]}
- endif
- endp
- ;-------------------
- @arc
- {nb}
- if arc_direction eq CCW then
- gcode = 3
- else ; CW
- gcode = 2
- endif
- if change(gcode) then
- {'G'gcode}
- else
- {' '}
- endif
- {[' X'xpos] [' Y'ypos] [' Z'zpos]}
- if arc_size eq 360 then
- if arc_plane eq XY then
- {' I'xcenter_rel, ' J'ycenter_rel}
- endif
- if arc_plane eq YZ then
- {' J'xcenter_rel, ' K'ycenter_rel}
- endif
- if arc_plane eq ZX then
- {' K'xcenter_rel, ' I'ycenter_rel}
- endif
- else
- if arc_size >= 180 then
- radius = -radius
- endif
- {' R'radius}
- endif
- if m_feed_flag eq 1
- m_feed_flag = 0
- { ' F'feed}
- else
- { [' F'feed]}
- endif
- endp
- ;-------------------
- @compensation
- if side eq COMP_LEFT then
- gcode = 41
- endif
- if side eq COMP_RIGHT then
- gcode = 42
- endif
- if side eq COMP_OFF then
- gcode = 40
- endif
- {nb, 'G'gcode, ' '}
- skipline = FALSE
- endp
- ;-------------------
- @delay
- gcode = 4
- {nb 'G'gcode, ' P'delay_period:integer_def_f}
- endp
- ;-------------------
- @change_ref_point
- ; Given in absolute mode
- local integer var_num
- var_num = loop_level + 20
- {nb, 'G0 Z50'}
- {nb, 'G0 X0 Y0'}
- endp
- ;-------------------
- @home_number
- gcode = 53 + home_number
- {nb, 'G'gcode}
- flag2 = 1
- endp
- ;-------------------
- @rotate
- ; Not exist in FANUC 6M
- if rotate_cancel then
- gcode = 69
- {nb, 'G'gcode}
- else
- gcode = 68
- {nb, 'G'gcode, ' X0 Y0 G91 R'angle}
- {nb, 'G90'}
- endif
- endp
- ;-------------------
- @fourth_axis
- gcode = 0
- {nb, 'G'gcode, ' A'angle}
- endp
- ;-------------------
- @change_tool
- {nb, 'G92.1'}
- {nb, 'G54'}
- {nb, 'G30'}
- if flag2 eq 0
- call @home_number
- endif
- flag2 = 1
- local logical save_blknum_gen
- {nb, '(######################################################)'}
- {nb, '(DEBUG, Change to ' tool_message ' - ' tool_user_type ' with diameter ' tool_diameter ' then click Resume)'}
- blknum_gen = true
- {nb, 'M6 T'tool_number}
- blknum_gen = FALSE
- if tool_type eq 0 then
- {nb, '( TOOL -'tool_number, '- DRILL DIA 'tool_diameter, ' inches )'}
- endif
- if tool_type eq 1 then
- {nb, '( TOOL -'tool_number, '- ROUGH DIA 'tool_diameter, ' inches )'}
- endif
- if tool_type eq 2 then
- {nb, '(TOOL -'tool_number, '- MILL DIA 'tool_diameter, ' R'corner_radius,' inches )'}
- endif
- ;{nb, 'G90 G00 G40 G'(53 + home_number)}
- label = first_user_proc
- save_blknum_gen = blknum_gen
- ; ### Uncomment this to get tool length compensation working
- ;gcode = 43
- ;{nb, 'G'gcode, ' H'tool_number, ' '}
- {nb, ' '}
- blknum_gen = save_blknum_gen
- xpos = xnext
- ypos = ynext
- zpos = znext
- skipline = FALSE
- call @rapid_move
- tool_direction = CCW
- call @start_tool
- if colent eq 0
- {nb, 'M8'}
- endif
- if colent eq 17
- {nb, 'M17'}
- endif
- if colent eq 18
- {nb, 'M18'}
- endif
- endp
- ;-------------------
- @message
- {nb, '(', message, ')'}
- endp
- ;-------------------
- @drill
- call @rapid_move
- if drill_type eq drilling then
- gcode = 81
- endif
- if drill_type eq f_drill then
- gcode = 82
- endif
- if drill_type eq peck then
- gcode = 83
- endif
- if drill_type eq tapping then
- gcode = 33.1
- endif
- if drill_type eq boring then
- gcode = 85
- endif
- if drill_type eq r_boring then
- gcode = 86
- endif
- if drill_type eq f_boring then
- gcode = 89
- endif
- ;; Rigid tapping is special in linuxcnc - G33.1
- if drill_type eq tapping then
- {nb,'G98 G33.1 Z'drill_lower_z, ' K'feed_teeth}
- endif
- ;; Exclude rigid tapping since we already did that
- if drill_type ne tapping then
- {nb,'G98 G'gcode, ' Z'drill_lower_z, ' R'drill_upper_z}
- if drill_type eq peck then
- {' Q'down_step}
- endif
- if drill_type eq f_drill
- {' P'delay:integer_def_f}
- endif
- {' F'feed}
- endif
- endp
- ;-------------------
- @drill_point
- if not first_drill then
- ;;rigid tapping needs the G0 coordinates each line because it doesn't think G33.1 is a motion mode
- if drill_type eq tapping then
- {nb, ' '}
- {nb, 'G0'[' X'xpos], [' Y'ypos], [' Z'zpos]}
- {nb, 'G98 G33.1 Z'drill_lower_z, ' K'feed_teeth}
- endif
- if drill_type ne tapping then
- {nb, ' ', [' X'xpos], [' Y'ypos], [' Z'zpos]}
- endif
- endif
- endp
- ;-------------------
- @mirror
- if mirror_type eq MIRROR_OFF then
- {nb, 'G50.1 X0 Y0'}
- else
- {nb, 'G51.1 '}
- if mirror_type eq MIRROR_X then
- {'X1 Y0'}
- endif
- if mirror_type eq MIRROR_Y then
- {'X0 Y1'}
- endif
- if mirror_type eq MIRROR_XY then
- {'X1 Y1'}
- endif
- endif
- endp
- ;-------------------
- @end_drill
- gcode = 80
- {nb, 'G'gcode}
- endp
- ;-------------------
- @halt_program
- {' M0'}
- endp
- ;--------------------
- @round_comp
- ; NOP
- endp
- ;--------------------
- @start_of_job
- ;runs at the start of every machining operation
- if dely eq 1
- {nb, 'G61'}
- endif
- endp
- ;--------------------
- @end_of_job
- ; NOP
- endp
- ;--------------------
- @assign_axis
- ; TBD
- endp
- ; =======================
- ; USER DEFINED PROCEDURES
- ; =======================
- @call_simple_proc
- active(message) = FALSE
- active(parm1) = FALSE
- active(parm2) = FALSE
- active(parm3) = FALSE
- proc_count = 1
- call @call_proc
- endp
- ;-------------------
- @start_tool
- if tool_direction eq CW then
- mcode = 4
- else ; CCW
- mcode = 3
- endif
- {'S'spin:integer_def_f, ' M'mcode}
- endp
- ;-------------------
- @m_feed_spin
- ; if tool_direction eq CW then
- ; mcode = 4
- ; else ; CCW
- ; mcode = 3
- ; endif
- ; if change(spin)
- ; {nb,'S'spin:integer_def_f, ' M'mcode}
- ; endif
- m_feed_flag = 1
- endp
- ;-------------------
- @stop_tool
- ; {' M5'}
- endp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement