Paste_1.py 6.1 KB

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