grbl_11.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. from FlatCAMPostProc import *
  2. class grbl_11(FlatCAMPostProc):
  3. coordinate_format = "%.*f"
  4. feedrate_format = '%.*f'
  5. def start_code(self, p):
  6. units = ' ' + str(p['units']).lower()
  7. coords_xy = p['toolchange_xy']
  8. gcode = ''
  9. if str(p['options']['type']) == 'Geometry':
  10. gcode += '(TOOL DIAMETER: ' + str(p['options']['tool_dia']) + units + ')\n' + '\n'
  11. gcode += '(Feedrate: ' + str(p['feedrate']) + units + '/min' + ')\n'
  12. if str(p['options']['type']) == 'Geometry':
  13. gcode += '(Feedrate_Z: ' + str(p['feedrate_z']) + units + '/min' + ')\n'
  14. gcode += '(Feedrate rapids ' + str(p['feedrate_rapid']) + units + '/min' + ')\n' + '\n'
  15. gcode += '(Z_Cut: ' + str(p['z_cut']) + units + ')\n'
  16. if str(p['options']['type']) == 'Geometry':
  17. if p['multidepth'] is True:
  18. gcode += '(DepthPerCut: ' + str(p['depthpercut']) + units + ' <=>' + \
  19. str(math.ceil(abs(p['z_cut']) / p['depthpercut'])) + ' passes' + ')\n'
  20. gcode += '(Z_Move: ' + str(p['z_move']) + units + ')\n'
  21. gcode += '(Z Toolchange: ' + str(p['toolchangez']) + units + ')\n'
  22. gcode += '(X,Y Toolchange: ' + "%.4f, %.4f" % (coords_xy[0], coords_xy[1]) + units + ')\n'
  23. gcode += '(Z Start: ' + str(p['startz']) + units + ')\n'
  24. gcode += '(Z End: ' + str(p['endz']) + units + ')\n'
  25. gcode += '(Steps per circle: ' + str(p['steps_per_circle']) + ')\n'
  26. if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
  27. gcode += '(Postprocessor Excellon: ' + str(p['pp_excellon_name']) + ')\n'
  28. else:
  29. gcode += '(Postprocessor Geometry: ' + str(p['pp_geometry_name']) + ')\n'
  30. gcode += '(Spindle Speed: ' + str(p['spindlespeed']) + ' RPM' + ')\n' + '\n'
  31. gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
  32. gcode += 'G90\n'
  33. gcode += 'G94\n'
  34. gcode += 'G17\n'
  35. return gcode
  36. def startz_code(self, p):
  37. if p.startz is not None:
  38. return 'G00 Z' + self.coordinate_format%(p.coords_decimals, p.startz)
  39. else:
  40. return ''
  41. def lift_code(self, p):
  42. return 'G00 Z' + self.coordinate_format%(p.coords_decimals, p.z_move)
  43. def down_code(self, p):
  44. return 'G01 Z' + self.coordinate_format%(p.coords_decimals, p.z_cut)
  45. def toolchange_code(self, p):
  46. toolchangez = p.toolchangez
  47. if int(p.tool) == 1 and p.startz is not None:
  48. toolchangez = p.startz
  49. if p.units.upper() == 'MM':
  50. toolC_formatted = format(p.toolC, '.2f')
  51. else:
  52. toolC_formatted = format(p.toolC, '.4f')
  53. if str(p['options']['type']) == 'Excellon':
  54. for i in p['options']['Tools_in_use']:
  55. if i[0] == p.tool:
  56. no_drills = i[2]
  57. return """G00 Z{toolchangez}
  58. T{tool}
  59. M5
  60. M6
  61. (MSG, Change to Tool Dia = {toolC}, Total drills for current tool = {t_drills})
  62. M0""".format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
  63. tool=int(p.tool),
  64. t_drills=no_drills,
  65. toolC=toolC_formatted)
  66. else:
  67. return """G00 Z{toolchangez}
  68. T{tool}
  69. M5
  70. M6
  71. (MSG, Change to Tool Dia = {toolC})
  72. M0""".format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
  73. tool=int(p.tool),
  74. toolC=toolC_formatted)
  75. def up_to_zero_code(self, p):
  76. return 'G01 Z0'
  77. def position_code(self, p):
  78. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  79. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  80. def rapid_code(self, p):
  81. return ('G00 ' + self.position_code(p)).format(**p)
  82. def linear_code(self, p):
  83. return ('G01 ' + self.position_code(p)).format(**p) + " " + self.feedrate_code(p)
  84. def end_code(self, p):
  85. coords_xy = p['toolchange_xy']
  86. gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, p.endz) + "\n")
  87. gcode += 'G00 X{x}Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
  88. return gcode
  89. def feedrate_code(self, p):
  90. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
  91. def feedrate_z_code(self, p):
  92. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate_z))
  93. def spindle_code(self,p):
  94. if p.spindlespeed:
  95. return 'M03 S%d' % p.spindlespeed
  96. else:
  97. return 'M03'
  98. def dwell_code(self, p):
  99. if p.dwelltime:
  100. return 'G4 P' + str(p.dwelltime)
  101. def spindle_stop_code(self,p):
  102. return 'M05'