ISEL_ICP_CNC.py 5.3 KB

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