Paste_1.py 5.6 KB

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