No Description
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.

square_gcode.py 948B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python
  2. filename = "square.gcode"
  3. w = 10
  4. h = 10
  5. n = 20
  6. pwr = 255
  7. speed_g0 = 3000
  8. speed_g1 = 500
  9. with open(filename, 'w') as f:
  10. def write(s):
  11. print(s)
  12. f.write(s + "\n")
  13. # header
  14. write("G90")
  15. write("G28")
  16. write("G92 X0 Y-20")
  17. write("M3 I")
  18. write("M3 S0")
  19. write("")
  20. square = [
  21. ( 0, 0 ),
  22. ( w, 0 ),
  23. ( w, h ),
  24. ( 0, h ),
  25. ]
  26. # first line is not having the power applied
  27. # so just draw it twice
  28. # TODO why?
  29. write("G0 X0 Y0 S0 F" + str(speed_g0))
  30. write("G1 X0 Y0 S" + str(pwr) + " F" + str(speed_g1))
  31. for i in range(0, n):
  32. for x, y in square:
  33. write("G1 X" + str(x) + " Y" + str(y) + " S" + str(pwr) + " F" + str(speed_g1))
  34. write("")
  35. # finish last line
  36. write("G1 X0 Y0 S" + str(pwr) + " F" + str(speed_g1))
  37. write("")
  38. # footer
  39. write("M5")
  40. write("G0 X0 Y0 F" + str(speed_g0))