Z_laser.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 Z_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'
  19. gcode += '(On toolchange event the laser will move to a defined Z height to change the laser dot size.)\n\n'
  20. xmin = '%.*f' % (p.coords_decimals, p['options']['xmin'])
  21. xmax = '%.*f' % (p.coords_decimals, p['options']['xmax'])
  22. ymin = '%.*f' % (p.coords_decimals, p['options']['ymin'])
  23. ymax = '%.*f' % (p.coords_decimals, p['options']['ymax'])
  24. gcode += '(Feedrate: ' + str(p['feedrate']) + units + '/min' + ')\n'
  25. gcode += '(Feedrate rapids: ' + str(p['feedrate_rapid']) + units + '/min' + ')\n' + '\n'
  26. gcode += '(Z Focus: ' + str(p['z_move']) + units + ')\n'
  27. gcode += '(Steps per circle: ' + str(p['steps_per_circle']) + ')\n'
  28. if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
  29. gcode += '(Preprocessor Excellon: ' + str(p['pp_excellon_name']) + ')\n'
  30. else:
  31. gcode += '(Preprocessor Geometry: ' + str(p['pp_geometry_name']) + ')\n' + '\n'
  32. gcode += '(X range: ' + '{: >9s}'.format(xmin) + ' ... ' + '{: >9s}'.format(xmax) + ' ' + units + ')\n'
  33. gcode += '(Y range: ' + '{: >9s}'.format(ymin) + ' ... ' + '{: >9s}'.format(ymax) + ' ' + units + ')\n\n'
  34. gcode += '(Laser Power (Spindle Speed): ' + str(p['spindlespeed']) + ')\n\n'
  35. gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
  36. gcode += 'G90\n'
  37. gcode += 'G17\n'
  38. gcode += 'G94'
  39. return gcode
  40. def startz_code(self, p):
  41. return ''
  42. def lift_code(self, p):
  43. return 'M5'
  44. def down_code(self, p):
  45. sdir = {'CW': 'M03', 'CCW': 'M04'}[p.spindledir]
  46. if p.spindlespeed:
  47. return '%s S%s' % (sdir, str(p.spindlespeed))
  48. else:
  49. return sdir
  50. def toolchange_code(self, p):
  51. return 'G00 Z' + self.coordinate_format % (p.coords_decimals, p.z_move)
  52. def up_to_zero_code(self, p):
  53. return 'M5'
  54. def position_code(self, p):
  55. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  56. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  57. def rapid_code(self, p):
  58. return ('G00 ' + self.position_code(p)).format(**p)
  59. def linear_code(self, p):
  60. return ('G01 ' + self.position_code(p)).format(**p) + \
  61. ' F' + str(self.feedrate_format % (p.fr_decimals, p.feedrate))
  62. def end_code(self, p):
  63. coords_xy = p['xy_end']
  64. gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + "\n")
  65. if coords_xy and coords_xy != '':
  66. gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
  67. return gcode
  68. def feedrate_code(self, p):
  69. return 'G01 F' + str(self.feedrate_format % (p.fr_decimals, p.feedrate))
  70. def z_feedrate_code(self, p):
  71. return 'G01 F' + str(self.feedrate_format % (p.fr_decimals, p.z_feedrate))
  72. def spindle_code(self, p):
  73. sdir = {'CW': 'M03', 'CCW': 'M04'}[p.spindledir]
  74. if p.spindlespeed:
  75. return '%s S%s' % (sdir, str(p.spindlespeed))
  76. else:
  77. return sdir
  78. def dwell_code(self, p):
  79. return ''
  80. def spindle_stop_code(self, p):
  81. return 'M5'