ISEL_ICP_CNC.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 FlatCAMPostProc import *
  9. class ISEL_ICP_CNC(FlatCAMPostProc):
  10. include_header = False
  11. def start_code(self, p):
  12. units = ' ' + str(p['units']).lower()
  13. coords_xy = p['xy_toolchange']
  14. gcode = ''
  15. xmin = '%.*f' % (p.coords_decimals, p['options']['xmin'])
  16. xmax = '%.*f' % (p.coords_decimals, p['options']['xmax'])
  17. ymin = '%.*f' % (p.coords_decimals, p['options']['ymin'])
  18. ymax = '%.*f' % (p.coords_decimals, p['options']['ymax'])
  19. gcode += 'IMF_PBL flatcam\r\n'
  20. if str(p['options']['type']) == 'Geometry':
  21. gcode += '; TOOL DIAMETER: ' + str(p['options']['tool_dia']) + units + '\r\n'
  22. gcode += '; Spindle Speed: %s RPM\r\n' % str(p['spindlespeed'])
  23. gcode += '; Feedrate: ' + str(p['feedrate']) + units + '/min' + '\r\n'
  24. if str(p['options']['type']) == 'Geometry':
  25. gcode += '; Feedrate_Z: ' + str(p['z_feedrate']) + units + '/min' + '\r\n'
  26. gcode += '; Feedrate rapids ' + str(p['feedrate_rapid']) + units + '/min' + '\r\n\r\n'
  27. gcode += '; Z_Cut: ' + str(p['z_cut']) + units + '\r\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' + '\r\n'
  32. gcode += '; Z_Move: ' + str(p['z_move']) + units + '\r\n'
  33. gcode += '; Z Toolchange: ' + str(p['z_toolchange']) + units + '\r\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 + '\r\n'
  37. else:
  38. gcode += '; X,Y Toolchange: ' + "None" + units + '\r\n'
  39. gcode += '; Z Start: ' + str(p['startz']) + units + '\r\n'
  40. gcode += '; Z End: ' + str(p['z_end']) + units + '\r\n'
  41. gcode += '; Steps per circle: ' + str(p['steps_per_circle']) + '\r\n'
  42. if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
  43. gcode += '; Preprocessor Excellon: ' + str(p['pp_excellon_name']) + '\r\n'
  44. else:
  45. gcode += '; Preprocessor Geometry: ' + str(p['pp_geometry_name']) + '\r\n'
  46. gcode += '; X range: ' + '{: >9s}'.format(xmin) + ' ... ' + '{: >9s}'.format(xmax) + ' ' + units + '\r\n'
  47. gcode += '; Y range: ' + '{: >9s}'.format(ymin) + ' ... ' + '{: >9s}'.format(ymax) + ' ' + units + '\r\n'
  48. return gcode
  49. def startz_code(self, p):
  50. if p.startz is not None:
  51. return 'FASTABS Z' + str(int(p.startz * 1000))
  52. else:
  53. return ''
  54. def lift_code(self, p):
  55. return 'FASTABS Z' + str(int(p.z_move * 1000))
  56. def down_code(self, p):
  57. return 'MOVEABS Z' + str(int(p.z_cut * 1000))
  58. def toolchange_code(self, p):
  59. f_plunge = p.f_plunge
  60. no_drills = 1
  61. toolC_formatted = '%.*f' % (p.decimals, p.toolC)
  62. if str(p['options']['type']) == 'Excellon':
  63. for i in p['options']['Tools_in_use']:
  64. if i[0] == p.tool:
  65. no_drills = i[2]
  66. gcode = "GETTOOL {tool}\r\n; Changed to Tool Dia = {toolC}".format(tool=int(p.tool), t_drills=no_drills, toolC=toolC_formatted)
  67. if f_plunge is True:
  68. gcode += '\r\nFASTABS Z' + str(int(p.z_move * 1000))
  69. return gcode
  70. else:
  71. gcode = "GETTOOL {tool}\r\n; Changed to Tool Dia = {toolC})".format(tool=int(p.tool), toolC=toolC_formatted)
  72. if f_plunge is True:
  73. gcode += '\r\nFASTABS Z' + str(int(p.z_move * 1000))
  74. return gcode
  75. def up_to_zero_code(self, p):
  76. return 'MOVEABS Z0'
  77. def position_code(self, p):
  78. return ('X' + str(int(p.x * 1000)) + ' Y' + str(int(p.y * 1000)))
  79. def rapid_code(self, p):
  80. return ('FASTABS ' + self.position_code(p)).format(**p)
  81. def linear_code(self, p):
  82. return ('MOVEABS ' + self.position_code(p)).format(**p)
  83. def end_code(self, p):
  84. gcode = ''
  85. gcode += 'WPCLEAR\r\n'
  86. gcode += 'FASTABS Z0\r\n'
  87. gcode += 'FASTABS X0 Y0\r\n'
  88. gcode += 'PROGEND'
  89. return gcode
  90. def feedrate_code(self, p):
  91. return 'VEL ' + str(int(p.feedrate / 60 * 1000))
  92. def z_feedrate_code(self, p):
  93. return 'VEL ' + str(int(p.z_feedrate / 60 * 1000))
  94. def spindle_code(self, p):
  95. sdir = {'CW': 'SPINDLE CW', 'CCW': 'SPINDLE CCW'}[p.spindledir]
  96. if p.spindlespeed:
  97. return '%s RPM%s' % (sdir, str(int(p.spindlespeed)))
  98. else:
  99. return sdir
  100. def dwell_code(self, p):
  101. if p.dwelltime:
  102. return 'WAIT ' + str(int(p.dwelltime * 1000))
  103. def spindle_stop_code(self,p):
  104. return 'SPINDLE OFF'