grbl_11.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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'
  33. gcode += '(Spindle Speed: ' + str(p['spindlespeed']) + ' RPM' + ')\n' + '\n'
  34. gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
  35. gcode += 'G90\n'
  36. gcode += 'G94\n'
  37. gcode += 'G17\n'
  38. return gcode
  39. def startz_code(self, p):
  40. if p.startz is not None:
  41. return 'G00 Z' + self.coordinate_format%(p.coords_decimals, p.startz)
  42. else:
  43. return ''
  44. def lift_code(self, p):
  45. return 'G00 Z' + self.coordinate_format%(p.coords_decimals, p.z_move)
  46. def down_code(self, p):
  47. return 'G01 Z' + self.coordinate_format%(p.coords_decimals, p.z_cut)
  48. def toolchange_code(self, p):
  49. toolchangez = p.toolchangez
  50. toolchangexy = p.toolchange_xy
  51. gcode = ''
  52. if toolchangexy is not None:
  53. toolchangex = toolchangexy[0]
  54. toolchangey = toolchangexy[1]
  55. if int(p.tool) == 1 and p.startz is not None:
  56. toolchangez = p.startz
  57. if p.units.upper() == 'MM':
  58. toolC_formatted = format(p.toolC, '.2f')
  59. else:
  60. toolC_formatted = format(p.toolC, '.4f')
  61. no_drills = 1
  62. if str(p['options']['type']) == 'Excellon':
  63. for i in p['options']['Tools_in_use']:
  64. if i[0] == p.tool:
  65. no_drills = i[2]
  66. gcode = """G00 Z{toolchangez}
  67. T{tool}
  68. M5
  69. M6
  70. (MSG, Change to Tool Dia = {toolC}, Total drills for tool T{tool} = {t_drills})
  71. M0""".format(toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
  72. tool=int(p.tool),
  73. t_drills=no_drills,
  74. toolC=toolC_formatted)
  75. if toolchangexy is not None:
  76. gcode += ('\n' + 'G00 X{toolchangex} Y{toolchangey}'.format(toolchangex=toolchangex,
  77. toolchangey=toolchangey))
  78. return gcode
  79. else:
  80. gcode = """G00 Z{toolchangez}
  81. T{tool}
  82. M5
  83. M6
  84. (MSG, Change to Tool Dia = {toolC})
  85. M0""".format(toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
  86. tool=int(p.tool),
  87. toolC=toolC_formatted)
  88. if toolchangexy is not None:
  89. gcode += ('\n' + 'G00 X{toolchangex} Y{toolchangey}'.format(toolchangex=toolchangex,
  90. toolchangey=toolchangey))
  91. return gcode
  92. def up_to_zero_code(self, p):
  93. return 'G01 Z0'
  94. def position_code(self, p):
  95. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  96. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  97. def rapid_code(self, p):
  98. return ('G00 ' + self.position_code(p)).format(**p)
  99. def linear_code(self, p):
  100. return ('G01 ' + self.position_code(p)).format(**p) + \
  101. ' F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
  102. def end_code(self, p):
  103. coords_xy = p['toolchange_xy']
  104. gcode = ('G00 Z' + self.feedrate_format %(p.fr_decimals, p.endz) + "\n")
  105. if coords_xy is not None:
  106. gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
  107. return gcode
  108. def feedrate_code(self, p):
  109. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
  110. def feedrate_z_code(self, p):
  111. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate_z))
  112. def spindle_code(self,p):
  113. if p.spindlespeed:
  114. return 'M03 S%d' % p.spindlespeed
  115. else:
  116. return 'M03'
  117. def dwell_code(self, p):
  118. if p.dwelltime:
  119. return 'G4 P' + str(p.dwelltime)
  120. def spindle_stop_code(self,p):
  121. return 'M05'