grbl_laser.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 FlatCAMPostProc import *
  9. # This post processor is configured to output code that
  10. # is compatible with almost any version of Grbl.
  11. class grbl_laser(FlatCAMPostProc):
  12. coordinate_format = "%.*f"
  13. feedrate_format = '%.*f'
  14. def start_code(self, p):
  15. units = ' ' + str(p['units']).lower()
  16. gcode = ''
  17. xmin = '%.*f' % (p.coords_decimals, p['options']['xmin'])
  18. xmax = '%.*f' % (p.coords_decimals, p['options']['xmax'])
  19. ymin = '%.*f' % (p.coords_decimals, p['options']['ymin'])
  20. ymax = '%.*f' % (p.coords_decimals, p['options']['ymax'])
  21. gcode += '(Feedrate: ' + str(p['feedrate']) + units + '/min' + ')\n'
  22. gcode += '(Feedrate rapids ' + str(p['feedrate_rapid']) + units + '/min' + ')\n' + '\n'
  23. gcode += '(Steps per circle: ' + str(p['steps_per_circle']) + ')\n'
  24. if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
  25. gcode += '(Preprocessor Excellon: ' + str(p['pp_excellon_name']) + ')\n'
  26. else:
  27. gcode += '(Preprocessor Geometry: ' + str(p['pp_geometry_name']) + ')\n'
  28. gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n" + '\n'
  29. gcode += '(X range: ' + '{: >9s}'.format(xmin) + ' ... ' + '{: >9s}'.format(xmax) + ' ' + units + ')\n'
  30. gcode += '(Y range: ' + '{: >9s}'.format(ymin) + ' ... ' + '{: >9s}'.format(ymax) + ' ' + units + ')\n\n'
  31. gcode += 'G90\n'
  32. gcode += 'G94\n'
  33. gcode += 'G17\n'
  34. return gcode
  35. def startz_code(self, p):
  36. return ''
  37. def lift_code(self, p):
  38. return 'M05 S0'
  39. def down_code(self, p):
  40. if p.spindlespeed:
  41. return 'M03 S%d' % p.spindlespeed
  42. else:
  43. return 'M03'
  44. def toolchange_code(self, p):
  45. return ''
  46. def up_to_zero_code(self, p):
  47. return 'M05'
  48. def position_code(self, p):
  49. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  50. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  51. def rapid_code(self, p):
  52. return ('G00 ' + self.position_code(p)).format(**p)
  53. def linear_code(self, p):
  54. return ('G01 ' + self.position_code(p)).format(**p) + \
  55. ' F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
  56. def end_code(self, p):
  57. coords_xy = p['xy_toolchange']
  58. gcode = ('G00 Z' + self.feedrate_format %(p.fr_decimals, p.z_end) + "\n")
  59. if coords_xy is not None:
  60. gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
  61. return gcode
  62. def feedrate_code(self, p):
  63. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
  64. def z_feedrate_code(self, p):
  65. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.z_feedrate))
  66. def spindle_code(self, p):
  67. sdir = {'CW': 'M03', 'CCW': 'M04'}[p.spindledir]
  68. if p.spindlespeed:
  69. return '%s S%s' % (sdir, str(p.spindlespeed))
  70. else:
  71. return sdir
  72. def dwell_code(self, p):
  73. return ''
  74. def spindle_stop_code(self,p):
  75. return 'M05'