2019-01-03 19:25:08 +00:00
|
|
|
from FlatCAMPostProc import *
|
|
|
|
|
|
|
|
|
|
|
|
class grbl_11(FlatCAMPostProc):
|
|
|
|
|
|
|
|
coordinate_format = "%.*f"
|
|
|
|
feedrate_format = '%.*f'
|
|
|
|
|
|
|
|
def start_code(self, p):
|
|
|
|
units = ' ' + str(p['units']).lower()
|
|
|
|
coords_xy = p['toolchange_xy']
|
|
|
|
gcode = ''
|
|
|
|
|
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':
|
|
|
|
gcode += '(TOOL DIAMETER: ' + str(p['options']['tool_dia']) + units + ')\n' + '\n'
|
|
|
|
|
|
|
|
gcode += '(Feedrate: ' + str(p['feedrate']) + units + '/min' + ')\n'
|
|
|
|
|
|
|
|
if str(p['options']['type']) == 'Geometry':
|
|
|
|
gcode += '(Feedrate_Z: ' + str(p['feedrate_z']) + units + '/min' + ')\n'
|
|
|
|
|
|
|
|
gcode += '(Feedrate rapids ' + str(p['feedrate_rapid']) + units + '/min' + ')\n' + '\n'
|
|
|
|
gcode += '(Z_Cut: ' + str(p['z_cut']) + units + ')\n'
|
|
|
|
|
|
|
|
if str(p['options']['type']) == 'Geometry':
|
|
|
|
if p['multidepth'] is True:
|
|
|
|
gcode += '(DepthPerCut: ' + str(p['depthpercut']) + units + ' <=>' + \
|
|
|
|
str(math.ceil(abs(p['z_cut']) / p['depthpercut'])) + ' passes' + ')\n'
|
|
|
|
|
|
|
|
gcode += '(Z_Move: ' + str(p['z_move']) + units + ')\n'
|
|
|
|
gcode += '(Z Toolchange: ' + str(p['toolchangez']) + units + ')\n'
|
2019-01-30 21:17:27 +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'
|
2019-01-03 19:25:08 +00:00
|
|
|
gcode += '(Z Start: ' + str(p['startz']) + units + ')\n'
|
|
|
|
gcode += '(Z End: ' + str(p['endz']) + units + ')\n'
|
|
|
|
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:
|
2019-01-31 22:23:20 +00:00
|
|
|
gcode += '(Postprocessor Geometry: ' + str(p['pp_geometry_name']) + ')\n' + '\n'
|
|
|
|
|
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
|
|
|
|
|
|
|
gcode += '(Spindle Speed: ' + str(p['spindlespeed']) + ' RPM' + ')\n' + '\n'
|
|
|
|
|
|
|
|
gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
|
|
|
|
gcode += 'G90\n'
|
|
|
|
gcode += 'G94\n'
|
|
|
|
gcode += 'G17\n'
|
|
|
|
|
|
|
|
return gcode
|
|
|
|
|
|
|
|
def startz_code(self, p):
|
|
|
|
if p.startz is not None:
|
|
|
|
return 'G00 Z' + self.coordinate_format%(p.coords_decimals, p.startz)
|
|
|
|
else:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
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):
|
|
|
|
toolchangez = p.toolchangez
|
2019-01-30 21:17:27 +00:00
|
|
|
toolchangexy = p.toolchange_xy
|
2019-01-31 11:58:49 +00:00
|
|
|
f_plunge = p.f_plunge
|
2019-01-30 21:17:27 +00:00
|
|
|
gcode = ''
|
|
|
|
|
|
|
|
if toolchangexy is not None:
|
|
|
|
toolchangex = toolchangexy[0]
|
|
|
|
toolchangey = toolchangexy[1]
|
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:
|
|
|
|
toolchangez = p.startz
|
|
|
|
|
|
|
|
if p.units.upper() == 'MM':
|
|
|
|
toolC_formatted = format(p.toolC, '.2f')
|
|
|
|
else:
|
|
|
|
toolC_formatted = format(p.toolC, '.4f')
|
|
|
|
|
|
|
|
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
|
|
|
|
G00 Z{toolchangez}
|
2019-01-30 23:45:14 +00:00
|
|
|
G00 X{toolchangex} Y{toolchangey}
|
|
|
|
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-01-30 23:45:14 +00:00
|
|
|
M0""".format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex),
|
|
|
|
toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
|
|
|
|
toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
|
|
|
|
tool=int(p.tool),
|
|
|
|
t_drills=no_drills,
|
|
|
|
toolC=toolC_formatted)
|
|
|
|
else:
|
2019-02-10 11:42:22 +00:00
|
|
|
gcode = """
|
|
|
|
M5
|
|
|
|
G00 Z{toolchangez}
|
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-01-30 23:45:14 +00:00
|
|
|
M0""".format(toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
|
|
|
|
tool=int(p.tool),
|
|
|
|
t_drills=no_drills,
|
|
|
|
toolC=toolC_formatted)
|
|
|
|
|
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
|
|
|
|
G00 Z{toolchangez}
|
|
|
|
G00 X{toolchangex} Y{toolchangey}
|
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})
|
|
|
|
M0""".format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex),
|
|
|
|
toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
|
|
|
|
toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
|
|
|
|
tool=int(p.tool),
|
|
|
|
toolC=toolC_formatted)
|
|
|
|
else:
|
2019-02-10 11:42:22 +00:00
|
|
|
gcode = """
|
|
|
|
M5
|
|
|
|
G00 Z{toolchangez}
|
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})
|
|
|
|
M0""".format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
|
|
|
|
tool=int(p.tool),
|
|
|
|
toolC=toolC_formatted)
|
|
|
|
|
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) + \
|
|
|
|
' F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def end_code(self, p):
|
|
|
|
coords_xy = p['toolchange_xy']
|
2019-01-30 21:17:27 +00:00
|
|
|
gcode = ('G00 Z' + self.feedrate_format %(p.fr_decimals, p.endz) + "\n")
|
|
|
|
|
|
|
|
if coords_xy is not None:
|
|
|
|
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):
|
|
|
|
return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
|
|
|
|
|
|
|
|
def feedrate_z_code(self, p):
|
|
|
|
return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate_z))
|
|
|
|
|
|
|
|
def spindle_code(self,p):
|
|
|
|
if p.spindlespeed:
|
|
|
|
return 'M03 S%d' % 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'
|