grbl_11.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. if coords_xy is not None:
  23. gcode += '(X,Y Toolchange: ' + "%.4f, %.4f" % (coords_xy[0], coords_xy[1]) + units + ')\n'
  24. else:
  25. gcode += '(X,Y Toolchange: ' + "None" + units + ')\n'
  26. gcode += '(Z Start: ' + str(p['startz']) + units + ')\n'
  27. gcode += '(Z End: ' + str(p['endz']) + units + ')\n'
  28. gcode += '(Steps per circle: ' + str(p['steps_per_circle']) + ')\n'
  29. if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
  30. gcode += '(Postprocessor Excellon: ' + str(p['pp_excellon_name']) + ')\n'
  31. else:
  32. gcode += '(Postprocessor Geometry: ' + str(p['pp_geometry_name']) + ')\n' + '\n'
  33. gcode += '(X min: ' + '%.*f' % (p.coords_decimals, p['options']['xmin']) + units + ')\n'
  34. gcode += '(Y min: ' + '%.*f' % (p.coords_decimals, p['options']['ymin']) + units + ')\n'
  35. gcode += '(X max: ' + '%.*f' % (p.coords_decimals, p['options']['xmax']) + units + ')\n'
  36. gcode += '(Y max: ' + '%.*f' % (p.coords_decimals, p['options']['ymax']) + units + ')\n\n'
  37. gcode += '(Spindle Speed: ' + str(p['spindlespeed']) + ' RPM' + ')\n' + '\n'
  38. gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
  39. gcode += 'G90\n'
  40. gcode += 'G94\n'
  41. gcode += 'G17\n'
  42. return gcode
  43. def startz_code(self, p):
  44. if p.startz is not None:
  45. return 'G00 Z' + self.coordinate_format%(p.coords_decimals, p.startz)
  46. else:
  47. return ''
  48. def lift_code(self, p):
  49. return 'G00 Z' + self.coordinate_format%(p.coords_decimals, p.z_move)
  50. def down_code(self, p):
  51. return 'G01 Z' + self.coordinate_format%(p.coords_decimals, p.z_cut)
  52. def toolchange_code(self, p):
  53. toolchangez = p.toolchangez
  54. toolchangexy = p.toolchange_xy
  55. f_plunge = p.f_plunge
  56. gcode = ''
  57. if toolchangexy is not None:
  58. toolchangex = toolchangexy[0]
  59. toolchangey = toolchangexy[1]
  60. no_drills = 1
  61. if int(p.tool) == 1 and p.startz is not None:
  62. toolchangez = p.startz
  63. if p.units.upper() == 'MM':
  64. toolC_formatted = format(p.toolC, '.2f')
  65. else:
  66. toolC_formatted = format(p.toolC, '.4f')
  67. if str(p['options']['type']) == 'Excellon':
  68. for i in p['options']['Tools_in_use']:
  69. if i[0] == p.tool:
  70. no_drills = i[2]
  71. if toolchangexy is not None:
  72. gcode = """G00 Z{toolchangez}
  73. G00 X{toolchangex} Y{toolchangey}
  74. T{tool}
  75. M5
  76. M6
  77. (MSG, Change to Tool Dia = {toolC} ||| Total drills for tool T{tool} = {t_drills})
  78. M0""".format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex),
  79. toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
  80. toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
  81. tool=int(p.tool),
  82. t_drills=no_drills,
  83. toolC=toolC_formatted)
  84. else:
  85. gcode = """G00 Z{toolchangez}
  86. T{tool}
  87. M5
  88. M6
  89. (MSG, Change to Tool Dia = {toolC} ||| Total drills for tool T{tool} = {t_drills})
  90. M0""".format(toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
  91. tool=int(p.tool),
  92. t_drills=no_drills,
  93. toolC=toolC_formatted)
  94. if f_plunge is True:
  95. gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move)
  96. return gcode
  97. else:
  98. if toolchangexy is not None:
  99. gcode = """G00 Z{toolchangez}
  100. G00 X{toolchangex} Y{toolchangey}
  101. T{tool}
  102. M5
  103. M6
  104. (MSG, Change to Tool Dia = {toolC})
  105. M0""".format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex),
  106. toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
  107. toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
  108. tool=int(p.tool),
  109. toolC=toolC_formatted)
  110. else:
  111. gcode = """G00 Z{toolchangez}
  112. T{tool}
  113. M5
  114. M6
  115. (MSG, Change to Tool Dia = {toolC})
  116. M0""".format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
  117. tool=int(p.tool),
  118. toolC=toolC_formatted)
  119. if f_plunge is True:
  120. gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move)
  121. return gcode
  122. def up_to_zero_code(self, p):
  123. return 'G01 Z0'
  124. def position_code(self, p):
  125. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  126. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  127. def rapid_code(self, p):
  128. return ('G00 ' + self.position_code(p)).format(**p)
  129. def linear_code(self, p):
  130. return ('G01 ' + self.position_code(p)).format(**p) + \
  131. ' F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
  132. def end_code(self, p):
  133. coords_xy = p['toolchange_xy']
  134. gcode = ('G00 Z' + self.feedrate_format %(p.fr_decimals, p.endz) + "\n")
  135. if coords_xy is not None:
  136. gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
  137. return gcode
  138. def feedrate_code(self, p):
  139. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
  140. def feedrate_z_code(self, p):
  141. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate_z))
  142. def spindle_code(self,p):
  143. if p.spindlespeed:
  144. return 'M03 S%d' % p.spindlespeed
  145. else:
  146. return 'M03'
  147. def dwell_code(self, p):
  148. if p.dwelltime:
  149. return 'G4 P' + str(p.dwelltime)
  150. def spindle_stop_code(self,p):
  151. return 'M05'