scalecalc.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python
  2. """
  3. # EMC2 stepper SCALE calculation helper
  4. # Copyright (c) 2009 Michael Buesch <mb@bu3sch.de>
  5. # Licensed under the GNU GPL version 2 or (at your option) any later version.
  6. """
  7. import sys
  8. import getopt
  9. degree_per_fullstep = 1.8
  10. units_per_rev = None
  11. range_max = 30
  12. def usage():
  13. print "Usage: %s [OPTIONS]" % sys.argv[0]
  14. print ""
  15. print "-u|--units-per-rev X Use X units per revolution (mandatory)"
  16. print "-d|--deg-per-fullstep X Use X degree per motor-fullstep (default 1.8)"
  17. print "-r|--range X List scale values up to X microsteps (default 30)"
  18. print "-h|--help Print this help text"
  19. try:
  20. (opts, args) = getopt.getopt(sys.argv[1:],
  21. "hu:d:r:",
  22. [ "help", "units-per-rev=", "deg-per-fullstep=",
  23. "range=", ])
  24. for (o, v) in opts:
  25. if o in ("-h", "--help"):
  26. usage()
  27. sys.exit(0)
  28. if o in ("-u", "--units-per-rev"):
  29. units_per_rev = float(v)
  30. if o in ("-d", "--deg-per-fullstep"):
  31. degree_per_fullstep = float(v)
  32. if o in ("-r", "--range"):
  33. range_max = int(v)
  34. if units_per_rev is None:
  35. raise ValueError()
  36. except (ValueError, getopt.GetoptError):
  37. usage()
  38. sys.exit(1)
  39. for microsteps in range(1, range_max + 1):
  40. scale = (float(microsteps) / float(degree_per_fullstep)) *\
  41. 360.0 * (1.0 / float(units_per_rev))
  42. print "%d microsteps => SCALE=%f" % (microsteps, scale)