Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive drone controlled - macos #211

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PieterBecking
Copy link

@PieterBecking PieterBecking commented Dec 21, 2024

Drone Examples

This directory contains examples of drone simulations using the Genesis framework.

Available Examples

1. Interactive Drone (interactive_drone.py)

A real-time interactive drone simulation where you can control the drone using keyboard inputs:

  • ↑ (Up Arrow): Move Forward (North)
  • ↓ (Down Arrow): Move Backward (South)
  • ← (Left Arrow): Move Left (West)
  • → (Right Arrow): Move Right (East)
  • ESC: Quit

Run with:

python interactive_drone.py -v

2. Automated Flight (fly.py)

A pre-programmed drone flight simulation that follows a predefined trajectory stored in fly_traj.pkl.

Run with:

python fly.py -v  # -v flag enables visualization

Technical Details

  • The drone model used is the Crazyflie 2.X (urdf/drones/cf2x.urdf)
  • Base hover RPM is approximately 14468
  • Movement is achieved by varying individual rotor RPMs to create directional thrust
  • The simulation uses realistic physics including gravity and aerodynamics
  • Visualization is optimized for macOS using threaded rendering

Controls Implementation

The interactive drone uses differential RPM control:

  • Forward/Backward movement: Adjusts front/back rotor pairs
  • Left/Right movement: Adjusts left/right rotor pairs
  • All movements maintain a stable hover while creating directional thrust
  • RPM changes are automatically clipped to safe ranges (0-25000 RPM)

Edit: thank you for open-sourcing this project. Really awesome work!

@zhouxian
Copy link
Collaborator

Does it work only on macos or cross-platform? if the latter would be great to merge it

@PieterBecking
Copy link
Author

@zhouxian I think it should work cross-platform (keyboard input with pynput), however think it's good to test that before merging. As I'm on macOS, I followed the rendering framework of examples/render_on_macos.py.

@peteryxu
Copy link

nice example.. I copied and posted the code into seperate files. was able to run the fly.py. For the interactive_drone.py, I was able to launch, saw the viewer, but the arrow control did not work for me. I am on Macbook pro M4. did not see error in std out. Any insight why this would be the case?

@YilingQiao
Copy link
Collaborator

Hi Pieter,

Thank you for your great PR!

I tried your code, and it works perfectly. For security reasons, I removed the pickle and embedded the trajectory directly into the code. I also added an argument to support visualization on Linux. Additionally, I formatted the code using Black to ensure it passes CI. Thank you again for your contribution!

I’ve created a PR to your branch. Please try it out and let me know if it causes any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants