Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

cut_test_gcode.py 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #!/usr/bin/env python
  2. # general settings
  3. filename = "cut_test.gcode"
  4. pwr = 255
  5. pwr_num = 150
  6. speed_g0 = 3000
  7. speed_g1_num = 500
  8. # settings of single test shape
  9. width = 10
  10. height = 10
  11. dist = 2
  12. # range for tests
  13. iterations = [ 5, 10, 15, 20 ]
  14. speeds_g1 = [ 1000, 500, 200 ]
  15. def drawSquare(w, h, x, y, speed_g1):
  16. write("G0 X" + str(x) + " Y" + str(y) + " S0 F" + str(speed_g0))
  17. square = [
  18. ( x + w, y ),
  19. ( x + w, y + h ),
  20. ( x, y + h ),
  21. ( x, y ),
  22. ]
  23. for xp, yp in square:
  24. write("G1 X" + str(xp) + " Y" + str(yp) + " S" + str(pwr) + " F" + str(speed_g1))
  25. def drawHeart(w, h, x, y, speed_g1):
  26. heart = [
  27. ( 0.0, 5.0 / 8.0 ),
  28. ( 0.0, 6.0 / 8.0 ),
  29. ( 0.1, 7.0 / 8.0 ),
  30. ( 0.2, 8.0 / 8.0 ),
  31. ( 0.3, 8.0 / 8.0 ),
  32. ( 0.4, 7.0 / 8.0 ),
  33. ( 0.5, 6.0 / 8.0 ),
  34. ( 0.6, 7.0 / 8.0 ),
  35. ( 0.7, 8.0 / 8.0 ),
  36. ( 0.8, 8.0 / 8.0 ),
  37. ( 0.9, 7.0 / 8.0 ),
  38. ( 1.0, 6.0 / 8.0 ),
  39. ( 1.0, 5.0 / 8.0 ),
  40. ( 0.9, 4.0 / 8.0 ),
  41. ( 0.8, 3.0 / 8.0 ),
  42. ( 0.7, 2.0 / 8.0 ),
  43. ( 0.6, 1.0 / 8.0 ),
  44. ( 0.5, 0.0 / 8.0 ),
  45. ( 0.4, 1.0 / 8.0 ),
  46. ( 0.3, 2.0 / 8.0 ),
  47. ( 0.2, 3.0 / 8.0 ),
  48. ( 0.1, 4.0 / 8.0 ),
  49. ( 0.0, 5.0 / 8.0 )
  50. ]
  51. write("G0 X" + str(x + heart[0][0] * w) + " Y" + str(y + heart[0][1] * h) + " S0 F" + str(speed_g0))
  52. for xp, yp in heart:
  53. write("G1 X" + str(x + xp * w) + " Y" + str(y + yp * h) + " S" + str(pwr) + " F" + str(speed_g1))
  54. def drawShape(w, h, x, y, speed_g1):
  55. #drawSquare(w, h, x, y, speed_g1)
  56. drawHeart(w, h, x, y, speed_g1)
  57. digits = [
  58. [
  59. # 0
  60. (0.0, 0.0),
  61. (0.0, 1.0),
  62. (1.0, 1.0),
  63. (1.0, 0.0),
  64. (0.0, 0.0)
  65. ], [
  66. # 1
  67. (0.5, 0.0),
  68. (0.5, 1.0)
  69. ], [
  70. # 2
  71. (0.0, 1.0),
  72. (1.0, 1.0),
  73. (1.0, 0.5),
  74. (0.0, 0.5),
  75. (0.0, 0.0),
  76. (1.0, 0.0),
  77. ], [
  78. # 3
  79. (0.0, 1.0),
  80. (1.0, 1.0),
  81. (1.0, 0.5),
  82. (0.0, 0.5),
  83. (1.0, 0.5),
  84. (1.0, 0.0),
  85. (0.0, 0.0),
  86. ], [
  87. # 4
  88. (0.0, 1.0),
  89. (0.0, 0.5),
  90. (1.0, 0.5),
  91. (1.0, 1.0),
  92. (1.0, 0.0),
  93. ], [
  94. # 5
  95. (1.0, 1.0),
  96. (0.0, 1.0),
  97. (0.0, 0.5),
  98. (1.0, 0.5),
  99. (1.0, 0.0),
  100. (0.0, 0.0),
  101. ], [
  102. # 6
  103. (1.0, 1.0),
  104. (0.0, 1.0),
  105. (0.0, 0.0),
  106. (1.0, 0.0),
  107. (1.0, 0.5),
  108. (0.0, 0.5),
  109. ], [
  110. # 7
  111. (0.0, 1.0),
  112. (1.0, 1.0),
  113. (1.0, 0.0),
  114. ], [
  115. # 8
  116. (1.0, 0.5),
  117. (1.0, 1.0),
  118. (0.0, 1.0),
  119. (0.0, 0.5),
  120. (1.0, 0.5),
  121. (1.0, 0.0),
  122. (0.0, 0.0),
  123. (0.0, 0.5),
  124. ], [
  125. # 9
  126. (1.0, 0.5),
  127. (1.0, 1.0),
  128. (0.0, 1.0),
  129. (0.0, 0.5),
  130. (1.0, 0.5),
  131. (1.0, 0.0),
  132. (0.0, 0.0),
  133. ]
  134. ]
  135. font_w = 1.5
  136. font_h = 3.0
  137. font_d = 0.5
  138. def draw_digit(f, i, size_x, size_y, off_x, off_y):
  139. dig = digits[i]
  140. n = 0
  141. for p in dig:
  142. x, y = p
  143. s = ""
  144. if n == 0:
  145. s += "G0 S0 F" + str(speed_g0)
  146. else:
  147. s += "G1 S" + str(pwr_num) + " F" + str(speed_g1_num)
  148. s += " X" + str(off_x + size_x * x)
  149. s += " Y" + str(off_y + size_y * y)
  150. print(s)
  151. f.write(s + "\n")
  152. n += 1
  153. return s
  154. def draw_number(f, n, x, y):
  155. if n >= 1000:
  156. draw_digit(f, int(n / 1000), font_w, font_h, x, y)
  157. draw_digit(f, int((n / 100)) % 10, font_w, font_h, x + font_d + font_w, y)
  158. draw_digit(f, int((n / 10) % 10), font_w, font_h, x + 2 * (font_d + font_w), y)
  159. draw_digit(f, int(n % 10), font_w, font_h, x + 3 * (font_d + font_w), y)
  160. elif n >= 100:
  161. draw_digit(f, int(n / 100), font_w, font_h, x, y)
  162. draw_digit(f, int((n / 10) % 10), font_w, font_h, x + font_d + font_w, y)
  163. draw_digit(f, int(n % 10), font_w, font_h, x + 2 * (font_d + font_w), y)
  164. elif n >= 10:
  165. draw_digit(f, int(n / 10), font_w, font_h, x, y)
  166. draw_digit(f, int(n % 10), font_w, font_h, x + font_d + font_w, y)
  167. else:
  168. draw_digit(f, n, font_w, font_h, x, y)
  169. with open(filename, 'w') as f:
  170. def write(s):
  171. print(s)
  172. f.write(s + "\n")
  173. # header
  174. write("G90")
  175. write("G28")
  176. write("G92 X0 Y-20")
  177. write("M3 I")
  178. write("M3 S0")
  179. write("")
  180. # first line is not having the power applied
  181. # TODO
  182. write("G0 X0 Y0 S0 F" + str(speed_g0))
  183. write("G1 X1 Y0 S1 F" + str(speeds_g1[0]))
  184. write("G0 X0 Y0 S0 F" + str(speed_g0))
  185. write("G1 X0 Y1 S1 F" + str(speeds_g1[0]))
  186. write("G0 X0 Y0 S0 F" + str(speed_g0))
  187. max_num_str_len = 4
  188. str_w = (max_num_str_len * font_w) + ((max_num_str_len - 1) * font_d)
  189. write("; iterations")
  190. for i in range(0, len(iterations)):
  191. write("; " + str(iterations[i]))
  192. draw_number(f, iterations[i], (width + str_w) / 2.0 + dist + i * (width + dist), 0)
  193. write("")
  194. write("; speeds")
  195. for i in range(0, len(speeds_g1)):
  196. write("; " + str(speeds_g1[i]))
  197. draw_number(f, speeds_g1[i], 0, (height + font_h) / 2.0 + dist + i * (height + dist))
  198. for i in range(0, len(speeds_g1)):
  199. for j in range(0, len(iterations)):
  200. write("; speed=" + str(speeds_g1[i]) + " n=" + str(iterations[j]))
  201. for k in range(0, iterations[j]):
  202. drawShape(width, height, str_w + dist + j * (width + dist), font_h + dist + i * (height + dist), speeds_g1[i])
  203. write("")
  204. # footer
  205. write("M5")
  206. write("G0 X0 Y0 F" + str(speed_g0))