GRBL_laser.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # ##########################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # http://flatcam.org #
  4. # File Author: Matthieu Berthomé #
  5. # Date: 5/26/2017 #
  6. # MIT Licence #
  7. # ##########################################################
  8. from appPreProcessor import *
  9. # This post processor is configured to output code that
  10. # is compatible with almost any version of Grbl.
  11. class GRBL_laser(PreProc):
  12. include_header = True
  13. coordinate_format = "%.*f"
  14. feedrate_format = '%.*f'
  15. def start_code(self, p):
  16. units = ' ' + str(p['units']).lower()
  17. gcode = '(This preprocessor is used with a motion controller loaded with GRBL firmware. )\n'
  18. gcode += '(It is for the case when it is used together with a LASER connected on the SPINDLE connector.)\n\n'
  19. xmin = '%.*f' % (p.coords_decimals, p['options']['xmin'])
  20. xmax = '%.*f' % (p.coords_decimals, p['options']['xmax'])
  21. ymin = '%.*f' % (p.coords_decimals, p['options']['ymin'])
  22. ymax = '%.*f' % (p.coords_decimals, p['options']['ymax'])
  23. gcode += '(Feedrate: ' + str(p['feedrate']) + units + '/min' + ')\n'
  24. gcode += '(Feedrate rapids: ' + str(p['feedrate_rapid']) + units + '/min' + ')\n' + '\n'
  25. gcode += '(Z Focus: ' + str(p['z_move']) + units + ')\n'
  26. gcode += '(Steps per circle: ' + str(p['steps_per_circle']) + ')\n'
  27. if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
  28. gcode += '(Preprocessor Excellon: ' + str(p['pp_excellon_name']) + ')\n'
  29. else:
  30. gcode += '(Preprocessor Geometry: ' + str(p['pp_geometry_name']) + ')\n' + '\n'
  31. gcode += '(X range: ' + '{: >9s}'.format(xmin) + ' ... ' + '{: >9s}'.format(xmax) + ' ' + units + ')\n'
  32. gcode += '(Y range: ' + '{: >9s}'.format(ymin) + ' ... ' + '{: >9s}'.format(ymax) + ' ' + units + ')\n\n'
  33. gcode += '(Laser Power - Spindle Speed: ' + str(p['spindlespeed']) + ')\n\n'
  34. gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
  35. gcode += 'G90\n'
  36. gcode += 'G17\n'
  37. gcode += 'G94'
  38. return gcode
  39. def startz_code(self, p):
  40. return ''
  41. def lift_code(self, p):
  42. return 'M5'
  43. def down_code(self, p):
  44. sdir = {'CW': 'M03', 'CCW': 'M04'}[p.spindledir]
  45. if p.spindlespeed:
  46. return '%s S%s' % (sdir, str(p.spindlespeed))
  47. else:
  48. return sdir
  49. def toolchange_code(self, p):
  50. return ''
  51. def up_to_zero_code(self, p):
  52. return 'M5'
  53. def position_code(self, p):
  54. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  55. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  56. def rapid_code(self, p):
  57. return ('G00 ' + self.position_code(p)).format(**p)
  58. def linear_code(self, p):
  59. return ('G01 ' + self.position_code(p)).format(**p) + \
  60. ' F' + str(self.feedrate_format % (p.fr_decimals, p.feedrate))
  61. def end_code(self, p):
  62. coords_xy = p['xy_end']
  63. gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + "\n")
  64. if coords_xy and coords_xy != '':
  65. gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
  66. return gcode
  67. def feedrate_code(self, p):
  68. return 'G01 F' + str(self.feedrate_format % (p.fr_decimals, p.feedrate))
  69. def z_feedrate_code(self, p):
  70. return 'G01 F' + str(self.feedrate_format % (p.fr_decimals, p.z_feedrate))
  71. def spindle_code(self, p):
  72. sdir = {'CW': 'M03', 'CCW': 'M04'}[p.spindledir]
  73. if p.spindlespeed:
  74. return '%s S%s' % (sdir, str(p.spindlespeed))
  75. else:
  76. return sdir
  77. def dwell_code(self, p):
  78. return ''
  79. def spindle_stop_code(self, p):
  80. return 'M5'