From bdb09909e7c9132fd156654a99bb997ddaebaab5 Mon Sep 17 00:00:00 2001 From: Lucca Pirovano Date: Thu, 11 Jun 2026 14:18:28 -0400 Subject: [PATCH] added ai genned control program, needs root though, going to switch input library --- README.md | 0 control.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ flyupflydown.py | 0 requirements.txt | 1 + 4 files changed, 56 insertions(+) mode change 100644 => 100755 README.md create mode 100755 control.py mode change 100644 => 100755 flyupflydown.py mode change 100644 => 100755 requirements.txt diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/control.py b/control.py new file mode 100755 index 0000000..a7d8718 --- /dev/null +++ b/control.py @@ -0,0 +1,55 @@ +from codrone_edu.drone import * +import keyboard +import time + +drone = Drone() +drone.connect() # or drone.pair() depending on your setup + +print("Connecting to drone...") +time.sleep(3) # Give it time to connect + +try: + drone.takeoff() + print("Drone took off! Use Arrow Keys to fly.") + print("↑ Forward | ↓ Backward | ← Left | → Right") + print("Hold keys for continuous movement. Press 'q' to land and quit.") + + power = 25 # ← Keep this LOW for safety (15-30 recommended) + + while True: + # Reset all movement every loop + drone.set_roll(0) + drone.set_pitch(0) + drone.set_yaw(0) + drone.set_throttle(0) + + # Arrow key controls (slow & safe) + if keyboard.is_pressed('up'): + drone.set_pitch(power) # Forward + if keyboard.is_pressed('down'): + drone.set_pitch(-power) # Backward + if keyboard.is_pressed('left'): + drone.set_roll(-power) # Left + if keyboard.is_pressed('right'): + drone.set_roll(power) # Right + + # Optional: Add throttle control with other keys + if keyboard.is_pressed('w'): + drone.set_throttle(power) # Up + if keyboard.is_pressed('s'): + drone.set_throttle(-power) # Down + + if keyboard.is_pressed('q'): + print("Landing...") + break + + drone.move(0.1) # Send command every 0.1 seconds (smooth control) + time.sleep(0.05) # Fast loop for responsive feel + +except Exception as e: + print("Error:", e) + +finally: + drone.land() + drone.disconnect() + print("Drone landed and disconnected.") diff --git a/flyupflydown.py b/flyupflydown.py old mode 100644 new mode 100755 diff --git a/requirements.txt b/requirements.txt old mode 100644 new mode 100755 index 243dbcc..29b2bb1 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ codrone_edu +keyboard