Skip to main content

Freestyle Quadcopter Flight in Pybullet with Gym and (soon) PettingZoo APIs

Project description

PyFlyt - UAV Flight Simulator Gymnasium Environments for Reinforcement Learning Research

This is a library for testing reinforcement learning algorithms on UAVs. This repo is still under development. We are also actively looking for users and developers, if this sounds like you, don't hesitate to get in touch!

PyFlyt currently supports two separate UAV platforms:

  • QuadX UAV

    • Inspired by the original pybullet drones by University of Toronto's Dynamic Systems Lab
    • Quadrotor UAV in the X configuration
    • Actual full cascaded PID flight controller implementations for each drone.
    • Actual motor RPM simulation using first order differential equation.
    • Modular control structure
    • For developers - 8 implemented flight modes that use tuned cascaded PID flight controllers, available in PyFlyt/core/drones/quadx.py.
  • Fixedwing UAV

Table of Contents

Installation

pip3 install pyflyt

Usage

Usage is similar to any other Gymnasium and (soon) PettingZoo environment:

import gymnasium
import PyFlyt.gym_envs

env = gymnasium.make("PyFlyt/QuadX-Hover-v0")

# omit the below line to remove rendering and let
# the simulation go as fast as possible
env.render()
obs = env.reset()

done = False
while not done:
    observation, reward, termination, truncation, info = env.step(env.action_space.sample())

Environments

PyFlyt/QuadX-Hover-v0

A simple environment where an agent can learn to hover. The environment ends when either the quadcopter collides with the ground or exits the permitted flight dome.

env = gymnasium.make(
  "PyFlyt/QuadX-Hover-v0",
  flight_dome_size: float = 3.0,
  max_duration_seconds: float = 10.0,
  angle_representation: str = "quaternion",
  agent_hz: int = 40,
  render_mode: None | str = None,
)

angle_representation can be either "quaternion" or "euler".

render_mode can be either "human" or None.

PyFlyt/QuadX-Waypoints-v0

A simple environment where the goal is to fly the quadrotor to a collection of random waypoints in space within the permitted flight dome. The environment ends when either the quadrotor collides with the ground or exits the permitted flight dome.

env = gymnasium.make(
  "PyFlyt/QuadX-Waypoints-v0",
  sparse_reward: bool = False,
  num_targets: int = 4,
  use_yaw_targets: bool = False,
  goal_reach_distance: float = 0.2,
  goal_reach_angle: float = 0.1,
  flight_dome_size: float = 5.0,
  max_duration_seconds: float = 10.0,
  angle_representation: str = "quaternion",
  agent_hz: int = 30,
  render_mode: None | str = None,
)

angle_representation can be either "quaternion" or "euler".

render_mode can be either "human" or None.

PyFlyt/Fixedwing-Waypoints-v0

A simple environment where the goal is to fly a fixedwing aircraft towards set of random waypionts in space within the permitted flight dome. The environment ends when either the aircraft collides with the ground or exits the permitted flight dome.

env = gymnasium.make(
  "PyFlyt/Fixedwing-Waypoints-v0",
  sparse_reward: bool = False,
  num_targets: int = 4,
  goal_reach_distance: float = 2.0,
  flight_dome_size: float = 100.0,
  max_duration_seconds: float = 120.0,
  angle_representation: str = "quaternion",
  agent_hz: int = 30,
  render_mode: None | str = None,
)

angle_representation can be either "quaternion" or "euler".

render_mode can be either "human" or None.



Non-Gymnasium examples

If you're not interested in RL but want to use the library for your own research, we provide a bunch of example code in examples/ that you can run with python3 examples/***.py in macOS and Linux.

PyFlyt also has naive support for flying real Crazyflie drones. These examples are provided under examples/crazyflie/***.py. The library is built using CrazyFlie drones, check out the documentation. These scripts are built with as little dependencies as possible, but enable interfacing with real (using the CrazyPA module) or virtual drones easy.

Simulation Only

sim_single.py

Simulates a single drone in the pybullet env with position control.

sim_swarm.py

Simulates a swarm of drones in the pybullet env with velocity control.

sim_cube.py

Simulates a swarm of drones in a spinning cube.

Hardware Only

fly_single.py

Flies a real Crazyflie, check out the documentation and how to connect to get your URI(s) and modify them in line 18.

fly_swarm.py

Flies a real Crazyflie swarm, same as the previous example, but now takes in a list of URIs.

Simulation or Hardware

sim_n_fly_single.py

Simple script that can be used to fly a single crazyflie in sim or with a real drone using either the --hardware or --simulate args.

sim_n_fly_multiple.py

Simple script that can be used to fly a swarm of crazyflies in sim or with real drones using either the --hardware or --simulate args.

sim_n_fly_cube_from_scratch.py

Simple script that can be used to fly a swarm of crazyflies in sim or with real drones using either the --hardware or --simulate args, and forms the same spinning cube from takeoff as in sim_cube.py.

Project details


Release history Release notifications | RSS feed

This version

0.5.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyFlyt-0.5.1.tar.gz (150.8 kB view details)

Uploaded Source

Built Distribution

PyFlyt-0.5.1-py3-none-any.whl (169.6 kB view details)

Uploaded Python 3

File details

Details for the file PyFlyt-0.5.1.tar.gz.

File metadata

  • Download URL: PyFlyt-0.5.1.tar.gz
  • Upload date:
  • Size: 150.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for PyFlyt-0.5.1.tar.gz
Algorithm Hash digest
SHA256 a4f844bac398f30a920d1c216b18c26bdbbfa00ef2fe9b2416b44fae039446bb
MD5 dfa7b44a160f2a84034692aaa33b974c
BLAKE2b-256 87113e84ea46de2e9538dd181040bf13c6c94366f78f375cac6e8e8cf28949e6

See more details on using hashes here.

File details

Details for the file PyFlyt-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: PyFlyt-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 169.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for PyFlyt-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d4fdbcdd3f13cf5e2ba137effb6f5cb9f097ec10ba26db7d3c600c734d10931
MD5 69058c354a8d5a2265c6fce528b78daf
BLAKE2b-256 65bd564f127fb961a181e83d463076b05f05fa41c2343a84ca7309af5e56c876

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page