Quellcode durchsuchen

feat: add camera playground script for capturing still images; add playground for mag dist

Silas Gruen vor 5 Monaten
Ursprung
Commit
4fe213275b
2 geänderte Dateien mit 77 neuen und 0 gelöschten Zeilen
  1. 29 0
      playgrounds/camera_playground.py
  2. 48 0
      playgrounds/mag_dist_playground.py

+ 29 - 0
playgrounds/camera_playground.py

@@ -0,0 +1,29 @@
+import cv2
+
+def main():
+    cap = cv2.VideoCapture(0)
+    if not cap.isOpened():
+        print("Cannot open camera")
+        return
+
+    print("Press 's' to save a still image. Press 'q' to quit.")
+    while True:
+        ret, frame = cap.read()
+        if not ret:
+            print("Can't receive frame (stream end?). Exiting ...")
+            break
+
+        cv2.imshow('Camera', frame)
+        key = cv2.waitKey(1) & 0xFF
+
+        if key == ord('s'):
+            cv2.imwrite('still_image.jpg', frame)
+            print("Image saved as still_image.jpg")
+        elif key == ord('q'):
+            break
+
+    cap.release()
+    cv2.destroyAllWindows()
+
+if __name__ == "__main__":
+    main()

+ 48 - 0
playgrounds/mag_dist_playground.py

@@ -0,0 +1,48 @@
+import sys
+import time
+
+from robot_control.src.robot.mag_distributor import MagDistributor
+from robot_control.src.utils.config import ConfigParser
+from robot_control.src.api.gpio import GPIOInterface, MockGPIO, PiGPIO
+
+def main():
+    # You may need to adjust these to your environment
+    config = ConfigParser().config
+    gpio_config = config.gpio
+    if gpio_config.debug:
+        gpio = MockGPIO()
+    else:
+        gpio = PiGPIO()
+
+    mag_dist = MagDistributor(config, gpio)
+
+    print("MagDistributor Playground")
+    print("Commands:")
+    print("  h - home")
+    print("  m <pos_mm> <rot_deg> - move to position (mm, deg)")
+    print("  q - quit")
+
+    while True:
+        cmd = input("Enter command: ").strip()
+        if cmd == "q":
+            print("Exiting.")
+            break
+        elif cmd == "h":
+            print("Homing...")
+            import asyncio
+            asyncio.run(mag_dist.home())
+            print("Homed.")
+        elif cmd.startswith("m "):
+            try:
+                _, pos_mm, rot_deg = cmd.split()
+                pos_mm = float(pos_mm)
+                rot_deg = float(rot_deg)
+                mag_dist.move_mag_distributor_at_pos(pos_mm, rot_deg)
+                print(f"Moved to {pos_mm} mm, {rot_deg} deg.")
+            except Exception as e:
+                print(f"Invalid move command: {e}")
+        else:
+            print("Unknown command.")
+
+if __name__ == "__main__":
+    main()