marlin.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. from FlatCAMPostProc import *
  2. class marlin(FlatCAMPostProc):
  3. coordinate_format = "%.*f"
  4. feedrate_format = '%.*f'
  5. feedrate_rapid_format = feedrate_format
  6. def start_code(self, p):
  7. units = ' ' + str(p['units']).lower()
  8. coords_xy = p['toolchange_xy']
  9. gcode = ''
  10. if str(p['options']['type']) == 'Geometry':
  11. gcode += ';TOOL DIAMETER: ' + str(p['options']['tool_dia']) + units + '\n' + '\n'
  12. gcode += ';Feedrate: ' + str(p['feedrate']) + units + '/min' + '\n'
  13. if str(p['options']['type']) == 'Geometry':
  14. gcode += ';Feedrate_Z: ' + str(p['feedrate_z']) + units + '/min' + '\n'
  15. gcode += ';Feedrate rapids ' + str(p['feedrate_rapid']) + units + '/min' + '\n' + '\n'
  16. gcode += ';Z_Cut: ' + str(p['z_cut']) + units + '\n'
  17. if str(p['options']['type']) == 'Geometry':
  18. if p['multidepth'] is True:
  19. gcode += ';DepthPerCut: ' + str(p['depthpercut']) + units + ' <=>' + \
  20. str(math.ceil(abs(p['z_cut']) / p['depthpercut'])) + ' passes' + '\n'
  21. gcode += ';Z_Move: ' + str(p['z_move']) + units + '\n'
  22. gcode += ';Z Toolchange: ' + str(p['toolchangez']) + units + '\n'
  23. if coords_xy is not None:
  24. gcode += ';X,Y Toolchange: ' + "%.4f, %.4f" % (coords_xy[0], coords_xy[1]) + units + '\n'
  25. else:
  26. gcode += ';X,Y Toolchange: ' + "None" + units + '\n'
  27. gcode += ';Z Start: ' + str(p['startz']) + units + '\n'
  28. gcode += ';Z End: ' + str(p['endz']) + units + '\n'
  29. gcode += ';Steps per circle: ' + str(p['steps_per_circle']) + '\n'
  30. if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
  31. gcode += ';Postprocessor Excellon: ' + str(p['pp_excellon_name']) + '\n'
  32. else:
  33. gcode += ';Postprocessor Geometry: ' + str(p['pp_geometry_name']) + '\n'
  34. gcode += ';Spindle Speed: ' + str(p['spindlespeed']) + ' RPM' + '\n' + '\n'
  35. gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
  36. gcode += 'G90\n'
  37. return gcode
  38. def startz_code(self, p):
  39. if p.startz is not None:
  40. return 'G0 Z' + self.coordinate_format % (p.coords_decimals, p.startz)
  41. else:
  42. return ''
  43. def lift_code(self, p):
  44. return 'G0 Z' + self.coordinate_format%(p.coords_decimals, p.z_move) + " " + self.feedrate_rapid_code(p)
  45. def down_code(self, p):
  46. return 'G1 Z' + self.coordinate_format%(p.coords_decimals, p.z_cut) + " " + self.end_feedrate_code(p)
  47. def toolchange_code(self, p):
  48. toolchangez = p.toolchangez
  49. no_drills = 1
  50. if int(p.tool) == 1 and p.startz is not None:
  51. toolchangez = p.startz
  52. if p.units.upper() == 'MM':
  53. toolC_formatted = format(p.toolC, '.2f')
  54. else:
  55. toolC_formatted = format(p.toolC, '.4f')
  56. if str(p['options']['type']) == 'Excellon':
  57. for i in p['options']['Tools_in_use']:
  58. if i[0] == p.tool:
  59. no_drills = i[2]
  60. return """G0 Z{toolchangez}
  61. M5
  62. M0 Change to Tool Dia = {toolC}, Total drills for current tool = {t_drills}
  63. """.format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
  64. tool=int(p.tool),
  65. t_drills=no_drills,
  66. toolC=toolC_formatted)
  67. else:
  68. return """G0 Z{toolchangez}
  69. M5
  70. M0 Change to Tool Dia = {toolC}
  71. """.format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
  72. tool=int(p.tool),
  73. toolC=toolC_formatted)
  74. def up_to_zero_code(self, p):
  75. return 'G1 Z0' + " " + self.feedrate_code(p)
  76. def position_code(self, p):
  77. return ('X' + self.coordinate_format + ' Y' + self.coordinate_format) % \
  78. (p.coords_decimals, p.x, p.coords_decimals, p.y)
  79. def rapid_code(self, p):
  80. return ('G0 ' + self.position_code(p)).format(**p) + " " + self.feedrate_rapid_code(p)
  81. def linear_code(self, p):
  82. return ('G1 ' + self.position_code(p)).format(**p) + " " + self.end_feedrate_code(p)
  83. def end_code(self, p):
  84. coords_xy = p['toolchange_xy']
  85. gcode = ('G0 Z' + self.feedrate_format %(p.fr_decimals, p.endz) + " " + self.feedrate_rapid_code(p) + "\n")
  86. if coords_xy is not None:
  87. gcode += 'G0 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + " " + self.feedrate_rapid_code(p) + "\n"
  88. return gcode
  89. def feedrate_code(self, p):
  90. return 'G1 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate))
  91. def end_feedrate_code(self, p):
  92. return 'F' + self.feedrate_format %(p.fr_decimals, p.feedrate)
  93. def feedrate_z_code(self, p):
  94. return 'G1 F' + str(self.feedrate_format %(p.fr_decimals, p.feedrate_z))
  95. def feedrate_rapid_code(self, p):
  96. return 'F' + self.feedrate_rapid_format % (p.fr_decimals, p.feedrate_rapid)
  97. def spindle_code(self,p):
  98. if p.spindlespeed:
  99. return 'M3 S%d' % p.spindlespeed
  100. else:
  101. return 'M3'
  102. def dwell_code(self, p):
  103. if p.dwelltime:
  104. return 'G4 P' + str(p.dwelltime)
  105. def spindle_stop_code(self,p):
  106. return 'M5'