2019-12-16 17:24:50 +00:00
|
|
|
# ##########################################################
|
2019-03-10 13:22:16 +00:00
|
|
|
# FlatCAM: 2D Post-processing for Manufacturing #
|
|
|
|
# http://flatcam.org #
|
|
|
|
# File Author: Matthieu Berthomé #
|
|
|
|
# Date: 5/26/2017 #
|
|
|
|
# MIT Licence #
|
2019-12-16 17:24:50 +00:00
|
|
|
# ##########################################################
|
2019-03-10 13:22:16 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
from FlatCAMPostProc import *
|
|
|
|
|
|
|
|
|
|
|
|
class grbl_11(FlatCAMPostProc):
|
|
|
|
|
2019-12-15 22:12:04 +00:00
|
|
|
include_header = True
|
2019-01-03 19:25:08 +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']
|
2020-02-08 18:38:51 +00:00
|
|
|
gcode = '(This preprocessor is used with a motion controller loaded with GRBL firmware.)\n'
|
|
|
|
gcode += '(It is configured to be compatible with almost any version of GRBL firmware.)\n\n'
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-02-01 14:19:16 +00:00
|
|
|
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'])
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
if str(p['options']['type']) == 'Geometry':
|
2020-02-17 14:35:09 +00:00
|
|
|
gcode += '(TOOL DIAMETER: ' + str(p['options']['tool_dia']) + units + ')\n'
|
|
|
|
gcode += '(Feedrate_XY: ' + str(p['feedrate']) + units + '/min' + ')\n'
|
2019-02-28 16:02:29 +00:00
|
|
|
gcode += '(Feedrate_Z: ' + str(p['z_feedrate']) + units + '/min' + ')\n'
|
2020-02-17 14:35:09 +00:00
|
|
|
gcode += '(Feedrate rapids ' + str(p['feedrate_rapid']) + units + '/min' + ')\n' + '\n'
|
|
|
|
gcode += '(Z_Cut: ' + str(p['z_cut']) + units + ')\n'
|
|
|
|
if p['multidepth'] is True:
|
|
|
|
gcode += '(DepthPerCut: ' + str(p['z_depthpercut']) + units + ' <=>' + \
|
|
|
|
str(math.ceil(abs(p['z_cut']) / p['z_depthpercut'])) + ' passes' + ')\n'
|
|
|
|
gcode += '(Z_Move: ' + str(p['z_move']) + units + ')\n'
|
|
|
|
|
|
|
|
elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True:
|
|
|
|
gcode += '\n(TOOLS DIAMETER: )\n'
|
|
|
|
for tool, val in p['exc_tools'].items():
|
|
|
|
gcode += '(Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["C"]) + ')\n'
|
|
|
|
|
|
|
|
gcode += '\n(FEEDRATE Z: )\n'
|
|
|
|
for tool, val in p['exc_tools'].items():
|
|
|
|
gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate: %s' % str(val['data']["feedrate_z"]) + ')\n'
|
|
|
|
|
|
|
|
gcode += '\n(FEEDRATE RAPIDS: )\n'
|
|
|
|
for tool, val in p['exc_tools'].items():
|
|
|
|
gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \
|
|
|
|
str(val['data']["feedrate_rapid"]) + ')\n'
|
|
|
|
|
|
|
|
gcode += '\n(Z_CUT: )\n'
|
|
|
|
for tool, val in p['exc_tools'].items():
|
|
|
|
gcode += '(Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["cutz"]) + ')\n'
|
|
|
|
|
|
|
|
gcode += '\n(Tools Offset: )\n'
|
|
|
|
for tool, val in p['exc_cnc_tools'].items():
|
|
|
|
gcode += '(Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % str(val['offset_z']) + ')\n'
|
|
|
|
|
|
|
|
if p['multidepth'] is True:
|
|
|
|
gcode += '\n(DEPTH_PER_CUT: )\n'
|
|
|
|
for tool, val in p['exc_tools'].items():
|
|
|
|
gcode += '(Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \
|
|
|
|
str(val['data']["depthperpass"]) + ')\n'
|
|
|
|
|
|
|
|
gcode += '\n(Z_MOVE: )\n'
|
|
|
|
for tool, val in p['exc_tools'].items():
|
|
|
|
gcode += '(Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["travelz"]) + ')\n'
|
|
|
|
gcode += '\n'
|
|
|
|
|
|
|
|
if p['toolchange'] is True:
|
|
|
|
gcode += '(Z Toolchange: ' + str(p['z_toolchange']) + units + ')\n'
|
|
|
|
|
|
|
|
if coords_xy is not None:
|
|
|
|
gcode += '(X,Y Toolchange: ' + "%.*f, %.*f" % (p.decimals, coords_xy[0],
|
|
|
|
p.decimals, coords_xy[1]) + units + ')\n'
|
|
|
|
else:
|
|
|
|
gcode += '(X,Y Toolchange: ' + "None" + units + ')\n'
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
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-01-03 19:25:08 +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':
|
2020-02-17 14:35:09 +00:00
|
|
|
gcode += '(Preprocessor Excellon: ' + str(p['pp_excellon_name']) + ')\n' + '\n'
|
2019-01-03 19:25:08 +00:00
|
|
|
else:
|
2019-12-06 21:00:43 +00:00
|
|
|
gcode += '(Preprocessor Geometry: ' + str(p['pp_geometry_name']) + ')\n' + '\n'
|
2019-01-31 22:23:20 +00:00
|
|
|
|
2019-02-01 14:19:16 +00:00
|
|
|
gcode += '(X range: ' + '{: >9s}'.format(xmin) + ' ... ' + '{: >9s}'.format(xmax) + ' ' + units + ')\n'
|
|
|
|
gcode += '(Y range: ' + '{: >9s}'.format(ymin) + ' ... ' + '{: >9s}'.format(ymax) + ' ' + units + ')\n\n'
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2020-02-17 14:35:09 +00:00
|
|
|
gcode += '(Spindle Speed: %s RPM)\n' % str(p['spindlespeed'])
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
|
|
|
|
gcode += 'G90\n'
|
|
|
|
gcode += 'G17\n'
|
2019-12-15 22:12:04 +00:00
|
|
|
gcode += 'G94\n'
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
return gcode
|
|
|
|
|
|
|
|
def startz_code(self, p):
|
|
|
|
if p.startz is not None:
|
2019-12-16 17:24:50 +00:00
|
|
|
return 'G00 Z' + self.coordinate_format % (p.coords_decimals, p.startz)
|
2019-01-03 19:25:08 +00:00
|
|
|
else:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def lift_code(self, p):
|
2019-12-16 17:24:50 +00:00
|
|
|
return 'G00 Z' + self.coordinate_format % (p.coords_decimals, p.z_move)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def down_code(self, p):
|
2019-12-16 17:24:50 +00:00
|
|
|
return 'G01 Z' + self.coordinate_format % (p.coords_decimals, p.z_cut)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def toolchange_code(self, p):
|
2019-02-28 16:02:29 +00:00
|
|
|
z_toolchange = p.z_toolchange
|
|
|
|
toolchangexy = p.xy_toolchange
|
2019-01-31 11:58:49 +00:00
|
|
|
f_plunge = p.f_plunge
|
2019-01-30 21:17:27 +00:00
|
|
|
|
|
|
|
if toolchangexy is not None:
|
2019-02-28 16:02:29 +00:00
|
|
|
x_toolchange = toolchangexy[0]
|
|
|
|
y_toolchange = toolchangexy[1]
|
2019-12-16 17:24:50 +00:00
|
|
|
else:
|
|
|
|
x_toolchange = 0.0
|
|
|
|
y_toolchange = 0.0
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-01-30 23:45:14 +00:00
|
|
|
no_drills = 1
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
if int(p.tool) == 1 and p.startz is not None:
|
2019-02-28 16:02:29 +00:00
|
|
|
z_toolchange = p.startz
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-12-05 13:18:54 +00:00
|
|
|
toolC_formatted = '%.*f' % (p.decimals, p.toolC)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
if str(p['options']['type']) == 'Excellon':
|
2019-01-07 00:56:55 +00:00
|
|
|
for i in p['options']['Tools_in_use']:
|
|
|
|
if i[0] == p.tool:
|
|
|
|
no_drills = i[2]
|
2019-01-30 21:17:27 +00:00
|
|
|
|
|
|
|
if toolchangexy is not None:
|
2019-02-10 11:42:22 +00:00
|
|
|
gcode = """
|
|
|
|
M5
|
2019-02-28 16:02:29 +00:00
|
|
|
G00 Z{z_toolchange}
|
|
|
|
G00 X{x_toolchange} Y{y_toolchange}
|
2019-01-30 23:45:14 +00:00
|
|
|
T{tool}
|
|
|
|
M6
|
2019-01-31 00:50:03 +00:00
|
|
|
(MSG, Change to Tool Dia = {toolC} ||| Total drills for tool T{tool} = {t_drills})
|
2019-12-06 21:00:43 +00:00
|
|
|
M0
|
|
|
|
G00 Z{z_toolchange}
|
|
|
|
""".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),
|
|
|
|
tool=int(p.tool),
|
|
|
|
t_drills=no_drills,
|
|
|
|
toolC=toolC_formatted)
|
2019-01-30 23:45:14 +00:00
|
|
|
else:
|
2019-02-10 11:42:22 +00:00
|
|
|
gcode = """
|
|
|
|
M5
|
2019-02-28 16:02:29 +00:00
|
|
|
G00 Z{z_toolchange}
|
2019-01-30 23:45:14 +00:00
|
|
|
T{tool}
|
|
|
|
M6
|
2019-01-31 00:50:03 +00:00
|
|
|
(MSG, Change to Tool Dia = {toolC} ||| Total drills for tool T{tool} = {t_drills})
|
2019-12-06 21:00:43 +00:00
|
|
|
M0
|
|
|
|
G00 Z{z_toolchange}
|
|
|
|
""".format(z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
|
|
|
|
tool=int(p.tool),
|
|
|
|
t_drills=no_drills,
|
|
|
|
toolC=toolC_formatted)
|
2019-01-30 23:45:14 +00:00
|
|
|
|
2019-01-31 11:58:49 +00:00
|
|
|
if f_plunge is True:
|
|
|
|
gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move)
|
2019-01-30 21:17:27 +00:00
|
|
|
return gcode
|
2019-01-30 23:45:14 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
else:
|
2019-01-30 21:17:27 +00:00
|
|
|
if toolchangexy is not None:
|
2019-02-10 11:42:22 +00:00
|
|
|
gcode = """
|
|
|
|
M5
|
2019-02-28 16:02:29 +00:00
|
|
|
G00 Z{z_toolchange}
|
|
|
|
G00 X{x_toolchange} Y{y_toolchange}
|
2019-01-30 23:45:14 +00:00
|
|
|
T{tool}
|
2019-02-10 11:42:22 +00:00
|
|
|
M6
|
2019-01-30 23:45:14 +00:00
|
|
|
(MSG, Change to Tool Dia = {toolC})
|
2019-12-06 21:00:43 +00:00
|
|
|
M0
|
|
|
|
G00 Z{z_toolchange}
|
|
|
|
""".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),
|
|
|
|
tool=int(p.tool),
|
|
|
|
toolC=toolC_formatted)
|
2019-01-30 23:45:14 +00:00
|
|
|
else:
|
2019-02-10 11:42:22 +00:00
|
|
|
gcode = """
|
|
|
|
M5
|
2019-02-28 16:02:29 +00:00
|
|
|
G00 Z{z_toolchange}
|
2019-01-30 23:45:14 +00:00
|
|
|
T{tool}
|
2019-02-10 11:42:22 +00:00
|
|
|
M6
|
2019-01-30 23:45:14 +00:00
|
|
|
(MSG, Change to Tool Dia = {toolC})
|
2019-12-06 21:00:43 +00:00
|
|
|
M0
|
|
|
|
G00 Z{z_toolchange}
|
2019-12-16 17:24:50 +00:00
|
|
|
""".format(z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
|
2019-12-06 21:00:43 +00:00
|
|
|
tool=int(p.tool),
|
|
|
|
toolC=toolC_formatted)
|
2019-01-30 23:45:14 +00:00
|
|
|
|
2019-01-31 11:58:49 +00:00
|
|
|
if f_plunge is True:
|
|
|
|
gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move)
|
2019-01-30 21:17:27 +00:00
|
|
|
return gcode
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
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):
|
2019-01-25 18:46:30 +00:00
|
|
|
return ('G01 ' + self.position_code(p)).format(**p) + \
|
2019-12-16 17:24:50 +00:00
|
|
|
' F' + str(self.feedrate_format % (p.fr_decimals, p.feedrate))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def end_code(self, p):
|
2020-02-26 02:43:54 +00:00
|
|
|
coords_xy = p['xy_end']
|
2019-12-16 17:24:50 +00:00
|
|
|
gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + "\n")
|
2019-01-30 21:17:27 +00:00
|
|
|
|
2020-02-28 15:59:15 +00:00
|
|
|
if coords_xy and coords_xy != '':
|
2019-01-30 21:17:27 +00:00
|
|
|
gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
|
2019-01-03 19:25:08 +00:00
|
|
|
return gcode
|
|
|
|
|
|
|
|
def feedrate_code(self, p):
|
2019-12-16 17:24:50 +00:00
|
|
|
return 'G01 F' + str(self.feedrate_format % (p.fr_decimals, p.feedrate))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-02-28 16:02:29 +00:00
|
|
|
def z_feedrate_code(self, p):
|
2019-12-16 17:24:50 +00:00
|
|
|
return 'G01 F' + str(self.feedrate_format % (p.fr_decimals, p.z_feedrate))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-05-16 00:13:22 +00:00
|
|
|
def spindle_code(self, p):
|
|
|
|
sdir = {'CW': 'M03', 'CCW': 'M04'}[p.spindledir]
|
2019-01-03 19:25:08 +00:00
|
|
|
if p.spindlespeed:
|
2019-05-16 00:13:22 +00:00
|
|
|
return '%s S%s' % (sdir, str(p.spindlespeed))
|
2019-01-03 19:25:08 +00:00
|
|
|
else:
|
2019-05-16 00:13:22 +00:00
|
|
|
return sdir
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def dwell_code(self, p):
|
|
|
|
if p.dwelltime:
|
|
|
|
return 'G4 P' + str(p.dwelltime)
|
|
|
|
|
2019-12-16 17:24:50 +00:00
|
|
|
def spindle_stop_code(self, p):
|
2019-01-03 19:25:08 +00:00
|
|
|
return 'M05'
|