mag_dist_playground.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. gpio_config.mag_dist_rot_pin = 14
  11. if gpio_config.debug:
  12. gpio = MockGPIO()
  13. else:
  14. gpio = PiGPIO()
  15. mag_dist = MagDistributor(config, gpio)
  16. print("MagDistributor Playground")
  17. print("Commands:")
  18. print(" h - home")
  19. print(" m <pos_mm> <rot_deg> - move to position (mm, deg)")
  20. print(" q - quit")
  21. while True:
  22. cmd = input("Enter command: ").strip()
  23. if cmd == "q":
  24. print("Exiting.")
  25. break
  26. elif cmd == "h":
  27. print("Homing...")
  28. import asyncio
  29. asyncio.run(mag_dist.home())
  30. print("Homed.")
  31. elif cmd.startswith("m "):
  32. try:
  33. _, pos_mm, rot_deg = cmd.split()
  34. pos_mm = float(pos_mm)
  35. rot_deg = float(rot_deg)
  36. mag_dist.move_mag_distributor_at_pos(pos_mm, rot_deg)
  37. print(f"Moved to {pos_mm} mm, {rot_deg} deg.")
  38. except Exception as e:
  39. print(f"Invalid move command: {e}")
  40. else:
  41. print("Unknown command.")
  42. if __name__ == "__main__":
  43. main()