2019-05-30 18:05:12 +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-05-30 18:05:12 +00:00
|
|
|
# ########################################################## ##
|
2019-03-10 13:22:16 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
from FlatCAMPostProc import *
|
|
|
|
|
|
|
|
# This post processor is configured to output code that
|
|
|
|
# is compatible with almost any version of Grbl.
|
|
|
|
|
|
|
|
|
|
|
|
class grbl_laser(FlatCAMPostProc):
|
|
|
|
|
|
|
|
coordinate_format = "%.*f"
|
|
|
|
feedrate_format = '%.*f'
|
|
|
|
|
|
|
|
def start_code(self, p):
|
|
|
|
units = ' ' + str(p['units']).lower()
|
|
|
|
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
|
|
|
gcode += '(Feedrate: ' + str(p['feedrate']) + units + '/min' + ')\n'
|
|
|
|
gcode += '(Feedrate rapids ' + str(p['feedrate_rapid']) + units + '/min' + ')\n' + '\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:
|
|
|
|
gcode += '(Postprocessor Geometry: ' + str(p['pp_geometry_name']) + ')\n'
|
2019-01-31 22:23:20 +00:00
|
|
|
gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\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-31 22:23:20 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
gcode += 'G90\n'
|
|
|
|
gcode += 'G94\n'
|
|
|
|
gcode += 'G17\n'
|
|
|
|
|
|
|
|
return gcode
|
|
|
|
|
|
|
|
def startz_code(self, p):
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def lift_code(self, p):
|
2019-03-04 19:19:55 +00:00
|
|
|
return 'M05 S0'
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def down_code(self, p):
|
2019-01-27 12:01:59 +00:00
|
|
|
if p.spindlespeed:
|
|
|
|
return 'M03 S%d' % p.spindlespeed
|
|
|
|
else:
|
|
|
|
return 'M03'
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def toolchange_code(self, p):
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def up_to_zero_code(self, p):
|
|
|
|
return 'M05'
|
|
|
|
|
|
|
|
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 22:26:58 +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):
|
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-01-30 21:17:27 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
|
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-01-24 17:22:02 +00:00
|
|
|
|
|
|
|
def spindle_code(self, p):
|
2019-05-16 00:13:22 +00:00
|
|
|
sdir = {'CW': 'M03', 'CCW': 'M04'}[p.spindledir]
|
|
|
|
if p.spindlespeed:
|
|
|
|
return '%s S%s' % (sdir, str(p.spindlespeed))
|
|
|
|
else:
|
|
|
|
return sdir
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def dwell_code(self, p):
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def spindle_stop_code(self,p):
|
|
|
|
return 'M05'
|