Toolchange_Probe_general.py 6.3 KB

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