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 - cross-platform #211

Conversation

PieterBecking
Copy link
Contributor

@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
Contributor 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.

support Linux; black format; and delete pickle
@PieterBecking
Copy link
Contributor Author

@YilingQiao Thank you for the improvement. I like the option of the mac flag for platform selection. Works like a charm!

@PieterBecking PieterBecking changed the title Interactive drone controlled - macos Interactive drone controlled - cross-platform Dec 22, 2024
@PieterBecking
Copy link
Contributor Author

@zhouxian Works cross-platform now

@zhouxian
Copy link
Collaborator

@YilingQiao could you make final approval?

@YilingQiao
Copy link
Collaborator

YilingQiao commented Dec 22, 2024

@PieterBecking We really appreciate your time and help.
Could you please take a few additional steps:

  1. Add an explanation for the -m argument in the README.
  2. Use black examples/drone to format the code so it can pass the CI.

After those I will merge this PR. Thank you!

@OIEIEIO
Copy link

OIEIEIO commented Dec 22, 2024

Ubuntu 24 - python interactive_drone.py --vis
Screencast from 2024-12-22 11-44-36.webm

@YilingQiao YilingQiao merged commit 43b11df into Genesis-Embodied-AI:main Dec 22, 2024
1 check passed
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.

5 participants