Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

grid_gcode.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/usr/bin/env python
  2. filename = "grid.gcode"
  3. w = 200
  4. h = 280
  5. d = 10
  6. pwr = 100
  7. speed_g0 = 3000
  8. speed_g1 = 1000
  9. digits = [
  10. [
  11. # 0
  12. (0.0, 0.0),
  13. (0.0, 1.0),
  14. (1.0, 1.0),
  15. (1.0, 0.0),
  16. (0.0, 0.0)
  17. ], [
  18. # 1
  19. (0.5, 0.0),
  20. (0.5, 1.0)
  21. ], [
  22. # 2
  23. (0.0, 1.0),
  24. (1.0, 1.0),
  25. (1.0, 0.5),
  26. (0.0, 0.5),
  27. (0.0, 0.0),
  28. (1.0, 0.0),
  29. ], [
  30. # 3
  31. (0.0, 1.0),
  32. (1.0, 1.0),
  33. (1.0, 0.5),
  34. (0.0, 0.5),
  35. (1.0, 0.5),
  36. (1.0, 0.0),
  37. (0.0, 0.0),
  38. ], [
  39. # 4
  40. (0.0, 1.0),
  41. (0.0, 0.5),
  42. (1.0, 0.5),
  43. (1.0, 1.0),
  44. (1.0, 0.0),
  45. ], [
  46. # 5
  47. (1.0, 1.0),
  48. (0.0, 1.0),
  49. (0.0, 0.5),
  50. (1.0, 0.5),
  51. (1.0, 0.0),
  52. (0.0, 0.0),
  53. ], [
  54. # 6
  55. (1.0, 1.0),
  56. (0.0, 1.0),
  57. (0.0, 0.0),
  58. (1.0, 0.0),
  59. (1.0, 0.5),
  60. (0.0, 0.5),
  61. ], [
  62. # 7
  63. (0.0, 1.0),
  64. (1.0, 1.0),
  65. (1.0, 0.0),
  66. ], [
  67. # 8
  68. (1.0, 0.5),
  69. (1.0, 1.0),
  70. (0.0, 1.0),
  71. (0.0, 0.5),
  72. (1.0, 0.5),
  73. (1.0, 0.0),
  74. (0.0, 0.0),
  75. (0.0, 0.5),
  76. ], [
  77. # 9
  78. (1.0, 0.5),
  79. (1.0, 1.0),
  80. (0.0, 1.0),
  81. (0.0, 0.5),
  82. (1.0, 0.5),
  83. (1.0, 0.0),
  84. (0.0, 0.0),
  85. ]
  86. ]
  87. font_w = 1.5
  88. font_h = 3.0
  89. font_d = 0.5
  90. def draw_digit(f, i, sx, sy, ox, oy):
  91. dig = digits[i]
  92. n = 0
  93. for p in dig:
  94. x, y = p
  95. s = ""
  96. if n == 0:
  97. s += "G0 S0 F" + str(speed_g0)
  98. else:
  99. s += "G1 S" + str(pwr) + " F" + str(speed_g1)
  100. s += " X" + str(ox + sx * x)
  101. s += " Y" + str(oy + sy * y)
  102. print(s)
  103. f.write(s + "\n")
  104. n += 1
  105. return s
  106. with open(filename, 'w') as f:
  107. def write(s):
  108. print(s)
  109. f.write(s + "\n")
  110. # header
  111. write("G90")
  112. write("G28")
  113. write("G92 X0 Y-20")
  114. write("M3 I")
  115. write("M3 S0")
  116. write("")
  117. # first line is not having the power applied
  118. # so just draw it twice
  119. # TODO why?
  120. write("G0 X0 Y0 S0 F" + str(speed_g0))
  121. write("G1 X0 Y" + str(h) + " S" + str(pwr) + " F" + str(speed_g1))
  122. # vertical lines
  123. write("; vertical lines")
  124. for x in range(0, w + d, d):
  125. write("G0 X" + str(x) + " Y0 S0 F" + str(speed_g0))
  126. write("G1 X" + str(x) + " Y" + str(h) + " S" + str(pwr) + " F" + str(speed_g1))
  127. write("")
  128. # horizontal lines
  129. write("; horizontal lines")
  130. for y in range(0, h + d, d):
  131. write("G0 X0 Y" + str(y) + " S0 F" + str(speed_g0))
  132. write("G1 X" + str(w) + " Y" + str(y) + " S" + str(pwr) + " F" + str(speed_g1))
  133. write("")
  134. # horizontal text
  135. for x in range(0, w, d):
  136. n = int(x / 10)
  137. write("; number '" + str(n) + "' at x " + str(x))
  138. if n >= 10:
  139. draw_digit(f, int(n / 10), font_w, font_h, font_d + x, font_d)
  140. draw_digit(f, int(n % 10), font_w, font_h, 2 * font_d + font_w + x, font_d)
  141. else:
  142. draw_digit(f, n, font_w, font_h, font_d + x, font_d)
  143. write("")
  144. # vertical text
  145. for y in range(d, h, d):
  146. n = int(y / 10)
  147. write("; number '" + str(n) + "' at y " + str(y))
  148. if n >= 10:
  149. draw_digit(f, int(n / 10), font_w, font_h, font_d, font_d + y)
  150. draw_digit(f, int(n % 10), font_w, font_h, 2 * font_d + font_w, font_d + y)
  151. else:
  152. draw_digit(f, n, font_w, font_h, font_d, font_d + y)
  153. write("")
  154. # footer
  155. write("M5")
  156. write("G0 X0 Y0 F" + str(speed_g0))