Paste_1.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. ############################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # http://flatcam.org #
  4. # File Author: Marius Adrian Stanciu (c) #
  5. # Date: 3/10/2019 #
  6. # MIT Licence #
  7. ############################################################
  8. from FlatCAMPostProc import *
  9. class Paste_1(FlatCAMPostProc_Tools):
  10. coordinate_format = "%.*f"
  11. feedrate_format = '%.*f'
  12. def start_code(self, p):
  13. units = ' ' + str(p['units']).lower()
  14. coords_xy = [float(eval(a)) for a in p['xy_toolchange'].split(",")]
  15. gcode = ''
  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 += '(TOOL DIAMETER: ' + str(p['options']['tool_dia']) + units + ')\n'
  21. gcode += '(Feedrate_XY: ' + str(p['frxy']) + units + '/min' + ')\n'
  22. gcode += '(Feedrate_Z: ' + str(p['frz']) + units + '/min' + ')\n'
  23. gcode += '(Feedrate_Z_Dispense: ' + str(p['frz_dispense']) + units + '/min' + ')\n'
  24. gcode += '(Z_Dispense_Start: ' + str(p['z_start']) + units + ')\n'
  25. gcode += '(Z_Dispense: ' + str(p['z_dispense']) + units + ')\n'
  26. gcode += '(Z_Dispense_Stop: ' + str(p['z_stop']) + units + ')\n'
  27. gcode += '(Z_Travel: ' + str(p['z_travel']) + units + ')\n'
  28. gcode += '(Z Toolchange: ' + str(p['z_toolchange']) + units + ')\n'
  29. gcode += '(X,Y Toolchange: ' + "%.4f, %.4f" % (coords_xy[0], coords_xy[1]) + units + ')\n'
  30. if 'Paste' in p.pp_solderpaste_name:
  31. gcode += '(Postprocessor SolderPaste Dispensing Geometry: ' + str(p.pp_solderpaste_name) + ')\n' + '\n'
  32. gcode += '(X range: ' + '{: >9s}'.format(xmin) + ' ... ' + '{: >9s}'.format(xmax) + ' ' + units + ')\n'
  33. gcode += '(Y range: ' + '{: >9s}'.format(ymin) + ' ... ' + '{: >9s}'.format(ymax) + ' ' + units + ')\n\n'
  34. gcode += '(Spindle Speed FWD: %s RPM)\n' % str(p['speedfwd'])
  35. gcode += '(Spindle Speed REV: %s RPM)\n' % str(p['speedrev'])
  36. gcode += '(Dwell FWD: %s RPM)\n' % str(p['dwellfwd'])
  37. gcode += '(Dwell REV: %s RPM)\n' % str(p['dwellrev'])
  38. gcode += ('G20\n' if p.units.upper() == 'IN' else 'G21\n')
  39. gcode += 'G90\n'
  40. gcode += 'G94\n'
  41. return gcode
  42. def lift_code(self, p):
  43. return 'G00 Z' + self.coordinate_format%(p.coords_decimals, float(p['z_travel']))
  44. def down_z_start_code(self, p):
  45. return 'G01 Z' + self.coordinate_format%(p.coords_decimals, float(p['z_start']))
  46. def lift_z_dispense_code(self, p):
  47. return 'G01 Z' + self.coordinate_format%(p.coords_decimals, float(p['z_dispense']))
  48. def down_z_stop_code(self, p):
  49. return 'G01 Z' + self.coordinate_format%(p.coords_decimals, float(p['z_stop']))
  50. def toolchange_code(self, p):
  51. z_toolchange = float(p['z_toolchange'])
  52. toolchangexy = [float(eval(a)) for a in p['xy_toolchange'].split(",")]
  53. gcode = ''
  54. if toolchangexy is not None:
  55. x_toolchange = toolchangexy[0]
  56. y_toolchange = toolchangexy[1]
  57. if p.units.upper() == 'MM':
  58. toolC_formatted = format(float(p['toolC']), '.2f')
  59. else:
  60. toolC_formatted = format(float(p['toolC']), '.4f')
  61. if toolchangexy is not None:
  62. gcode = """
  63. G00 Z{z_toolchange}
  64. G00 X{x_toolchange} Y{y_toolchange}
  65. T{tool}
  66. M6
  67. (MSG, Change to Tool with Nozzle Dia = {toolC})
  68. M0
  69. """.format(x_toolchange=self.coordinate_format % (p.coords_decimals, x_toolchange),
  70. y_toolchange=self.coordinate_format % (p.coords_decimals, y_toolchange),
  71. z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
  72. tool=int(int(p.tool)),
  73. toolC=toolC_formatted)
  74. else:
  75. gcode = """
  76. G00 Z{z_toolchange}
  77. T{tool}
  78. M6
  79. (MSG, Change to Tool with Nozzle Dia = {toolC})
  80. M0
  81. """.format(z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
  82. tool=int(int(p.tool)),
  83. toolC=toolC_formatted)
  84. return gcode
  85. def position_code(self, p):
  86. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  87. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  88. def rapid_code(self, p):
  89. return ('G00 ' + self.position_code(p)).format(**p) + '\nG00 Z' + \
  90. self.coordinate_format%(p.coords_decimals, float(p['z_travel']))
  91. def linear_code(self, p):
  92. return ('G01 ' + self.position_code(p)).format(**p)
  93. def end_code(self, p):
  94. coords_xy = [float(eval(a)) for a in p['xy_toolchange'].split(",")]
  95. gcode = ('G00 Z' + self.feedrate_format %(p.fr_decimals, float(p['z_toolchange'])) + "\n")
  96. if coords_xy is not None:
  97. gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
  98. return gcode
  99. def feedrate_xy_code(self, p):
  100. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, float(p['frxy'])))
  101. def z_feedrate_code(self, p):
  102. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, float(p['frz'])))
  103. def feedrate_z_dispense_code(self, p):
  104. return 'G01 F' + str(self.feedrate_format %(p.fr_decimals, float(p['frz_dispense'])))
  105. def spindle_fwd_code(self, p):
  106. if p.spindlespeed:
  107. return 'M03 S' + str(float(p['speedfwd']))
  108. else:
  109. return 'M03'
  110. def spindle_rev_code(self, p):
  111. if p.spindlespeed:
  112. return 'M04 S' + str(float(p['speedrev']))
  113. else:
  114. return 'M04'
  115. def spindle_off_code(self,p):
  116. return 'M05'
  117. def dwell_fwd_code(self, p):
  118. if p.dwelltime:
  119. return 'G4 P' + str(float(p['dwellfwd']))
  120. def dwell_rev_code(self, p):
  121. if p.dwelltime:
  122. return 'G4 P' + str(float(p['dwellrev']))