Paste_1.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. if toolchangexy is not None:
  56. x_toolchange = toolchangexy[0]
  57. y_toolchange = toolchangexy[1]
  58. else:
  59. x_toolchange = 0.0
  60. y_toolchange = 0.0
  61. toolC_formatted = '%.*f' % (p.decimals, float(p['toolC']))
  62. if toolchangexy is not None:
  63. gcode = """
  64. G00 Z{z_toolchange}
  65. G00 X{x_toolchange} Y{y_toolchange}
  66. T{tool}
  67. M6
  68. (MSG, Change to Tool with Nozzle Dia = {toolC})
  69. M0
  70. G00 Z{z_toolchange}
  71. """.format(x_toolchange=self.coordinate_format % (p.coords_decimals, x_toolchange),
  72. y_toolchange=self.coordinate_format % (p.coords_decimals, y_toolchange),
  73. z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
  74. tool=int(int(p.tool)),
  75. toolC=toolC_formatted)
  76. else:
  77. gcode = """
  78. G00 Z{z_toolchange}
  79. T{tool}
  80. M6
  81. (MSG, Change to Tool with Nozzle Dia = {toolC})
  82. M0
  83. G00 Z{z_toolchange}
  84. """.format(z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolchange),
  85. tool=int(int(p.tool)),
  86. toolC=toolC_formatted)
  87. return gcode
  88. def position_code(self, p):
  89. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  90. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  91. def rapid_code(self, p):
  92. return ('G00 ' + self.position_code(p)).format(**p) + '\nG00 Z' + \
  93. self.coordinate_format % (p.coords_decimals, float(p['z_travel']))
  94. def linear_code(self, p):
  95. return ('G01 ' + self.position_code(p)).format(**p)
  96. def end_code(self, p):
  97. coords_xy = [float(eval(a)) for a in p['xy_end'].split(",") if a != '']
  98. gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, float(p['z_toolchange'])) + "\n")
  99. if coords_xy and coords_xy != '':
  100. gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
  101. return gcode
  102. def feedrate_xy_code(self, p):
  103. return 'G01 F' + str(self.feedrate_format % (p.fr_decimals, float(p['frxy'])))
  104. def z_feedrate_code(self, p):
  105. return 'G01 F' + str(self.feedrate_format % (p.fr_decimals, float(p['frz'])))
  106. def feedrate_z_dispense_code(self, p):
  107. return 'G01 F' + str(self.feedrate_format % (p.fr_decimals, float(p['frz_dispense'])))
  108. def spindle_fwd_code(self, p):
  109. if p.spindlespeed:
  110. return 'M03 S' + str(float(p['speedfwd']))
  111. else:
  112. return 'M03'
  113. def spindle_rev_code(self, p):
  114. if p.spindlespeed:
  115. return 'M04 S' + str(float(p['speedrev']))
  116. else:
  117. return 'M04'
  118. def spindle_off_code(self, p):
  119. return 'M05'
  120. def dwell_fwd_code(self, p):
  121. if p.dwelltime:
  122. return 'G4 P' + str(float(p['dwellfwd']))
  123. def dwell_rev_code(self, p):
  124. if p.dwelltime:
  125. return 'G4 P' + str(float(p['dwellrev']))