2019-03-10 13:22:16 +00:00
|
|
|
############################################################
|
|
|
|
# FlatCAM: 2D Post-processing for Manufacturing #
|
|
|
|
# http://flatcam.org #
|
|
|
|
# File Author: Marius Adrian Stanciu (c) #
|
|
|
|
# Date: 3/10/2019 #
|
|
|
|
# MIT Licence #
|
|
|
|
############################################################
|
|
|
|
|
2019-02-02 22:11:17 +00:00
|
|
|
from FlatCAMPostProc import *
|
|
|
|
|
|
|
|
|
2019-02-04 14:29:12 +00:00
|
|
|
class Toolchange_Probe_MACH3(FlatCAMPostProc):
|
2019-02-02 22:11:17 +00:00
|
|
|
|
|
|
|
coordinate_format = "%.*f"
|
|
|
|
feedrate_format = '%.*f'
|
|
|
|
|
|
|
|
def start_code(self, p):
|
|
|
|
units = ' ' + str(p['units']).lower()
|
2019-02-28 16:02:29 +00:00
|
|
|
coords_xy = p['xy_toolchange']
|
2019-02-02 22:11:17 +00:00
|
|
|
gcode = ''
|
|
|
|
|
|
|
|
xmin = '%.*f' % (p.coords_decimals, p['options']['xmin'])
|
|
|
|
xmax = '%.*f' % (p.coords_decimals, p['options']['xmax'])
|
|
|
|
ymin = '%.*f' % (p.coords_decimals, p['options']['ymin'])
|
|
|
|
ymax = '%.*f' % (p.coords_decimals, p['options']['ymax'])
|
|
|
|
|
|
|
|
if str(p['options']['type']) == 'Geometry':
|
|
|
|
gcode += '(TOOL DIAMETER: ' + str(p['options']['tool_dia']) + units + ')\n'
|
|
|
|
|
|
|
|
gcode += '(Feedrate: ' + str(p['feedrate']) + units + '/min' + ')\n'
|
|
|
|
|
|
|
|
if str(p['options']['type']) == 'Geometry':
|
2019-02-28 16:02:29 +00:00
|
|
|
gcode += '(Feedrate_Z: ' + str(p['z_feedrate']) + units + '/min' + ')\n'
|
2019-02-02 22:11:17 +00:00
|
|
|
|
|
|
|
gcode += '(Feedrate rapids ' + str(p['feedrate_rapid']) + units + '/min' + ')\n' + '\n'
|
2019-02-05 17:40:46 +00:00
|
|
|
gcode += '(Feedrate Probe ' + str(p['feedrate_probe']) + units + '/min' + ')\n' + '\n'
|
2019-02-02 22:11:17 +00:00
|
|
|
gcode += '(Z_Cut: ' + str(p['z_cut']) + units + ')\n'
|
|
|
|
|
|
|
|
if str(p['options']['type']) == 'Geometry':
|
|
|
|
if p['multidepth'] is True:
|
2019-02-28 16:02:29 +00:00
|
|
|
gcode += '(DepthPerCut: ' + str(p['z_depthpercut']) + units + ' <=>' + \
|
|
|
|
str(math.ceil(abs(p['z_cut']) / p['z_depthpercut'])) + ' passes' + ')\n'
|
2019-02-02 22:11:17 +00:00
|
|
|
|
|
|
|
gcode += '(Z_Move: ' + str(p['z_move']) + units + ')\n'
|
2019-02-28 16:02:29 +00:00
|
|
|
gcode += '(Z Toolchange: ' + str(p['z_toolchange']) + units + ')\n'
|
2019-02-02 22:11:17 +00:00
|
|
|
|
|
|
|
if coords_xy is not None:
|
|
|
|
gcode += '(X,Y Toolchange: ' + "%.4f, %.4f" % (coords_xy[0], coords_xy[1]) + units + ')\n'
|
|
|
|
else:
|
|
|
|
gcode += '(X,Y Toolchange: ' + "None" + units + ')\n'
|
|
|
|
|
|
|
|
gcode += '(Z Start: ' + str(p['startz']) + units + ')\n'
|
2019-02-28 16:02:29 +00:00
|
|
|
gcode += '(Z End: ' + str(p['z_end']) + units + ')\n'
|
2019-02-05 17:40:46 +00:00
|
|
|
gcode += '(Z Probe Depth: ' + str(p['z_pdepth']) + units + ')\n'
|
2019-02-02 22:11:17 +00:00
|
|
|
gcode += '(Steps per circle: ' + str(p['steps_per_circle']) + ')\n'
|
|
|
|
|
|
|
|
if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
|
|
|
|
gcode += '(Postprocessor Excellon: ' + str(p['pp_excellon_name']) + ')\n'
|
|
|
|
else:
|
|
|
|
gcode += '(Postprocessor Geometry: ' + str(p['pp_geometry_name']) + ')\n' + '\n'
|
|
|
|
|
|
|
|
gcode += '(X range: ' + '{: >9s}'.format(xmin) + ' ... ' + '{: >9s}'.format(xmax) + ' ' + units + ')\n'
|
|
|
|
gcode += '(Y range: ' + '{: >9s}'.format(ymin) + ' ... ' + '{: >9s}'.format(ymax) + ' ' + units + ')\n\n'
|
|
|
|
|
|
|
|
gcode += '(Spindle Speed: %s RPM)\n' % str(p['spindlespeed'])
|
|
|
|
|
|
|
|
gcode += ('G20\n' if p.units.upper() == 'IN' else 'G21\n')
|
|
|
|
gcode += 'G90\n'
|
2019-02-05 14:43:12 +00:00
|
|
|
gcode += 'G17\n'
|
2019-02-02 22:11:17 +00:00
|
|
|
gcode += 'G94\n'
|
2019-02-10 21:04:37 +00:00
|
|
|
gcode += '(MSG, WARNING: Make sure you do zero on all axis. ' \
|
2019-02-25 17:42:56 +00:00
|
|
|
'For Z axis, since it will be probed, make a rough estimate and do a zero.)\n'
|
2019-02-10 21:04:37 +00:00
|
|
|
gcode += 'M0'
|
2019-02-02 22:11:17 +00:00
|
|
|
|
|
|
|
return gcode
|
|
|
|
|
|
|
|
def startz_code(self, p):
|
2019-02-04 14:29:12 +00:00
|
|
|
return ''
|
2019-02-02 22:11:17 +00:00
|
|
|
|
|
|
|
def lift_code(self, p):
|
|
|
|
return 'G00 Z' + self.coordinate_format%(p.coords_decimals, p.z_move)
|
|
|
|
|
|
|
|
def down_code(self, p):
|
|
|
|
return 'G01 Z' + self.coordinate_format%(p.coords_decimals, p.z_cut)
|
|
|
|
|
|
|
|
def toolchange_code(self, p):
|
2019-02-28 16:02:29 +00:00
|
|
|
z_toolchange = p.z_toolchange
|
|
|
|
toolchangexy = p.xy_toolchange
|
2019-02-02 22:11:17 +00:00
|
|
|
f_plunge = p.f_plunge
|
2019-02-10 21:36:59 +00:00
|
|
|
|
2019-02-02 22:11:17 +00:00
|
|
|
gcode = ''
|
|
|
|
|
|
|
|
if toolchangexy is not None:
|
2019-02-28 16:02:29 +00:00
|
|
|
x_toolchange = toolchangexy[0]
|
|
|
|
y_toolchange = toolchangexy[1]
|
2019-02-02 22:11:17 +00:00
|
|
|
|
|
|
|
no_drills = 1
|
|
|
|
|
|
|
|
if int(p.tool) == 1 and p.startz is not None:
|
2019-02-28 16:02:29 +00:00
|
|
|
z_toolchange = p.startz
|
2019-02-02 22:11:17 +00:00
|
|
|
|
|
|
|
if p.units.upper() == 'MM':
|
|
|
|
toolC_formatted = format(p.toolC, '.2f')
|
|
|
|
else:
|
|
|
|
toolC_formatted = format(p.toolC, '.4f')
|
|
|
|
|
|
|
|
if str(p['options']['type']) == 'Excellon':
|
|
|
|
for i in p['options']['Tools_in_use']:
|
|
|
|
if i[0] == p.tool:
|
|
|
|
no_drills = i[2]
|
|
|
|
|
|
|
|
if toolchangexy is not None:
|
2019-02-10 11:42:22 +00:00
|
|
|
gcode = """
|
|
|
|
M5
|
2019-02-02 22:11:17 +00:00
|
|
|
T{tool}
|
2019-02-05 17:40:46 +00:00
|
|
|
M6
|
2019-02-28 16:02:29 +00:00
|
|
|
G00 Z{z_toolchange}
|
|
|
|
G00 X{x_toolchange} Y{y_toolchange}
|
2019-02-10 21:36:59 +00:00
|
|
|
(MSG, Change to Tool Dia = {toolC} ||| CONNECT THE PROBE ||| Drills for this tool = {t_drills})
|
2019-02-05 14:43:12 +00:00
|
|
|
M0
|
2019-02-05 17:40:46 +00:00
|
|
|
F{feedrate_probe}
|
2019-02-05 14:43:12 +00:00
|
|
|
G31 Z{z_pdepth}
|
|
|
|
G92 Z0
|
2019-02-10 21:36:59 +00:00
|
|
|
G00 Z{z_in_between}
|
2019-02-05 17:40:46 +00:00
|
|
|
F{feedrate_probe_slow}
|
2019-02-05 14:43:12 +00:00
|
|
|
G31 Z{z_pdepth}
|
|
|
|
G92 Z0
|
2019-02-10 21:36:59 +00:00
|
|
|
G00 Z{z_move}
|
2019-02-05 14:43:12 +00:00
|
|
|
(MSG, Remove any clips or other devices used for probing. CNC work is resuming ...)
|
2019-02-02 22:11:17 +00:00
|
|
|
M0
|
2019-02-28 16:02:29 +00:00
|
|
|
""".format(x_toolchange=self.coordinate_format % (p.coords_decimals, x_toolchange),
|
|
|
|
y_toolchange=self.coordinate_format % (p.coords_decimals, y_toolchange),
|
|
|
|
z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
|
2019-02-05 14:43:12 +00:00
|
|
|
z_move=self.coordinate_format % (p.coords_decimals, p.z_move),
|
2019-02-10 21:36:59 +00:00
|
|
|
z_in_between=self.coordinate_format % (p.coords_decimals, p.z_move / 2),
|
2019-02-05 17:40:46 +00:00
|
|
|
feedrate_probe=str(self.feedrate_format %(p.fr_decimals, p.feedrate_probe)),
|
|
|
|
feedrate_probe_slow=str(self.feedrate_format % (p.fr_decimals, (p.feedrate_probe / 2))),
|
2019-02-05 14:43:12 +00:00
|
|
|
z_pdepth=self.coordinate_format % (p.coords_decimals, p.z_pdepth),
|
|
|
|
tool=int(p.tool),
|
|
|
|
t_drills=no_drills,
|
|
|
|
toolC=toolC_formatted)
|
2019-02-02 22:11:17 +00:00
|
|
|
else:
|
2019-02-04 14:29:12 +00:00
|
|
|
gcode = """
|
2019-02-02 22:11:17 +00:00
|
|
|
M5
|
2019-02-10 11:42:22 +00:00
|
|
|
T{tool}
|
2019-02-05 17:40:46 +00:00
|
|
|
M6
|
2019-02-28 16:02:29 +00:00
|
|
|
G00 Z{z_toolchange}
|
2019-02-10 21:36:59 +00:00
|
|
|
(MSG, Change to Tool Dia = {toolC} ||| CONNECT THE PROBE ||| Drills for this tool = {t_drills})
|
2019-02-05 14:43:12 +00:00
|
|
|
M0
|
2019-02-05 17:40:46 +00:00
|
|
|
F{feedrate_probe}
|
2019-02-05 14:43:12 +00:00
|
|
|
G31 Z{z_pdepth}
|
|
|
|
G92 Z0
|
2019-02-10 21:36:59 +00:00
|
|
|
G00 Z{z_in_between}
|
2019-02-05 17:40:46 +00:00
|
|
|
F{feedrate_probe_slow}
|
2019-02-05 14:43:12 +00:00
|
|
|
G31 Z{z_pdepth}
|
|
|
|
G92 Z0
|
2019-02-10 21:36:59 +00:00
|
|
|
G00 Z{z_move}
|
2019-02-05 14:43:12 +00:00
|
|
|
(MSG, Remove any clips or other devices used for probing. CNC work is resuming ...)
|
|
|
|
M0
|
2019-02-28 16:02:29 +00:00
|
|
|
""".format(z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
|
2019-02-05 14:43:12 +00:00
|
|
|
z_move=self.coordinate_format % (p.coords_decimals, p.z_move),
|
2019-02-10 21:36:59 +00:00
|
|
|
z_in_between=self.coordinate_format % (p.coords_decimals, p.z_move / 2),
|
2019-02-05 17:40:46 +00:00
|
|
|
feedrate_probe=str(self.feedrate_format %(p.fr_decimals, p.feedrate_probe)),
|
|
|
|
feedrate_probe_slow=str(self.feedrate_format % (p.fr_decimals, (p.feedrate_probe / 2))),
|
2019-02-05 14:43:12 +00:00
|
|
|
z_pdepth=self.coordinate_format % (p.coords_decimals, p.z_pdepth),
|
|
|
|
tool=int(p.tool),
|
|
|
|
t_drills=no_drills,
|
|
|
|
toolC=toolC_formatted)
|
|
|
|
|
|
|
|
# if f_plunge is True:
|
|
|
|
# gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move)
|
2019-02-02 22:11:17 +00:00
|
|
|
return gcode
|
|
|
|
|
|
|
|
else:
|
|
|
|
if toolchangexy is not None:
|
2019-02-04 14:29:12 +00:00
|
|
|
gcode = """
|
2019-02-02 22:11:17 +00:00
|
|
|
M5
|
2019-02-10 11:42:22 +00:00
|
|
|
T{tool}
|
2019-02-05 17:40:46 +00:00
|
|
|
M6
|
2019-02-28 16:02:29 +00:00
|
|
|
G00 Z{z_toolchange}
|
|
|
|
G00 X{x_toolchange} Y{y_toolchange}
|
2019-02-10 21:36:59 +00:00
|
|
|
(MSG, Change to Tool Dia = {toolC} ||| CONNECT THE PROBE)
|
2019-02-05 14:43:12 +00:00
|
|
|
M0
|
2019-02-05 17:40:46 +00:00
|
|
|
F{feedrate_probe}
|
2019-02-05 14:43:12 +00:00
|
|
|
G31 Z{z_pdepth}
|
|
|
|
G92 Z0
|
2019-02-10 21:36:59 +00:00
|
|
|
G00 Z{z_in_between}
|
2019-02-05 17:40:46 +00:00
|
|
|
F{feedrate_probe_slow}
|
2019-02-05 14:43:12 +00:00
|
|
|
G31 Z{z_pdepth}
|
|
|
|
G92 Z0
|
2019-02-10 21:36:59 +00:00
|
|
|
G00 Z{z_move}
|
2019-02-05 14:43:12 +00:00
|
|
|
(MSG, Remove any clips or other devices used for probing. CNC work is resuming ...)
|
|
|
|
M0
|
2019-02-28 16:02:29 +00:00
|
|
|
""".format(x_toolchange=self.coordinate_format % (p.coords_decimals, x_toolchange),
|
|
|
|
y_toolchange=self.coordinate_format % (p.coords_decimals, y_toolchange),
|
|
|
|
z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
|
2019-02-05 14:43:12 +00:00
|
|
|
z_move=self.coordinate_format % (p.coords_decimals, p.z_move),
|
2019-02-10 21:36:59 +00:00
|
|
|
z_in_between=self.coordinate_format % (p.coords_decimals, p.z_move / 2),
|
2019-02-05 17:40:46 +00:00
|
|
|
feedrate_probe=str(self.feedrate_format %(p.fr_decimals, p.feedrate_probe)),
|
|
|
|
feedrate_probe_slow=str(self.feedrate_format % (p.fr_decimals, (p.feedrate_probe / 2))),
|
2019-02-05 14:43:12 +00:00
|
|
|
z_pdepth=self.coordinate_format % (p.coords_decimals, p.z_pdepth),
|
|
|
|
tool=int(p.tool),
|
|
|
|
toolC=toolC_formatted)
|
2019-02-02 22:11:17 +00:00
|
|
|
else:
|
2019-02-04 14:29:12 +00:00
|
|
|
gcode = """
|
2019-02-02 22:11:17 +00:00
|
|
|
M5
|
2019-02-10 11:42:22 +00:00
|
|
|
T{tool}
|
2019-02-05 17:40:46 +00:00
|
|
|
M6
|
2019-02-28 16:02:29 +00:00
|
|
|
G00 Z{z_toolchange}
|
2019-02-10 21:36:59 +00:00
|
|
|
(MSG, Change to Tool Dia = {toolC} ||| CONNECT THE PROBE)
|
2019-02-05 14:43:12 +00:00
|
|
|
M0
|
2019-02-05 17:40:46 +00:00
|
|
|
F{feedrate_probe}
|
2019-02-05 14:43:12 +00:00
|
|
|
G31 Z{z_pdepth}
|
|
|
|
G92 Z0
|
2019-02-10 21:36:59 +00:00
|
|
|
G00 Z{z_in_between}
|
2019-02-05 17:40:46 +00:00
|
|
|
F{feedrate_probe_slow}
|
2019-02-05 14:43:12 +00:00
|
|
|
G31 Z{z_pdepth}
|
|
|
|
G92 Z0
|
2019-02-10 21:36:59 +00:00
|
|
|
G00 Z{z_move}
|
2019-02-05 14:43:12 +00:00
|
|
|
(MSG, Remove any clips or other devices used for probing. CNC work is resuming ...)
|
|
|
|
M0
|
2019-02-28 16:02:29 +00:00
|
|
|
""".format(z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
|
2019-02-05 14:43:12 +00:00
|
|
|
z_move=self.coordinate_format % (p.coords_decimals, p.z_move),
|
2019-02-10 21:36:59 +00:00
|
|
|
z_in_between=self.coordinate_format % (p.coords_decimals, p.z_move / 2),
|
2019-02-05 17:40:46 +00:00
|
|
|
feedrate_probe=str(self.feedrate_format %(p.fr_decimals, p.feedrate_probe)),
|
|
|
|
feedrate_probe_slow=str(self.feedrate_format % (p.fr_decimals, (p.feedrate_probe / 2))),
|
2019-02-05 14:43:12 +00:00
|
|
|
z_pdepth=self.coordinate_format % (p.coords_decimals, p.z_pdepth),
|
|
|
|
tool=int(p.tool),
|
|
|
|
toolC=toolC_formatted)
|
|
|
|
|
|
|
|
# if f_plunge is True:
|
|
|
|
# gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move)
|
2019-02-02 22:11:17 +00:00
|
|
|
return gcode
|
|
|
|
|
|
|
|
def up_to_zero_code(self, p):
|
|
|
|
return 'G01 Z0'
|
|
|
|
|
|
|
|
def position_code(self, p):
|
|
|
|
return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
|
|
|
|
(p.coords_decimals, p.x, p.coords_decimals, p.y)
|
|
|
|
|
|
|
|
def rapid_code(self, p):
|
|
|
|
return ('G00 ' + self.position_code(p)).format(**p)
|
|
|
|
|
|
|
|
def linear_code(self, p):
|
|
|
|
return ('G01 ' + self.position_code(p)).format(**p)
|
|
|
|
|
|
|
|
def end_code(self, p):
|
2019-02-28 16:02:29 +00:00
|
|
|
coords_xy = p['xy_toolchange']
|
|
|
|
gcode = ('G00 Z' + self.feedrate_format %(p.fr_decimals, p.z_end) + "\n")
|
2019-02-02 22:11:17 +00:00
|
|
|
|
|
|
|
if coords_xy is not None:
|
|
|
|
gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
|
|
|
|
return gcode
|
|
|
|
|
|
|
|
def feedrate_code(self, p):
|
|
|
|
return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
|
|
|
|
|
2019-02-28 16:02:29 +00:00
|
|
|
def z_feedrate_code(self, p):
|
|
|
|
return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.z_feedrate))
|
2019-02-02 22:11:17 +00:00
|
|
|
|
|
|
|
def spindle_code(self, p):
|
|
|
|
if p.spindlespeed:
|
|
|
|
return 'M03 S' + str(p.spindlespeed)
|
|
|
|
else:
|
|
|
|
return 'M03'
|
|
|
|
|
|
|
|
def dwell_code(self, p):
|
|
|
|
if p.dwelltime:
|
|
|
|
return 'G4 P' + str(p.dwelltime)
|
|
|
|
|
|
|
|
def spindle_stop_code(self,p):
|
|
|
|
return 'M05'
|