Default_no_M6.py 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. class Default_no_M6(PreProc):
  10. include_header = True
  11. coordinate_format = "%.*f"
  12. feedrate_format = '%.*f'
  13. def start_code(self, p):
  14. units = ' ' + str(p['units']).lower()
  15. coords_xy = p['xy_toolchange']
  16. end_coords_xy = p['xy_end']
  17. gcode = '(This preprocessor is the default preprocessor used by FlatCAM.)\n'
  18. gcode += '(It is made to work with MACH3 compatible motion controllers.)\n\n'
  19. xmin = '%.*f' % (p.coords_decimals, p['options']['xmin'])
  20. xmax = '%.*f' % (p.coords_decimals, p['options']['xmax'])
  21. ymin = '%.*f' % (p.coords_decimals, p['options']['ymin'])
  22. ymax = '%.*f' % (p.coords_decimals, p['options']['ymax'])
  23. if str(p['options']['type']) == 'Geometry':
  24. gcode += '(TOOL DIAMETER: ' + str(p['options']['tool_dia']) + units + ')\n'
  25. gcode += '(Feedrate_XY: ' + str(p['feedrate']) + units + '/min' + ')\n'
  26. gcode += '(Feedrate_Z: ' + str(p['z_feedrate']) + units + '/min' + ')\n'
  27. gcode += '(Feedrate rapids ' + str(p['feedrate_rapid']) + units + '/min' + ')\n' + '\n'
  28. gcode += '(Z_Cut: ' + str(p['z_cut']) + units + ')\n'
  29. if p['multidepth'] is True:
  30. gcode += '(DepthPerCut: ' + str(p['z_depthpercut']) + units + ' <=>' + \
  31. str(math.ceil(abs(p['z_cut']) / p['z_depthpercut'])) + ' passes' + ')\n'
  32. gcode += '(Z_Move: ' + str(p['z_move']) + units + ')\n'
  33. elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True:
  34. gcode += '\n(TOOLS DIAMETER: )\n'
  35. for tool, val in p['exc_tools'].items():
  36. gcode += '(Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + ')\n'
  37. gcode += '\n(FEEDRATE Z: )\n'
  38. for tool, val in p['exc_tools'].items():
  39. gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \
  40. str(val['data']["tools_drill_feedrate_z"]) + ')\n'
  41. gcode += '\n(FEEDRATE RAPIDS: )\n'
  42. for tool, val in p['exc_tools'].items():
  43. gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \
  44. str(val['data']["tools_drill_feedrate_rapid"]) + ')\n'
  45. gcode += '\n(Z_CUT: )\n'
  46. for tool, val in p['exc_tools'].items():
  47. gcode += '(Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + ')\n'
  48. gcode += '\n(Tools Offset: )\n'
  49. for tool, val in p['exc_cnc_tools'].items():
  50. gcode += '(Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \
  51. str(val['data']["tools_drill_offset"]) + ')\n'
  52. if p['multidepth'] is True:
  53. gcode += '\n(DEPTH_PER_CUT: )\n'
  54. for tool, val in p['exc_tools'].items():
  55. gcode += '(Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \
  56. str(val['data']["tools_drill_depthperpass"]) + ')\n'
  57. gcode += '\n(Z_MOVE: )\n'
  58. for tool, val in p['exc_tools'].items():
  59. gcode += '(Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + ')\n'
  60. gcode += '\n'
  61. if p['toolchange'] is True:
  62. gcode += '(Z Toolchange: ' + str(p['z_toolchange']) + units + ')\n'
  63. if coords_xy is not None:
  64. gcode += '(X,Y Toolchange: ' + "%.*f, %.*f" % (p.decimals, coords_xy[0],
  65. p.decimals, coords_xy[1]) + units + ')\n'
  66. else:
  67. gcode += '(X,Y Toolchange: ' + "None" + units + ')\n'
  68. gcode += '(Z Start: ' + str(p['startz']) + units + ')\n'
  69. gcode += '(Z End: ' + str(p['z_end']) + units + ')\n'
  70. if end_coords_xy is not None:
  71. gcode += '(X,Y End: ' + "%.*f, %.*f" % (p.decimals, end_coords_xy[0],
  72. p.decimals, end_coords_xy[1]) + units + ')\n'
  73. else:
  74. gcode += '(X,Y End: ' + "None" + units + ')\n'
  75. gcode += '(Steps per circle: ' + str(p['steps_per_circle']) + ')\n'
  76. if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
  77. gcode += '(Preprocessor Excellon: ' + str(p['pp_excellon_name']) + ')\n' + '\n'
  78. else:
  79. gcode += '(Preprocessor Geometry: ' + str(p['pp_geometry_name']) + ')\n' + '\n'
  80. gcode += '(X range: ' + '{: >9s}'.format(xmin) + ' ... ' + '{: >9s}'.format(xmax) + ' ' + units + ')\n'
  81. gcode += '(Y range: ' + '{: >9s}'.format(ymin) + ' ... ' + '{: >9s}'.format(ymax) + ' ' + units + ')\n\n'
  82. gcode += '(Spindle Speed: %s RPM)\n' % str(p['spindlespeed'])
  83. gcode += ('G20\n' if p.units.upper() == 'IN' else 'G21\n')
  84. gcode += 'G90\n'
  85. gcode += 'G94'
  86. return gcode
  87. def startz_code(self, p):
  88. if p.startz is not None:
  89. return 'G00 Z' + self.coordinate_format % (p.coords_decimals, p.startz)
  90. else:
  91. return ''
  92. def lift_code(self, p):
  93. return 'G00 Z' + self.coordinate_format % (p.coords_decimals, p.z_move)
  94. def down_code(self, p):
  95. return 'G01 Z' + self.coordinate_format % (p.coords_decimals, p.z_cut)
  96. def toolchange_code(self, p):
  97. z_toolchange = p.z_toolchange
  98. toolchangexy = p.xy_toolchange
  99. f_plunge = p.f_plunge
  100. if toolchangexy is not None:
  101. x_toolchange = toolchangexy[0]
  102. y_toolchange = toolchangexy[1]
  103. else:
  104. x_toolchange = 0.0
  105. y_toolchange = 0.0
  106. no_drills = 1
  107. if int(p.tool) == 1 and p.startz is not None:
  108. z_toolchange = p.startz
  109. toolC_formatted = '%.*f' % (p.decimals, p.toolC)
  110. if str(p['options']['type']) == 'Excellon':
  111. for i in p['options']['Tools_in_use']:
  112. if i[0] == p.tool:
  113. no_drills = i[2]
  114. if toolchangexy is not None:
  115. gcode = """
  116. M5
  117. G00 Z{z_toolchange}
  118. T{tool}
  119. G00 X{x_toolchange} Y{y_toolchange}
  120. (MSG, Change to Tool Dia = {toolC} ||| Total drills for tool T{tool} = {t_drills})
  121. M0
  122. G00 Z{z_toolchange}
  123. """.format(x_toolchange=self.coordinate_format % (p.coords_decimals, x_toolchange),
  124. y_toolchange=self.coordinate_format % (p.coords_decimals, y_toolchange),
  125. z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
  126. tool=int(p.tool),
  127. t_drills=no_drills,
  128. toolC=toolC_formatted)
  129. else:
  130. gcode = """
  131. M5
  132. G00 Z{z_toolchange}
  133. T{tool}
  134. (MSG, Change to Tool Dia = {toolC} ||| Total drills for tool T{tool} = {t_drills})
  135. M0
  136. G00 Z{z_toolchange}
  137. """.format(z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
  138. tool=int(p.tool),
  139. t_drills=no_drills,
  140. toolC=toolC_formatted)
  141. if f_plunge is True:
  142. gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move)
  143. return gcode
  144. else:
  145. if toolchangexy is not None:
  146. gcode = """
  147. M5
  148. G00 Z{z_toolchange}
  149. G00 X{x_toolchange} Y{y_toolchange}
  150. T{tool}
  151. (MSG, Change to Tool Dia = {toolC})
  152. M0
  153. G00 Z{z_toolchange}
  154. """.format(x_toolchange=self.coordinate_format % (p.coords_decimals, x_toolchange),
  155. y_toolchange=self.coordinate_format % (p.coords_decimals, y_toolchange),
  156. z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
  157. tool=int(p.tool),
  158. toolC=toolC_formatted)
  159. else:
  160. gcode = """
  161. M5
  162. G00 Z{z_toolchange}
  163. T{tool}
  164. (MSG, Change to Tool Dia = {toolC})
  165. M0
  166. G00 Z{z_toolchange}
  167. """.format(z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
  168. tool=int(p.tool),
  169. toolC=toolC_formatted)
  170. if f_plunge is True:
  171. gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move)
  172. return gcode
  173. def up_to_zero_code(self, p):
  174. return 'G01 Z0'
  175. def position_code(self, p):
  176. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  177. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  178. def rapid_code(self, p):
  179. return ('G00 ' + self.position_code(p)).format(**p)
  180. def linear_code(self, p):
  181. return ('G01 ' + self.position_code(p)).format(**p)
  182. def end_code(self, p):
  183. end_coords_xy = p['xy_end']
  184. gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + "\n")
  185. if end_coords_xy and end_coords_xy != '':
  186. gcode += 'G00 X{x} Y{y}'.format(x=end_coords_xy[0], y=end_coords_xy[1]) + "\n"
  187. return gcode
  188. def feedrate_code(self, p):
  189. return 'G01 F' + str(self.feedrate_format % (p.fr_decimals, p.feedrate))
  190. def z_feedrate_code(self, p):
  191. return 'G01 F' + str(self.feedrate_format % (p.fr_decimals, p.z_feedrate))
  192. def spindle_code(self, p):
  193. sdir = {'CW': 'M03', 'CCW': 'M04'}[p.spindledir]
  194. if p.spindlespeed:
  195. return '%s S%s' % (sdir, str(p.spindlespeed))
  196. else:
  197. return sdir
  198. def dwell_code(self, p):
  199. if p.dwelltime:
  200. return 'G4 P' + str(p.dwelltime)
  201. def spindle_stop_code(self, p):
  202. return 'M05'