line_xyz.py 7.6 KB

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