Repetier.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # ########################################################## ##
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # http://flatcam.org #
  4. # File Author: Marius Adrian Stanciu (c) #
  5. # Date: 3/10/2019 #
  6. # MIT Licence #
  7. # ########################################################## ##
  8. from FlatCAMPostProc import *
  9. class Repetier(FlatCAMPostProc):
  10. coordinate_format = "%.*f"
  11. feedrate_format = '%.*f'
  12. feedrate_rapid_format = feedrate_format
  13. def start_code(self, p):
  14. units = ' ' + str(p['units']).lower()
  15. coords_xy = p['xy_toolchange']
  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. if str(p['options']['type']) == 'Geometry':
  22. gcode += ';TOOL DIAMETER: ' + str(p['options']['tool_dia']) + units + '\n' + '\n'
  23. gcode += ';Feedrate: ' + str(p['feedrate']) + units + '/min' + '\n'
  24. if str(p['options']['type']) == 'Geometry':
  25. gcode += ';Feedrate_Z: ' + str(p['z_feedrate']) + units + '/min' + '\n'
  26. gcode += ';Feedrate rapids ' + str(p['feedrate_rapid']) + units + '/min' + '\n' + '\n'
  27. gcode += ';Z_Cut: ' + str(p['z_cut']) + units + '\n'
  28. if str(p['options']['type']) == 'Geometry':
  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. gcode += ';Z Toolchange: ' + str(p['z_toolchange']) + units + '\n'
  34. if coords_xy is not None:
  35. gcode += ';X,Y Toolchange: ' + "%.*f, %.*f" % (p.decimals, coords_xy[0],
  36. p.decimals, coords_xy[1]) + units + '\n'
  37. else:
  38. gcode += ';X,Y Toolchange: ' + "None" + units + '\n'
  39. gcode += ';Z Start: ' + str(p['startz']) + units + '\n'
  40. gcode += ';Z End: ' + str(p['z_end']) + units + '\n'
  41. gcode += ';Steps per circle: ' + str(p['steps_per_circle']) + '\n'
  42. if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
  43. gcode += ';Preprocessor Excellon: ' + str(p['pp_excellon_name']) + '\n'
  44. else:
  45. gcode += ';Preprocessor Geometry: ' + str(p['pp_geometry_name']) + '\n' + '\n'
  46. gcode += ';X range: ' + '{: >9s}'.format(xmin) + ' ... ' + '{: >9s}'.format(xmax) + ' ' + units + '\n'
  47. gcode += ';Y range: ' + '{: >9s}'.format(ymin) + ' ... ' + '{: >9s}'.format(ymax) + ' ' + units + '\n\n'
  48. gcode += ';Spindle Speed: ' + str(p['spindlespeed']) + ' RPM' + '\n' + '\n'
  49. gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
  50. gcode += 'G90\n'
  51. return gcode
  52. def startz_code(self, p):
  53. if p.startz is not None:
  54. return 'G0 Z' + self.coordinate_format % (p.coords_decimals, p.startz)
  55. else:
  56. return ''
  57. def lift_code(self, p):
  58. return 'G0 Z' + self.coordinate_format%(p.coords_decimals, p.z_move) + " " + self.feedrate_rapid_code(p)
  59. def down_code(self, p):
  60. return 'G1 Z' + self.coordinate_format%(p.coords_decimals, p.z_cut) + " " + self.inline_z_feedrate_code(p)
  61. def toolchange_code(self, p):
  62. z_toolchange = p.z_toolchange
  63. toolchangexy = p.xy_toolchange
  64. f_plunge = p.f_plunge
  65. gcode = ''
  66. if toolchangexy is not None:
  67. x_toolchange = toolchangexy[0]
  68. y_toolchange = toolchangexy[1]
  69. no_drills = 1
  70. if int(p.tool) == 1 and p.startz is not None:
  71. z_toolchange = p.startz
  72. toolC_formatted = '%.*f' % (p.decimals, p.toolC)
  73. if str(p['options']['type']) == 'Excellon':
  74. for i in p['options']['Tools_in_use']:
  75. if i[0] == p.tool:
  76. no_drills = i[2]
  77. if toolchangexy is not None:
  78. gcode = """
  79. G0 Z{z_toolchange}
  80. G0 X{x_toolchange} Y{y_toolchange}
  81. M84
  82. @pause Change to Tool Dia = {toolC}, Total drills for tool T{tool} = {t_drills}
  83. G0 Z{z_toolchange}
  84. """.format(x_toolchange=self.coordinate_format % (p.coords_decimals, x_toolchange),
  85. y_toolchange=self.coordinate_format % (p.coords_decimals, y_toolchange),
  86. z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
  87. tool=int(p.tool),
  88. t_drills=no_drills,
  89. toolC=toolC_formatted)
  90. else:
  91. gcode = """
  92. G0 Z{z_toolchange}
  93. M84
  94. @pause Change to Tool Dia = {toolC}, Total drills for tool T{tool} = {t_drills}
  95. G0 Z{z_toolchange}
  96. """.format(z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
  97. tool=int(p.tool),
  98. t_drills=no_drills,
  99. toolC=toolC_formatted)
  100. if f_plunge is True:
  101. gcode += '\nG0 Z%.*f' % (p.coords_decimals, p.z_move)
  102. return gcode
  103. else:
  104. if toolchangexy is not None:
  105. gcode = """
  106. G0 Z{z_toolchange}
  107. G0 X{x_toolchange} Y{y_toolchange}
  108. M84
  109. @pause Change to tool T{tool} with Tool Dia = {toolC}
  110. G0 Z{z_toolchange}
  111. """.format(x_toolchange=self.coordinate_format % (p.coords_decimals, x_toolchange),
  112. y_toolchange=self.coordinate_format % (p.coords_decimals, y_toolchange),
  113. z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
  114. tool=int(p.tool),
  115. toolC=toolC_formatted)
  116. else:
  117. gcode = """
  118. G0 Z{z_toolchange}
  119. M84
  120. @pause Change to tool T{tool} with Tool Dia = {toolC}
  121. G0 Z{z_toolchange}
  122. """.format(z_toolchange=self.coordinate_format%(p.coords_decimals, z_toolchange),
  123. tool=int(p.tool),
  124. toolC=toolC_formatted)
  125. if f_plunge is True:
  126. gcode += '\nG0 Z%.*f' % (p.coords_decimals, p.z_move)
  127. return gcode
  128. def up_to_zero_code(self, p):
  129. return 'G1 Z0' + " " + self.feedrate_code(p)
  130. def position_code(self, p):
  131. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  132. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  133. def rapid_code(self, p):
  134. return ('G0 ' + self.position_code(p)).format(**p) + " " + self.feedrate_rapid_code(p)
  135. def linear_code(self, p):
  136. return ('G1 ' + self.position_code(p)).format(**p) + " " + self.inline_feedrate_code(p)
  137. def end_code(self, p):
  138. coords_xy = p['xy_toolchange']
  139. gcode = ('G0 Z' + self.feedrate_format %(p.fr_decimals, p.z_end) + " " + self.feedrate_rapid_code(p) + "\n")
  140. if coords_xy is not None:
  141. gcode += 'G0 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + " " + self.feedrate_rapid_code(p) + "\n"
  142. return gcode
  143. def feedrate_code(self, p):
  144. return 'G1 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
  145. def inline_feedrate_code(self, p):
  146. return 'F' + self.feedrate_format %(p.fr_decimals, p.feedrate)
  147. def inline_z_feedrate_code(self, p):
  148. return 'F' + self.feedrate_format %(p.fr_decimals, p.z_feedrate)
  149. def z_feedrate_code(self, p):
  150. return 'G1 F' + str(self.feedrate_format %(p.fr_decimals, p.z_feedrate))
  151. def feedrate_rapid_code(self, p):
  152. return 'F' + self.feedrate_rapid_format % (p.fr_decimals, p.feedrate_rapid)
  153. def spindle_code(self,p):
  154. if p.spindlespeed:
  155. return 'M106 S%d' % p.spindlespeed
  156. else:
  157. return 'M106'
  158. def dwell_code(self, p):
  159. if p.dwelltime:
  160. return 'G4 P' + str(p.dwelltime)
  161. def spindle_stop_code(self,p):
  162. return 'M107'