line_xyz.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. gcode += '(X,Y Toolchange: ' + "%.4f, %.4f" % (coords_xy[0], coords_xy[1]) + units + ')\n'
  23. gcode += '(Z Start: ' + str(p['startz']) + units + ')\n'
  24. gcode += '(Z End: ' + str(p['endz']) + units + ')\n'
  25. gcode += '(Steps per circle: ' + str(p['steps_per_circle']) + ')\n'
  26. if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
  27. gcode += '(Postprocessor Excellon: ' + str(p['pp_excellon_name']) + ')\n'
  28. else:
  29. gcode += '(Postprocessor Geometry: ' + str(p['pp_geometry_name']) + ')\n'
  30. gcode += '(Spindle Speed: %s RPM)\n' % str(p['spindlespeed'])
  31. gcode += ('G20\n' if p.units.upper() == 'IN' else 'G21\n')
  32. gcode += 'G90\n'
  33. gcode += 'G94\n'
  34. return gcode
  35. def startz_code(self, p):
  36. if p.startz is not None:
  37. g = 'G00 ' + 'X' + self.coordinate_format%(p.coords_decimals, p.x) + \
  38. ' Y' + self.coordinate_format%(p.coords_decimals, p.y) + \
  39. ' Z' + self.coordinate_format%(p.coords_decimals, p.startz)
  40. return g
  41. else:
  42. return ''
  43. def lift_code(self, p):
  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.z_move)
  47. return g
  48. def down_code(self, p):
  49. g = 'G01 ' + 'X' + self.coordinate_format % (p.coords_decimals, p.x) + \
  50. ' Y' + self.coordinate_format % (p.coords_decimals, p.y) + \
  51. ' Z' + self.coordinate_format % (p.coords_decimals, p.z_cut)
  52. return g
  53. def toolchange_code(self, p):
  54. toolchangez = p.toolchangez
  55. toolchangexy = p.toolchange_xy
  56. toolchangex = toolchangexy[0]
  57. toolchangey = toolchangexy[1]
  58. no_drills = 1
  59. if int(p.tool) == 1 and p.startz is not None:
  60. toolchangez = p.startz
  61. if p.units.upper() == 'MM':
  62. toolC_formatted = format(p.toolC, '.2f')
  63. else:
  64. toolC_formatted = format(p.toolC, '.4f')
  65. if str(p['options']['type']) == 'Excellon':
  66. for i in p['options']['Tools_in_use']:
  67. if i[0] == p.tool:
  68. no_drills = i[2]
  69. return """G00 X{toolchangex} Y{toolchangey} Z{toolchangez}
  70. T{tool}
  71. M5
  72. M6
  73. (MSG, Change to Tool Dia = {toolC}, Total drills for current tool = {t_drills})
  74. M0""".format(toolchangex=self.coordinate_format%(p.coords_decimals, toolchangex),
  75. toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
  76. toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
  77. tool=int(p.tool),
  78. t_drills=no_drills,
  79. toolC=toolC_formatted)
  80. else:
  81. return """G00 X{toolchangex} Y{toolchangey} Z{toolchangez}
  82. T{tool}
  83. M5
  84. M6
  85. (MSG, Change to Tool Dia = {toolC})
  86. M0""".format(toolchangex=self.coordinate_format%(p.coords_decimals, toolchangex),
  87. toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
  88. toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
  89. tool=int(p.tool),
  90. toolC=toolC_formatted)
  91. def up_to_zero_code(self, p):
  92. g = 'G01 ' + 'X' + self.coordinate_format % (p.coords_decimals, p.x) + \
  93. ' Y' + self.coordinate_format % (p.coords_decimals, p.y) + \
  94. ' Z0'
  95. return g
  96. def position_code(self, p):
  97. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  98. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  99. def rapid_code(self, p):
  100. g = ('G00 ' + self.position_code(p)).format(**p)
  101. g += ' Z' + self.coordinate_format % (p.coords_decimals, p.z_move)
  102. return g
  103. def linear_code(self, p):
  104. g = ('G01 ' + self.position_code(p)).format(**p)
  105. g += ' Z' + self.coordinate_format % (p.coords_decimals, p.z_cut)
  106. return g
  107. def end_code(self, p):
  108. g = ('G00 ' + self.position_code(p)).format(**p)
  109. g += ' Z' + self.coordinate_format % (p.coords_decimals, p.endz)
  110. return g
  111. def feedrate_code(self, p):
  112. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
  113. def feedrate_z_code(self, p):
  114. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate_z))
  115. def spindle_code(self, p):
  116. if p.spindlespeed:
  117. return 'M03 S' + str(p.spindlespeed)
  118. else:
  119. return 'M03'
  120. def dwell_code(self, p):
  121. if p.dwelltime:
  122. return 'G4 P' + str(p.dwelltime)
  123. def spindle_stop_code(self,p):
  124. return 'M05'