- added a new preprocessor for Marlin that has movemements on the Z axis named Marlin_laser_Z

- cleaned up Marlin preprocessors
This commit is contained in:
Marius Stanciu
2022-01-29 13:51:41 +02:00
committed by Marius
parent 965ccca885
commit a0fb8b5413
7 changed files with 193 additions and 31 deletions

View File

@@ -65,7 +65,7 @@ class GRBL_laser_Z(PreProc):
gcode += '(X range: ' + '{: >9s}'.format(xmin) + ' ... ' + '{: >9s}'.format(xmax) + ' ' + units + ')\n'
gcode += '(Y range: ' + '{: >9s}'.format(ymin) + ' ... ' + '{: >9s}'.format(ymax) + ' ' + units + ')\n\n'
gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
gcode += 'G20\n' if p.units.upper() == 'IN' else 'G21\n'
gcode += 'G90\n'
gcode += 'G17\n'
gcode += 'G94'

View File

@@ -89,7 +89,7 @@ class Marlin(PreProc):
p.decimals, end_coords_xy[1]) + units + '\n'
else:
gcode += ';X,Y End: ' + "None" + units + '\n'
gcode += '(Steps per circle: ' + str(p['steps_per_circle']) + ')\n'
gcode += ';Steps per circle: ' + str(p['steps_per_circle']) + '\n'
gcode += ';Steps per circle: ' + str(p['steps_per_circle']) + '\n'
if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
@@ -102,8 +102,7 @@ class Marlin(PreProc):
gcode += ';Spindle Speed: %s RPM)\n' % str(p['spindlespeed'])
gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
gcode += 'G90'
gcode += 'G20\n' if p.units.upper() == 'IN' else 'G21\n'
return gcode

View File

