Skip to main content

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

Project description

PyFlyt - Freestyle Quadcopter Flight in Pybullet with Gymnasium and (soon) PettingZoo APIs

This is a library for running reinforcement learning algorithms on both real crazyflies and simulated ones using the Gymnasium and (soon) PettingZoo APIs. This repo's master branch is still under development.

Inspired by the original pybullet drones by University of Toronto's Dynamic Systems Lab with several key differences:

  • Actual full cascaded PID flight controller implementations for each drone.
  • Actual motor RPM simulation using first order differential equation.
  • More modular control structure
  • For developers - 8 implemented flight modes that use tuned cascaded PID flight controllers, available in PyFlyt/core/drone.py.
  • For developers - easily build your own multiagent environments using the PyFlyt.core.aviary.Aviary class.
  • More environments with increasing difficulties, targetted at enabling hiearchical learning for as true-to-realistic freestyle quadcopter flight.

Table of Contents

Installation

pip3 install wheel
pip3 install pyflyt

Usage

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

import gymnasium
import PyFlyt

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

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

done = False
while not done:
    observation, reward, done, _ = env.step(env.observation_space.sample())

Observation Space

All observation spaces use gymnasium.spaces.Box. For Simple environments, the observation spaces are simple 1D vectors of length less than 25, all values are not normalized. For Advanced environments, the observation spaces use gymnasium.spaces.Dict with an image and state component.

Action Space

All environments use the same action space, this is to allow hiearchical learning to take place - an RL agent can learn to hover before learning to move around.

By default, all environments have an action space that corresponds to FPV controls - pitch angular rate, roll angular rate, yaw_angular rate, thrust. The limits for angular rate are +-3 rad/s. The limits for thrust commands are -1 to 1.

The angular rates are intentionally not normalized to allow for a) better interpretation and b) more realistic inputs.

Environments

PyFlyt/SimpleHoverEnv-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.

PyFlyt/SimpleWaypointEnv-v0

A simple environment where the goal is to position the Quadcopter at random setpoints in space within the permitted flight dome. The environment ends when either the Quadcopter collides with the ground or exits the permitted flight dome.

MORE ARE ON THE WAY

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 template scripts in examples/ that you can run with python3 examples/***.py in macOS and Linux. 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

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.3.0.tar.gz (141.8 kB view details)

Uploaded Source

Built Distribution

PyFlyt-0.3.0-py3-none-any.whl (157.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: PyFlyt-0.3.0.tar.gz
  • Upload date:
  • Size: 141.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.3.0.tar.gz
Algorithm Hash digest
SHA256 11e4c08c12fc43fb181db8471011963417b509326a285e062dbc1549d39c30e2
MD5 d0ccc25dea390076731f5b837597ae5e
BLAKE2b-256 3247b24ee53b0ab49444a048e3a8d30c767ba0e76281d93d5cdabe6eee103b5f

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: PyFlyt-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 157.1 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df16c38bebf37eb72262264b5e40ade63c5a84c04edb8073582a4df3768b3d09
MD5 c49518fd76c9012f5a1c8127440095fb
BLAKE2b-256 92502c6e73b846a204941475784c5685663a721bebfcad7c70405e9c60e89323

See more details on using hashes here.

Provenance

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