ISEL_ICP_CNC.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # ##########################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # http://flatcam.org #
  4. # File Author: Matthieu Berthomé, Daniel Friderich #
  5. # Date: 12/15/2019 #
  6. # MIT Licence #
  7. # ##########################################################
  8. from appPreProcessor import *
  9. class ISEL_ICP_CNC(PreProc):
  10. include_header = False
  11. def start_code(self, p):
  12. units = ' ' + str(p['units']).lower()
  13. coords_xy = p['xy_toolchange']
  14. end_coords_xy = p['xy_end']
  15. gcode = '; This preprocessor is used with a ISEL ICP CNC router.\n\n'
  16. xmin = '%.*f' % (p.coords_decimals, p['options']['xmin'])
  17. xmax = '%.*f' % (p.coords_decimals, p['options']['xmax'])
  18. ymin = '%.*f' % (p.coords_decimals, p['options']['ymin'])
  19. ymax = '%.*f' % (p.coords_decimals, p['options']['ymax'])
  20. gcode += 'IMF_PBL flatcam\n\n'
  21. if str(p['options']['type']) == 'Geometry':
  22. gcode += ';TOOL DIAMETER: ' + str(p['options']['tool_dia']) + units + '\n'
  23. gcode += ';Feedrate_XY: ' + str(p['feedrate']) + units + '/min' + '\n'
  24. gcode += ';Feedrate_Z: ' + str(p['z_feedrate']) + units + '/min' + '\n'
  25. gcode += ';Feedrate rapids ' + str(p['feedrate_rapid']) + units + '/min' + '\n' + '\n'
  26. gcode += ';Z_Cut: ' + str(p['z_cut']) + units + '\n'
  27. if p['multidepth'] is True:
  28. gcode += ';DepthPerCut: ' + str(p['z_depthpercut']) + units + ' <=>' + \
  29. str(math.ceil(abs(p['z_cut']) / p['z_depthpercut'])) + ' passes' + '\n'
  30. gcode += ';Z_Move: ' + str(p['z_move']) + units + '\n'
  31. elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True:
  32. gcode += '\n;TOOLS DIAMETER: \n'
  33. for tool, val in p['exc_tools'].items():
  34. gcode += ';Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + '\n'
  35. gcode += '\n;FEEDRATE Z: \n'
  36. for tool, val in p['exc_tools'].items():
  37. gcode += ';Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \
  38. str(val['data']["tools_drill_feedrate_z"]) + '\n'
  39. gcode += '\n;FEEDRATE RAPIDS: \n'
  40. for tool, val in p['exc_tools'].items():
  41. gcode += ';Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \
  42. str(val['data']["tools_drill_feedrate_rapid"]) + '\n'
  43. gcode += '\n;Z_CUT: \n'
  44. for tool, val in p['exc_tools'].items():
  45. gcode += ';Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + '\n'
  46. gcode += '\n;Tools Offset: \n'
  47. for tool, val in p['exc_cnc_tools'].items():
  48. gcode += ';Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \
  49. str(val['data']["tools_drill_offset"]) + '\n'
  50. if p['multidepth'] is True:
  51. gcode += '\n;DEPTH_PER_CUT: \n'
  52. for tool, val in p['exc_tools'].items():
  53. gcode += ';Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \
  54. str(val['data']["tools_drill_depthperpass"]) + '\n'
  55. gcode += '\n;Z_MOVE: \n'
  56. for tool, val in p['exc_tools'].items():
  57. gcode += ';Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + '\n'
  58. gcode += '\n'
  59. if p['toolchange'] is True:
  60. gcode += ';Z Toolchange: ' + str(p['z_toolchange']) + units + '\n'
  61. if coords_xy is not None:
  62. gcode += ';X,Y Toolchange: ' + "%.*f, %.*f" % (p.decimals, coords_xy[0],
  63. p.decimals, coords_xy[1]) + units + '\n'
  64. else:
  65. gcode += ';X,Y Toolchange: ' + "None" + units + '\n'
  66. gcode += ';Z Start: ' + str(p['startz']) + units + '\n'
  67. gcode += ';Z End: ' + str(p['z_end']) + units + '\n'
  68. if end_coords_xy is not None:
  69. gcode += ';X,Y End: ' + "%.*f, %.*f" % (p.decimals, end_coords_xy[0],
  70. p.decimals, end_coords_xy[1]) + units + '\n'
  71. else:
  72. gcode += ';X,Y End: ' + "None" + units + '\n'
  73. gcode += '(Steps per circle: ' + str(p['steps_per_circle']) + ')\n'
  74. gcode += ';Steps per circle: ' + str(p['steps_per_circle']) + '\n'
  75. if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
  76. gcode += ';Preprocessor Excellon: ' + str(p['pp_excellon_name']) + '\n' + '\n'
  77. else:
  78. gcode += ';Preprocessor Geometry: ' + str(p['pp_geometry_name']) + '\n' + '\n'
  79. gcode += ';X range: ' + '{: >9s}'.format(xmin) + ' ... ' + '{: >9s}'.format(xmax) + ' ' + units + '\n'
  80. gcode += ';Y range: ' + '{: >9s}'.format(ymin) + ' ... ' + '{: >9s}'.format(ymax) + ' ' + units + '\n\n'
  81. gcode += ';Spindle Speed: %s RPM)\n' % str(p['spindlespeed'])
  82. return gcode
  83. def startz_code(self, p):
  84. if p.startz is not None:
  85. return 'FASTABS Z' + str(int(p.startz * 1000))
  86. else:
  87. return ''
  88. def lift_code(self, p):
  89. return 'FASTABS Z' + str(int(p.z_move * 1000))
  90. def down_code(self, p):
  91. return 'MOVEABS Z' + str(int(p.z_cut * 1000))
  92. def toolchange_code(self, p):
  93. f_plunge = p.f_plunge
  94. no_drills = 1
  95. toolC_formatted = '%.*f' % (p.decimals, p.toolC)
  96. if str(p['options']['type']) == 'Excellon':
  97. for i in p['options']['Tools_in_use']:
  98. if i[0] == p.tool:
  99. no_drills = i[2]
  100. gcode = "GETTOOL {tool}\n; Changed to Tool Dia = {toolC}".format(tool=int(p.tool), t_drills=no_drills,
  101. toolC=toolC_formatted)
  102. if f_plunge is True:
  103. gcode += '\nFASTABS Z' + str(int(p.z_move * 1000))
  104. return gcode
  105. else:
  106. gcode = "GETTOOL {tool}\n; Changed to Tool Dia = {toolC}".format(tool=int(p.tool), toolC=toolC_formatted)
  107. if f_plunge is True:
  108. gcode += '\nFASTABS Z' + str(int(p.z_move * 1000))
  109. return gcode
  110. def up_to_zero_code(self, p):
  111. return 'MOVEABS Z0'
  112. def position_code(self, p):
  113. return 'X' + str(int(p.x * 1000)) + ' Y' + str(int(p.y * 1000))
  114. def rapid_code(self, p):
  115. return ('FASTABS ' + self.position_code(p)).format(**p)
  116. def linear_code(self, p):
  117. return ('MOVEABS ' + self.position_code(p)).format(**p)
  118. def end_code(self, p):
  119. gcode = ''
  120. gcode += 'WPCLEAR\n'
  121. gcode += 'FASTABS Z0\n'
  122. gcode += 'FASTABS X0 Y0\n'
  123. gcode += 'PROGEND'
  124. return gcode
  125. def feedrate_code(self, p):
  126. return 'VEL ' + str(int(p.feedrate / 60 * 1000))
  127. def z_feedrate_code(self, p):
  128. return 'VEL ' + str(int(p.z_feedrate / 60 * 1000))
  129. def spindle_code(self, p):
  130. sdir = {'CW': 'SPINDLE CW', 'CCW': 'SPINDLE CCW'}[p.spindledir]
  131. if p.spindlespeed:
  132. return '%s RPM%s' % (sdir, str(int(p.spindlespeed)))
  133. else:
  134. return sdir
  135. def dwell_code(self, p):
  136. if p.dwelltime:
  137. return 'WAIT ' + str(int(p.dwelltime * 1000))
  138. def spindle_stop_code(self, p):
  139. return 'SPINDLE OFF'