mag_dist_playground.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import sys
  2. import time
  3. from robot_control.src.robot.mag_distributor import MagDistributor
  4. from robot_control.src.utils.config import ConfigParser
  5. from robot_control.src.api.gpio import GPIOInterface, MockGPIO, PiGPIO
  6. def main():
  7. # You may need to adjust these to your environment
  8. config = ConfigParser().config
  9. gpio_config = config.gpio
  10. if gpio_config.debug:
  11. gpio = MockGPIO()
  12. else:
  13. gpio = PiGPIO()
  14. mag_dist = MagDistributor(config, gpio)
  15. print("MagDistributor Playground")
  16. print("Commands:")
  17. print(" h - home")
  18. print(" m <pos_mm> <rot_deg> - move to position (mm, deg)")
  19. print(" q - quit")
  20. while True:
  21. cmd = input("Enter command: ").strip()
  22. if cmd == "q":
  23. print("Exiting.")
  24. break
  25. elif cmd == "h":
  26. print("Homing...")
  27. import asyncio
  28. asyncio.run(mag_dist.home())
  29. print("Homed.")
  30. elif cmd.startswith("m "):
  31. try:
  32. _, pos_mm, rot_deg = cmd.split()
  33. pos_mm = float(pos_mm)
  34. rot_deg = float(rot_deg)
  35. mag_dist.move_mag_distributor_at_pos(pos_mm, rot_deg)
  36. print(f"Moved to {pos_mm} mm, {rot_deg} deg.")
  37. except Exception as e:
  38. print(f"Invalid move command: {e}")
  39. else:
  40. print("Unknown command.")
  41. if __name__ == "__main__":
  42. main()