@@ -18,10 +18,12 @@ class Marlin_laser_FAN_pin(PreProc):
def start_code(self, p):
units = ' ' + str(p['units']).lower()
coords_xy = p['xy_toolchange']
end_coords_xy = p['xy_end']
gcode = ';This preprocessor is used with a motion controller loaded with MARLIN firmware.\n'
gcode += ';It is for the case when it is used together with a LASER connected on one of the FAN pins.\n\n'
gcode += ';It is for the case when it is used together with a LASER connected on one of the FAN pins.\n'\
';This preprocessor makes no moves on the Z axis it will only move horizontally.\n' \
';It assumes a manually focused laser.\n' \
';The laser is started with M3 command and stopped with the M5 command.\n\n'
xmin = '%.*f' % (p.coords_decimals, p['options']['xmin'])
xmax = '%.*f' % (p.coords_decimals, p['options']['xmax'])
@@ -40,27 +42,24 @@ class Marlin_laser_FAN_pin(PreProc):
else:
gcode += ';Preprocessor Geometry: ' + str(p['pp_geometry_name']) + '\n'
if end_coords_xy is not None:
gcode += '(X,Y End: ' + "%.*f, %.*f" % (p.decimals, end_coords_xy[0],
p.decimals, end_coords_xy[1]) + units + ')\n'
gcode += ';X,Y End: ' + "%.*f, %.*f" % (p.decimals, end_coords_xy[0],
p.decimals, end_coords_xy[1]) + units + '\n'
else:
gcode += '(X,Y End: ' + "None" + units + ')\n'
gcode += '(Steps per circle: ' + str(p['steps_per_circle']) + ')\n'
gcode += ';X,Y End: ' + "None" + units + '\n'
gcode += ';Steps per circle: ' + str(p['steps_per_circle']) + '\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 += ';Laser Power (Spindle Speed): ' + str(p['spindlespeed']) + '\n' + '\n'
gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
gcode += 'G20\n' if p.units.upper() == 'IN' else 'G21\n'
gcode += 'G90'
return gcode
def startz_code(self, p):
if p.startz is not None:
return 'G0 Z' + self.coordinate_format % (p.coords_decimals, p.z_move)
else:
return ''
return ''
def lift_code(self, p):
gcode = 'M400\n'
@@ -105,11 +104,10 @@ class Marlin_laser_FAN_pin(PreProc):
def end_code(self, p):
coords_xy = p['xy_end']
gcode = ('G0 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + " " + self.feedrate_rapid_code(p) + "\n")
gcode = ''
if coords_xy and coords_xy != '':
gcode += 'G0 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + " " + self.feedrate_rapid_code(p) + "\n"
return gcode
def feedrate_code(self, p):

View File

@@ -18,10 +18,12 @@ class Marlin_laser_Spindle_pin(PreProc):
def start_code(self, p):
units = ' ' + str(p['units']).lower()
coords_xy = p['xy_toolchange']
end_coords_xy = p['xy_end']
gcode = ';This preprocessor is used with a motion controller loaded with MARLIN firmware.\n'
gcode += ';It is for the case when it is used together with a LASER connected on the SPINDLE connector.\n\n'
gcode += ';It is for the case when it is used together with a LASER connected on the SPINDLE connector.\n'\
';This preprocessor makes no moves on the Z axis it will only move horizontally.\n' \
';It assumes a manually focused laser.\n' \
';The laser is started with M3 command and stopped with the M5 command.\n\n'
xmin = '%.*f' % (p.coords_decimals, p['options']['xmin'])
xmax = '%.*f' % (p.coords_decimals, p['options']['xmax'])
@@ -40,26 +42,23 @@ class Marlin_laser_Spindle_pin(PreProc):
else:
gcode += ';Preprocessor Geometry: ' + str(p['pp_geometry_name']) + '\n'
if end_coords_xy is not None:
gcode += '(X,Y End: ' + "%.*f, %.*f" % (p.decimals, end_coords_xy[0],
p.decimals, end_coords_xy[1]) + units + ')\n'
gcode += ';X,Y End: ' + "%.*f, %.*f" % (p.decimals, end_coords_xy[0],
p.decimals, end_coords_xy[1]) + units + '\n'
else:
gcode += '(X,Y End: ' + "None" + units + ')\n\n'
gcode += ';X,Y End: ' + "None" + units + '\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 += ';Laser Power (Spindle Speed): ' + str(p['spindlespeed']) + '\n' + '\n'
gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
gcode += 'G20\n' if p.units.upper() == 'IN' else 'G21\n'
gcode += 'G90'
return gcode
def startz_code(self, p):
if p.startz is not None:
return 'G0 Z' + self.coordinate_format % (p.coords_decimals, p.z_move)
else:
return ''
return ''
def lift_code(self, p):
gcode = 'M400\n'
@@ -104,11 +103,10 @@ class Marlin_laser_Spindle_pin(PreProc):
return ('G1 ' + self.position_code(p)).format(**p) + " " + self.inline_feedrate_code(p)
def end_code(self, p):
gcode = ''
coords_xy = p['xy_end']
gcode = ('G0 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + " " + self.feedrate_rapid_code(p) + "\n")
if coords_xy and coords_xy != '':
gcode += 'G0 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + " " + self.feedrate_rapid_code(p) + "\n"
gcode = 'G0 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + " " + self.feedrate_rapid_code(p) + "\n"
return gcode

View File

@@ -0,0 +1,165 @@
# ##########################################################
# FlatCAM: 2D Post-processing for Manufacturing #
# Website: http://flatcam.org #
# File Author: Marius Adrian Stanciu (c) #
# Date: 8-Feb-2020 #
# License: MIT Licence #
# ##########################################################
from appPreProcessor import *
class Marlin_laser_z(PreProc):
include_header = True
coordinate_format = "%.*f"
feedrate_format = '%.*f'
feedrate_rapid_format = feedrate_format
def start_code(self, p):
units = ' ' + str(p['units']).lower()
coords_xy = p['xy_toolchange']
end_coords_xy = p['xy_end']
gcode = ';This preprocessor is used with a motion controller loaded with MARLIN firmware.\n'
gcode += ';It is for the case when it is used together with a LASER connected on the SPINDLE connector.\n' \
';On toolchange event the laser will move to a defined Z height to change the laser dot size.\n\n'
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 p['use_ui'] is True and p['multigeo']:
gcode += '\n;TOOLS DIAMETER: \n'
for tool, val in p['tools'].items():
gcode += ';Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + '\n'
gcode += '\n;FEEDRATE: \n'
for tool, val in p['tools'].items():
gcode += ';Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \
str(val['data']["tools_mill_feedrate"]) + '\n'
gcode += '\n;FEEDRATE RAPIDS: \n'
for tool, val in p['tools'].items():
gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate rapids: %s' % \
str(val['data']["tools_mill_feedrate_rapid"]) + '\n'
gcode += '\n;Z FOCUS: \n'
for tool, val in p['tools'].items():
gcode += ';Tool: %s -> ' % str(tool) + 'Z: %s' % \
str(val['data']["tools_mill_travelz"]) + '\n'
gcode += '\n;LASER POWER: \n'
for tool, val in p['tools'].items():
gcode += ';Tool: %s -> ' % str(tool) + 'Power: %s' % \
str(val['data']["tools_mill_spindlespeed"]) + '\n'
else:
gcode += ';Feedrate: %s %s/min\n' % (str(p['feedrate']), units)
gcode += ';Feedrate rapids: %s %s/min\n\n' % (str(p['feedrate_rapid']), units)
gcode += ';Z Focus: %s %s\n' % (str(p['z_move']), units)
gcode += ';Laser Power: %s\n' % str(p['spindlespeed'])
gcode += '\n'
if coords_xy is not None:
gcode += ';X,Y Toolchange: ' + "%.*f, %.*f%s\n" % \
(p.decimals, coords_xy[0], p.decimals, coords_xy[1], units)
else:
gcode += ';X,Y End: None %s\n' % units
if end_coords_xy is not None:
gcode += ';X,Y End: ' + "%.*f, %.*f" % (p.decimals, end_coords_xy[0],
p.decimals, end_coords_xy[1]) + units + '\n'
else:
gcode += ';X,Y End: ' + "None" + units + '\n'
gcode += ';Z End: ' + str(p['z_end']) + 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 += ';Preprocessor Excellon: ' + str(p['pp_excellon_name']) + '\n'
else:
gcode += ';Preprocessor Geometry: ' + str(p['pp_geometry_name']) + '\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 += 'G20\n' if p.units.upper() == 'IN' else 'G21\n'
gcode += 'G90'
return gcode
def startz_code(self, p):
if p.startz is not None:
return 'G0 Z' + self.coordinate_format % (p.coords_decimals, p.z_move)
else:
return ''
def lift_code(self, p):
gcode = 'M400\n'
gcode += 'M5'
return gcode
def down_code(self, p):
if p.spindlespeed:
return '%s S%s' % ('M3', str(p.spindlespeed))
else:
return 'M3'
def toolchange_code(self, p):
return 'G0 Z' + self.coordinate_format % (p.coords_decimals, p.z_move)
def up_to_zero_code(self, p):
gcode = 'M400\n'
gcode += 'M5'
return gcode
def position_code(self, p):
# formula for skewing on x for example is:
# x_fin = x_init + y_init/slope where slope = p._bed_limit_y / p._bed_skew_x (a.k.a tangent)
if p._bed_skew_x == 0:
x_pos = p.x + p._bed_offset_x
else:
x_pos = (p.x + p._bed_offset_x) + ((p.y / p._bed_limit_y) * p._bed_skew_x)
if p._bed_skew_y == 0:
y_pos = p.y + p._bed_offset_y
else:
y_pos = (p.y + p._bed_offset_y) + ((p.x / p._bed_limit_x) * p._bed_skew_y)
return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
(p.coords_decimals, x_pos, p.coords_decimals, y_pos)
def rapid_code(self, p):
return ('G0 ' + self.position_code(p)).format(**p) + " " + self.feedrate_rapid_code(p)
def linear_code(self, p):
return ('G1 ' + self.position_code(p)).format(**p) + " " + self.inline_feedrate_code(p)
def end_code(self, p):
coords_xy = p['xy_end']
gcode = ('G0 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + " " + self.feedrate_rapid_code(p) + "\n")
if coords_xy and coords_xy != '':
gcode += 'G0 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + " " + self.feedrate_rapid_code(p) + "\n"
return gcode
def feedrate_code(self, p):
return 'G1 F' + str(self.feedrate_format % (p.fr_decimals, p.feedrate))
def z_feedrate_code(self, p):
return 'G1 F' + str(self.feedrate_format % (p.fr_decimals, p.z_feedrate))
def inline_feedrate_code(self, p):
return 'F' + self.feedrate_format % (p.fr_decimals, p.feedrate)
def feedrate_rapid_code(self, p):
return 'F' + self.feedrate_rapid_format % (p.fr_decimals, p.feedrate_rapid)
def spindle_code(self, p):
if p.spindlespeed:
return '%s S%s' % ('M3', str(p.spindlespeed))
else:
return 'M3'
def dwell_code(self, p):
return ''
def spindle_stop_code(self, p):
gcode = 'M400\n'
gcode += 'M5'
return gcode