ISEL_ICP_CNC.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 = '; This preprocessor is used with a ISEL ICP CNC router.\n\n'
  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\n\n'
  20. if str(p['options']['type']) == 'Geometry':
  21. gcode += '; TOOL DIAMETER: ' + str(p['options']['tool_dia']) + units + '\n'
  22. gcode += '; Spindle Speed: %s RPM\n' % str(p['spindlespeed'])
  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 += '\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'
  44. else:
  45. gcode += '; Preprocessor Geometry: ' + str(p['pp_geometry_name']) + '\n'
  46. gcode += '\n'
  47. gcode += '; X range: ' + '{: >9s}'.format(xmin) + ' ... ' + '{: >9s}'.format(xmax) + ' ' + units + '\n'
  48. gcode += '; Y range: ' + '{: >9s}'.format(ymin) + ' ... ' + '{: >9s}'.format(ymax) + ' ' + units + '\n'
  49. return gcode
  50. def startz_code(self, p):
  51. if p.startz is not None:
  52. return 'FASTABS Z' + str(int(p.startz * 1000))
  53. else:
  54. return ''
  55. def lift_code(self, p):
  56. return 'FASTABS Z' + str(int(p.z_move * 1000))
  57. def down_code(self, p):
  58. return 'MOVEABS Z' + str(int(p.z_cut * 1000))
  59. def toolchange_code(self, p):
  60. f_plunge = p.f_plunge
  61. no_drills = 1
  62. toolC_formatted = '%.*f' % (p.decimals, p.toolC)
  63. if str(p['options']['type']) == 'Excellon':
  64. for i in p['options']['Tools_in_use']:
  65. if i[0] == p.tool:
  66. no_drills = i[2]
  67. gcode = "GETTOOL {tool}\n; Changed to Tool Dia = {toolC}".format(tool=int(p.tool), t_drills=no_drills,
  68. toolC=toolC_formatted)
  69. if f_plunge is True:
  70. gcode += '\nFASTABS Z' + str(int(p.z_move * 1000))
  71. return gcode
  72. else:
  73. gcode = "GETTOOL {tool}\n; Changed to Tool Dia = {toolC}".format(tool=int(p.tool), toolC=toolC_formatted)
  74. if f_plunge is True:
  75. gcode += '\nFASTABS Z' + str(int(p.z_move * 1000))
  76. return gcode
  77. def up_to_zero_code(self, p):
  78. return 'MOVEABS Z0'
  79. def position_code(self, p):
  80. return 'X' + str(int(p.x * 1000)) + ' Y' + str(int(p.y * 1000))
  81. def rapid_code(self, p):
  82. return ('FASTABS ' + self.position_code(p)).format(**p)
  83. def linear_code(self, p):
  84. return ('MOVEABS ' + self.position_code(p)).format(**p)
  85. def end_code(self, p):
  86. gcode = ''
  87. gcode += 'WPCLEAR\n'
  88. gcode += 'FASTABS Z0\n'
  89. gcode += 'FASTABS X0 Y0\n'
  90. gcode += 'PROGEND'
  91. return gcode
  92. def feedrate_code(self, p):
  93. return 'VEL ' + str(int(p.feedrate / 60 * 1000))
  94. def z_feedrate_code(self, p):
  95. return 'VEL ' + str(int(p.z_feedrate / 60 * 1000))
  96. def spindle_code(self, p):
  97. sdir = {'CW': 'SPINDLE CW', 'CCW': 'SPINDLE CCW'}[p.spindledir]
  98. if p.spindlespeed:
  99. return '%s RPM%s' % (sdir, str(int(p.spindlespeed)))
  100. else:
  101. return sdir
  102. def dwell_code(self, p):
  103. if p.dwelltime:
  104. return 'WAIT ' + str(int(p.dwelltime * 1000))
  105. def spindle_stop_code(self, p):
  106. return 'SPINDLE OFF'