ISEL_CNC.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # ########################################################## ##
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # http://flatcam.org #
  4. # File Author: Matthieu Berthomé #
  5. # Date: 5/26/2017 #
  6. # MIT Licence #
  7. # ########################################################## ##
  8. from FlatCAMPostProc import *
  9. class ISEL_CNC(FlatCAMPostProc):
  10. include_header = True
  11. coordinate_format = "%.*f"
  12. feedrate_format = '%.*f'
  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'
  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' + '\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: %s RPM)\n' % str(p['spindlespeed'])
  49. gcode += 'G71\n'
  50. gcode += 'G90\n'
  51. gcode += 'G94\n'
  52. return gcode
  53. def startz_code(self, p):
  54. if p.startz is not None:
  55. return 'G00 Z' + self.coordinate_format%(p.coords_decimals, p.startz)
  56. else:
  57. return ''
  58. def lift_code(self, p):
  59. return 'G00 Z' + self.coordinate_format%(p.coords_decimals, p.z_move)
  60. def down_code(self, p):
  61. return 'G01 Z' + self.coordinate_format%(p.coords_decimals, p.z_cut)
  62. def toolchange_code(self, p):
  63. f_plunge = p.f_plunge
  64. no_drills = 1
  65. toolC_formatted = '%.*f' % (p.decimals, p.toolC)
  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. gcode = """
  71. M05
  72. T{tool}
  73. M06
  74. (MSG, Change to Tool Dia = {toolC} ||| Total drills for tool T{tool} = {t_drills})
  75. M01""".format(tool=int(p.tool), t_drills=no_drills, toolC=toolC_formatted)
  76. if f_plunge is True:
  77. gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move)
  78. return gcode
  79. else:
  80. gcode = """
  81. M05
  82. T{tool}
  83. M06
  84. (MSG, Change to Tool Dia = {toolC})
  85. M01""".format(tool=int(p.tool), toolC=toolC_formatted)
  86. if f_plunge is True:
  87. gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move)
  88. return gcode
  89. def up_to_zero_code(self, p):
  90. return 'G01 Z0'
  91. def position_code(self, p):
  92. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  93. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  94. def rapid_code(self, p):
  95. return ('G00 ' + self.position_code(p)).format(**p)
  96. def linear_code(self, p):
  97. return ('G01 ' + self.position_code(p)).format(**p)
  98. def end_code(self, p):
  99. coords_xy = p['xy_toolchange']
  100. gcode = ('G00 Z' + self.feedrate_format %(p.fr_decimals, p.z_end) + "\n")
  101. if coords_xy is not None:
  102. gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
  103. return gcode
  104. def feedrate_code(self, p):
  105. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
  106. def z_feedrate_code(self, p):
  107. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, p.z_feedrate))
  108. def spindle_code(self, p):
  109. sdir = {'CW': 'M03', 'CCW': 'M04'}[p.spindledir]
  110. if p.spindlespeed:
  111. return '%s S%s' % (sdir, str(p.spindlespeed))
  112. else:
  113. return sdir
  114. def dwell_code(self, p):
  115. if p.dwelltime:
  116. return 'G4 P' + str(p.dwelltime)
  117. def spindle_stop_code(self,p):
  118. return 'M05'