gym-pybullet-drones

learnsyslabMIT活跃维护

基于 PyBullet 物理引擎的四旋翼控制强化学习环境,支持单智能体和多智能体训练,可对接 Crazyflie 等真实无人机。

PyBullet Gymnasium environments for single and multi-agent reinforcement learning of quadcopter control

v1.0.0发布于 2021-03-09 21:11 UTC2,204star +2 / 7 天577fork同步于 2026-11-10 17:46 UTC

怎么上手

由 README 提炼,执行前请确认
git clone https://github.com/learnsyslab/gym-pybullet-drones.git
cd gym-pybullet-drones/
conda create -n drones python=3.12
conda activate drones
pip3 install -e .
硬件要求按 README 说明

README 未说明显存或 GPU 要求;测试环境为 Intel x64/Ubuntu 24.04 与 Apple Silicon/macOS 26,物理仿真由 PyBullet 承担

支持 Apple Silicon
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

基于 PyBullet 的四旋翼强化学习仿真环境,支持单机与多机控制训练

基于 PyBullet 物理引擎的四旋翼控制强化学习环境,支持单智能体和多智能体训练,可对接 Crazyflie 等真实无人机。

核心能力

  • 提供兼容 Gymnasium 接口的四旋翼飞行环境
  • 内置 PID、MRAC 等控制示例与下洗气流示例
  • 用 SB3 的 PPO 跑单机与多机悬停训练
  • 通过 PettingZooWrapper 接入 PettingZoo 并行 API
  • 支持 Betaflight SITL 软件在环仿真

容易踩的坑

Python 3.10 以上 pybullet 没有预编译 wheel,Ubuntu 需先装 build-essential 自行编译,macOS 需用 CFLAGS="-Dfdopen=fdopen" pip install pybullet --no-cache-dir 安装;Betaflight SITL 示例仅支持 Ubuntu,且需先用 clone_bfs.sh 按无人机数量构建可执行文件,--num_drones 不能超过该数量;多机 RL 需显式加 --multiagent true,play.py 也要带同样参数才能加载对应模型

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v1.0.0
  1. v1.0.0最新正式版2021-03-09 · 2021-03-09 21:11 UTC

    这个版本没有写更新说明。

  2. v0.5.2pre-release2020-11-25 · 2020-11-25 23:51 UTC

    这个版本没有写更新说明。

  3. v0.5.1pre-release2020-11-18 · 2020-11-18 21:53 UTC

    这个版本没有写更新说明。

  4. v0.5.0pre-release2020-11-05 · 2020-11-05 05:21 UTC

    这个版本没有写更新说明。

  5. v0.3.0pre-release2020-09-12 · 2020-09-12 14:25 UTC

    这个版本没有写更新说明。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    [!TIP] For research work with symbolic dynamics and constraints, also try safe-control-gym

    For GPU-accelerated, differentiable, JAX-based simulation, also try crazyflow

    For real-world deployment of PX4/ArduPilot + ROS2 + JetPack, use aerial-autonomy-stack

    gym-pybullet-drones

    This is a minimalist refactoring of the original gym-pybullet-drones repository, designed for compatibility with gymnasium, stable-baselines3 2.0, and betaflight SITL.

    NEWS: gym-pybullet-drones was featured in GitHub's Maintainer Spotlight 2026

    NOTE: if you want to access the original IROS 2021 codebase, please git checkout [paper|master]

    Installation

    Tested on Intel x64/Ubuntu 24.04 and Apple Silicon/macOS 26.

    git clone https://github.com/learnsyslab/gym-pybullet-drones.git
    cd gym-pybullet-drones/
    
    conda create -n drones python=3.12
    conda activate drones
    
    # Beyond Python 3.10, `pybullet` has no pre-built wheel
    # On Ubuntu, install `gcc` to let `pip3 install` build `pybullet`
    sudo apt install build-essential
    # On macOS, build and install `pybullet` with
    CFLAGS="-Dfdopen=fdopen" pip install pybullet --no-cache-dir
    
    pip3 install -e .
    
    # check installed packages with `conda list`, deactivate with `conda deactivate`, remove with `conda remove -n drones --all`
    

    Use

    Control examples

    cd gym_pybullet_drones/examples/
    python3 pid.py
    python3 pid_velocity.py
    python3 mrac.py
    

    Downwash effect example

    cd gym_pybullet_drones/examples/
    python3 downwash.py
    

    Reinforcement learning examples (SB3's PPO)

    cd gym_pybullet_drones/examples/
    
    # single agent, task: single drone hover at z == 1.0
    python learn.py
    LATEST_MODEL=$(ls -t results | head -n 1) && python play.py --model_path "results/${LATEST_MODEL}/best_model.zip"
    
    # multi-agent, task: 2-drone hover at z == 1.2 and 0.7
    python learn.py --multiagent true
    LATEST_MODEL=$(ls -t results | head -n 1) && python play.py --multiagent true --model_path "results/${LATEST_MODEL}/best_model.zip"
    

    Multi-agent RL with PettingZoo

    PettingZooWrapper exposes any multi-drone aviary through PettingZoo's Parallel API, with one agent per drone (drone_0, drone_1, ...). That makes it usable with MARL libraries built on PettingZoo.

    from gym_pybullet_drones.envs.MultiHoverAviary import MultiHoverAviary
    from gym_pybullet_drones.utils.PettingZooWrapper import PettingZooWrapper
    
    env = PettingZooWrapper(MultiHoverAviary(num_drones=3))
    observations, infos = env.reset(seed=42)
    while env.agents:
        actions = {agent: env.action_space(agent).sample() for agent in env.agents}
        observations, rewards, terminations, truncations, infos = env.step(actions)
    env.close()
    

    Each agent receives its own row of the aviary's observation. The aviary's team reward and episode flags are shared by all agents, and env.state() returns every drone's kinematics for centralised critics.

    cd gym_pybullet_drones/examples/
    
    # MWE based on `learn.py --multiagent true`
    python pettingzoo_multiagent.py
    

    Betaflight SITL example (Ubuntu only)

    # one-time setup: from the repo's top folder, build one SITL executable per drone (e.g. 2), if needed, `apt install curl`
    cd gym-pybullet-drones/
    ./gym_pybullet_drones/assets/clone_bfs.sh 2
    
    # run the example
    cd gym_pybullet_drones/examples/
    python3 beta.py --num_drones 2
    # --num_drones must be <= the number passed to clone_bfs.sh
    

    Run all tests

    # from the repo's top folder
    cd gym-pybullet-drones/
    pytest tests/
    

    Citation

    If you wish, please cite our IROS 2021 paper (and original codebase) as

    @INPROCEEDINGS{panerati2021learning,
          title={Learning to Fly---a Gym Environment with PyBullet Physics for Reinforcement Learning of Multi-agent Quadcopter Control}, 
          author={Jacopo Panerati and Hehui Zheng and SiQi Zhou and James Xu and Amanda Prorok and Angela P. Schoellig},
          booktitle={2021 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS)},
          year={2021},
          volume={},
          number={},
          pages={7512-7519},
          doi={10.1109/IROS51168.2021.9635857}
    }
    

    References


    UTIAS / Learning Systems and Robotics Lab / Vector Institute / University of Cambridge's Prorok Lab