line_xyz.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. from FlatCAMPostProc import *
  2. class line_xyz(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 += 'G94\n'
  43. return gcode
  44. def startz_code(self, p):
  45. if p.startz is not None:
  46. g = 'G00 ' + 'X' + self.coordinate_format%(p.coords_decimals, p.x) + \
  47. ' Y' + self.coordinate_format%(p.coords_decimals, p.y) + \
  48. ' Z' + self.coordinate_format%(p.coords_decimals, p.startz)
  49. return g
  50. else:
  51. return ''
  52. def lift_code(self, p):
  53. g = 'G00 ' + 'X' + self.coordinate_format % (p.coords_decimals, p.x) + \
  54. ' Y' + self.coordinate_format % (p.coords_decimals, p.y) + \
  55. ' Z' + self.coordinate_format % (p.coords_decimals, p.z_move)
  56. return g
  57. def down_code(self, p):
  58. g = 'G01 ' + 'X' + self.coordinate_format % (p.coords_decimals, p.x) + \
  59. ' Y' + self.coordinate_format % (p.coords_decimals, p.y) + \
  60. ' Z' + self.coordinate_format % (p.coords_decimals, p.z_cut)
  61. return g
  62. def toolchange_code(self, p):
  63. toolchangez = p.toolchangez
  64. toolchangexy = p.toolchange_xy
  65. f_plunge = p.f_plunge
  66. gcode = ''
  67. if toolchangexy is not None:
  68. toolchangex = toolchangexy[0]
  69. toolchangey = toolchangexy[1]
  70. else:
  71. if str(p['options']['type']) == 'Excellon':
  72. toolchangex = p.oldx
  73. toolchangey = p.oldy
  74. else:
  75. toolchangex = p.x
  76. toolchangey = p.y
  77. no_drills = 1
  78. if int(p.tool) == 1 and p.startz is not None:
  79. toolchangez = p.startz
  80. if p.units.upper() == 'MM':
  81. toolC_formatted = format(p.toolC, '.2f')
  82. else:
  83. toolC_formatted = format(p.toolC, '.4f')
  84. if str(p['options']['type']) == 'Excellon':
  85. for i in p['options']['Tools_in_use']:
  86. if i[0] == p.tool:
  87. no_drills = i[2]
  88. gcode = """
  89. M5
  90. G00 X{toolchangex} Y{toolchangey} Z{toolchangez}
  91. T{tool}
  92. M6
  93. (MSG, Change to Tool Dia = {toolC} ||| Total drills for tool T{tool} = {t_drills})
  94. M0""".format(toolchangex=self.coordinate_format%(p.coords_decimals, toolchangex),
  95. toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
  96. toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
  97. tool=int(p.tool),
  98. t_drills=no_drills,
  99. toolC=toolC_formatted)
  100. if f_plunge is True:
  101. gcode += """\nG00 X{toolchangex} Y{toolchangey} Z{z_move}""".format(
  102. toolchangex=self.coordinate_format%(p.coords_decimals, toolchangex),
  103. toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
  104. z_move=self.coordinate_format % (p.coords_decimals, p.z_move))
  105. return gcode
  106. else:
  107. gcode = """
  108. M5
  109. G00 X{toolchangex} Y{toolchangey} Z{toolchangez}
  110. T{tool}
  111. M6
  112. (MSG, Change to Tool Dia = {toolC})
  113. M0""".format(toolchangex=self.coordinate_format%(p.coords_decimals, toolchangex),
  114. toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
  115. toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
  116. tool=int(p.tool),
  117. toolC=toolC_formatted)
  118. if f_plunge is True:
  119. gcode += """\nG00 X{toolchangex} Y{toolchangey} Z{z_move}""".format(
  120. toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex),
  121. toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
  122. z_move=self.coordinate_format % (p.coords_decimals, p.z_move))
  123. return gcode
  124. def up_to_zero_code(self, p):
  125. g = 'G01 ' + 'X' + self.coordinate_format % (p.coords_decimals, p.x) + \
  126. ' Y' + self.coordinate_format % (p.coords_decimals, p.y) + \
  127. ' Z0'
  128. return g
  129. def position_code(self, p):
  130. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  131. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  132. def rapid_code(self, p):
  133. g = ('G00 ' + self.position_code(p)).format(**p)
  134. g += ' Z' + self.coordinate_format % (p.coords_decimals, p.z_move)
  135. return g
  136. def linear_code(self, p):
  137. g = ('G01 ' + self.position_code(p)).format(**p)
  138. g += ' Z' + self.coordinate_format % (p.coords_decimals, p.z_cut)
  139. return g
  140. def end_code(self, p):
  141. coords_xy = p['toolchange_xy']
  142. if coords_xy is not None:
  143. g = 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
  144. else:
  145. g = ('G00 ' + self.position_code(p)).format(**p)
  146. g += ' Z' + self.coordinate_format % (p.coords_decimals, p.endz)
  147. return g
  148. def feedrate_code(self, p):
  149. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
  150. def feedrate_z_code(self, p):
  151. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate_z))
  152. def spindle_code(self, p):
  153. if p.spindlespeed:
  154. return 'M03 S' + str(p.spindlespeed)
  155. else:
  156. return 'M03'
  157. def dwell_code(self, p):
  158. if p.dwelltime:
  159. return 'G4 P' + str(p.dwelltime)
  160. def spindle_stop_code(self,p):
  161. return 'M05'