123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- #!/usr/bin/env python
-
- # general settings
- filename = "cut_test.gcode"
- pwr = 255
- pwr_num = 150
- speed_g0 = 3000
- speed_g1_num = 500
-
- # settings of single test shape
- width = 10
- height = 10
- dist = 2
-
- # range for tests
- iterations = [ 5, 10, 15, 20 ]
- speeds_g1 = [ 1000, 500, 200 ]
-
- def drawSquare(w, h, x, y, speed_g1):
- write("G0 X" + str(x) + " Y" + str(y) + " S0 F" + str(speed_g0))
- square = [
- ( x + w, y ),
- ( x + w, y + h ),
- ( x, y + h ),
- ( x, y ),
- ]
- for xp, yp in square:
- write("G1 X" + str(xp) + " Y" + str(yp) + " S" + str(pwr) + " F" + str(speed_g1))
-
- def drawHeart(w, h, x, y, speed_g1):
- heart = [
- ( 0.0, 5.0 / 8.0 ),
- ( 0.0, 6.0 / 8.0 ),
- ( 0.1, 7.0 / 8.0 ),
- ( 0.2, 8.0 / 8.0 ),
- ( 0.3, 8.0 / 8.0 ),
- ( 0.4, 7.0 / 8.0 ),
- ( 0.5, 6.0 / 8.0 ),
- ( 0.6, 7.0 / 8.0 ),
- ( 0.7, 8.0 / 8.0 ),
- ( 0.8, 8.0 / 8.0 ),
- ( 0.9, 7.0 / 8.0 ),
- ( 1.0, 6.0 / 8.0 ),
- ( 1.0, 5.0 / 8.0 ),
- ( 0.9, 4.0 / 8.0 ),
- ( 0.8, 3.0 / 8.0 ),
- ( 0.7, 2.0 / 8.0 ),
- ( 0.6, 1.0 / 8.0 ),
- ( 0.5, 0.0 / 8.0 ),
- ( 0.4, 1.0 / 8.0 ),
- ( 0.3, 2.0 / 8.0 ),
- ( 0.2, 3.0 / 8.0 ),
- ( 0.1, 4.0 / 8.0 ),
- ( 0.0, 5.0 / 8.0 )
- ]
- write("G0 X" + str(x + heart[0][0] * w) + " Y" + str(y + heart[0][1] * h) + " S0 F" + str(speed_g0))
- for xp, yp in heart:
- write("G1 X" + str(x + xp * w) + " Y" + str(y + yp * h) + " S" + str(pwr) + " F" + str(speed_g1))
-
- def drawShape(w, h, x, y, speed_g1):
- #drawSquare(w, h, x, y, speed_g1)
- drawHeart(w, h, x, y, speed_g1)
-
- digits = [
- [
- # 0
- (0.0, 0.0),
- (0.0, 1.0),
- (1.0, 1.0),
- (1.0, 0.0),
- (0.0, 0.0)
- ], [
- # 1
- (0.5, 0.0),
- (0.5, 1.0)
- ], [
- # 2
- (0.0, 1.0),
- (1.0, 1.0),
- (1.0, 0.5),
- (0.0, 0.5),
- (0.0, 0.0),
- (1.0, 0.0),
- ], [
- # 3
- (0.0, 1.0),
- (1.0, 1.0),
- (1.0, 0.5),
- (0.0, 0.5),
- (1.0, 0.5),
- (1.0, 0.0),
- (0.0, 0.0),
- ], [
- # 4
- (0.0, 1.0),
- (0.0, 0.5),
- (1.0, 0.5),
- (1.0, 1.0),
- (1.0, 0.0),
- ], [
- # 5
- (1.0, 1.0),
- (0.0, 1.0),
- (0.0, 0.5),
- (1.0, 0.5),
- (1.0, 0.0),
- (0.0, 0.0),
- ], [
- # 6
- (1.0, 1.0),
- (0.0, 1.0),
- (0.0, 0.0),
- (1.0, 0.0),
- (1.0, 0.5),
- (0.0, 0.5),
- ], [
- # 7
- (0.0, 1.0),
- (1.0, 1.0),
- (1.0, 0.0),
- ], [
- # 8
- (1.0, 0.5),
- (1.0, 1.0),
- (0.0, 1.0),
- (0.0, 0.5),
- (1.0, 0.5),
- (1.0, 0.0),
- (0.0, 0.0),
- (0.0, 0.5),
- ], [
- # 9
- (1.0, 0.5),
- (1.0, 1.0),
- (0.0, 1.0),
- (0.0, 0.5),
- (1.0, 0.5),
- (1.0, 0.0),
- (0.0, 0.0),
- ]
- ]
-
- font_w = 1.5
- font_h = 3.0
- font_d = 0.5
-
- def draw_digit(f, i, size_x, size_y, off_x, off_y):
- dig = digits[i]
- n = 0
- for p in dig:
- x, y = p
- s = ""
-
- if n == 0:
- s += "G0 S0 F" + str(speed_g0)
- else:
- s += "G1 S" + str(pwr_num) + " F" + str(speed_g1_num)
-
- s += " X" + str(off_x + size_x * x)
- s += " Y" + str(off_y + size_y * y)
-
- print(s)
- f.write(s + "\n")
- n += 1
-
- return s
-
- def draw_number(f, n, x, y):
- if n >= 1000:
- draw_digit(f, int(n / 1000), font_w, font_h, x, y)
- draw_digit(f, int((n / 100)) % 10, font_w, font_h, x + font_d + font_w, y)
- draw_digit(f, int((n / 10) % 10), font_w, font_h, x + 2 * (font_d + font_w), y)
- draw_digit(f, int(n % 10), font_w, font_h, x + 3 * (font_d + font_w), y)
- elif n >= 100:
- draw_digit(f, int(n / 100), font_w, font_h, x, y)
- draw_digit(f, int((n / 10) % 10), font_w, font_h, x + font_d + font_w, y)
- draw_digit(f, int(n % 10), font_w, font_h, x + 2 * (font_d + font_w), y)
- elif n >= 10:
- draw_digit(f, int(n / 10), font_w, font_h, x, y)
- draw_digit(f, int(n % 10), font_w, font_h, x + font_d + font_w, y)
- else:
- draw_digit(f, n, font_w, font_h, x, y)
-
- with open(filename, 'w') as f:
- def write(s):
- print(s)
- f.write(s + "\n")
-
- # header
- write("G90")
- write("G28")
- write("G92 X0 Y-20")
- write("M3 I")
- write("M3 S0")
- write("")
-
- # first line is not having the power applied
- # TODO
- write("G0 X0 Y0 S0 F" + str(speed_g0))
- write("G1 X1 Y0 S1 F" + str(speeds_g1[0]))
- write("G0 X0 Y0 S0 F" + str(speed_g0))
- write("G1 X0 Y1 S1 F" + str(speeds_g1[0]))
- write("G0 X0 Y0 S0 F" + str(speed_g0))
-
- max_num_str_len = 4
- str_w = (max_num_str_len * font_w) + ((max_num_str_len - 1) * font_d)
-
- write("; iterations")
- for i in range(0, len(iterations)):
- write("; " + str(iterations[i]))
- draw_number(f, iterations[i], (width + str_w) / 2.0 + dist + i * (width + dist), 0)
- write("")
-
- write("; speeds")
- for i in range(0, len(speeds_g1)):
- write("; " + str(speeds_g1[i]))
- draw_number(f, speeds_g1[i], 0, (height + font_h) / 2.0 + dist + i * (height + dist))
-
- for i in range(0, len(speeds_g1)):
- for j in range(0, len(iterations)):
- write("; speed=" + str(speeds_g1[i]) + " n=" + str(iterations[j]))
- for k in range(0, iterations[j]):
- drawShape(width, height, str_w + dist + j * (width + dist), font_h + dist + i * (height + dist), speeds_g1[i])
- write("")
-
- # footer
- write("M5")
- write("G0 X0 Y0 F" + str(speed_g0))
|