RotorPy Multirotor Simulator

repository·main·Indexed 43 days ago

https://github.com/spencerfolk/rotorpy

A Python-based multirotor simulation environment for UAV estimation, planning, and control research. Version 3.0.0 features realistic aerodynamic wrenches, high-speed batched simulations for CPU/GPU, and Gymnasium-compatible reinforcement learning environments via QuadrotorEnv. The toolkit includes modules for vehicle dynamics, sensors (IMU, motion capture, camera), controllers, trajectories, wind profiles, and state estimators such as EKF and UKF.

Tokens
12.1K
Snippets
28
Records
52
Agent score
56%

What's inside RotorPy

  1. Overview of RotorPy modules

    main

    RotorPy is a dynamics simulator for aerial robotics planning and control. The simulation is composed of several specialized modules that interact to model a complete robotic system:

    • Vehicles: Continuous-time dynamics for UAVs.
    • Sensors: Transforms ground truth state into noisy/biased measurements (e.g., IMU, motion capture) and includes a pinhole camera for visual feature rendering.
    • Worlds: Uses json map files to define world bounds, obstacles, and visual features.
    • Controllers: Logic to stabilize the vehicle to a specific trajectory.
    • Trajectories: Defines the desired motion of the vehicle over time.
    • Wind: Adds external disturbances via spatial or temporal vector fields.
    • Estimators: Filters or estimates states/parameters using sensor measurements and dynamics models.
  2. Available wind models in RotorPy

    main

    RotorPy provides several pre-implemented wind modules for different simulation scenarios:

    • Common Gust Models (default_winds.py): Includes sinusoid wind signals, constant wind, and discrete step changes.
    • Static Spatial Wind Fields (spatial_winds.py): Allows for creating static spatial wind fields, such as a steady-state wind tunnel column.
    • Stochastic Turbulence (dryden_winds.py): Implements the Dryden Wind Turbulence Model to produce stochastic wind patterns (utilizing code from the wind-dynamics repository).
  3. Generate trajectories for multirotor motion

    main

    Trajectories in RotorPy define the desired motion of a multirotor over time. There are two primary approaches to trajectory generation available in the module:

    1. Waypoint-based: Uses minsnap.py to generate trajectories based on specific waypoints (implementing Minimum Snap Trajectory Generation).
    2. Time-parameterized shapes: Uses predefined mathematical shapes parameterized by time.

    Currently, the implemented trajectories output flat outputs (position and yaw) to ensure compatibility with the SE3 controller. While you can develop custom trajectories for different controller hierarchies, they must follow the expected structure to work with the simulation environment.

  4. Implement a custom vehicle class

    main

    To use a custom vehicle within RotorPy, your class must implement a step method to handle dynamics integration. While you can use any integration method, scipy.integrate.solve_ivp is a recommended starting point.

    If you intend to use an IMU sensor with your vehicle, you must also implement a statedot method. This method should output the acceleration and angular body rates of the rigid body at the center of mass.

  5. Use QuadrotorEnv for Reinforcement Learning

    main

    For reinforcement learning tasks, RotorPy provides QuadrotorEnv in the rotorpy.learning module. This is a custom Gymnasium environment designed to be a stripped-down version of the standard simulation.

    Features:

    • Includes full aerodynamics and motor dynamics.
    • Supports various control abstractions (from high-level velocity vectors to direct motor speed commands).
    • Allows users to specify custom reward functions.

    See rotorpy/examples/gymnasium_basic_usage.py for a starting point.

  6. How wind models work in RotorPy

    main

    In RotorPy, winds are implemented as independent objects. To compute a wind vector, these objects require two inputs: the current time and the vehicle's location.

    Wind models can be designed to be:

    • Spatially varying: The wind vector changes based on the vehicle's position.
    • Temporally varying: The wind vector changes over time.
    • Both: The wind vector changes based on both position and time.
  7. How the Estimator Module works

    main

    Estimators in rotorpy combine sensor measurements with an internal dynamics model to provide filtered estimates of states or quantities of interest.

    Currently, the module provides two implementations for estimating the local wind vector acting on a vehicle's center of mass using IMU and external motion capture data:

    1. A hand-implemented Extended Kalman Filter (EKF).
    2. An Unscented Kalman Filter (UKF) that leverages the FilterPy library.

    Model Details

    The provided estimators use a simplified dynamics model with the following characteristics:

    • Filter States: The state vector $\boldsymbol{x}_{filter}$ includes ZYX Euler angles $[\psi, \theta, \phi]$, translational velocities in the body frame $[v_x, v_y, v_z]$, and wind components in the body frame $[w_x, w_y, w_z]$.
    • Approximations: Small angle approximations near hover are used to simplify the process model.
    • Drag Model: The model assumes parasitic (quadratic) drag with airspeed and neglects rotor drag. Drag coefficients can be identified using flight data collected in the absence of wind.
    • Inputs: The process model accepts commanded thrust ($f_c$) and body rates ($\Omega$) from external motion capture.
    • Measurements: The filters consume noisy acceleration measurements from the IMU and attitude/body velocity measurements from external motion capture sensors.
  8. Use batched simulations for parallel execution

    main

    RotorPy supports batched environments that allow simulating multiple drones in parallel on the CPU or GPU. This is highly efficient for generating large datasets for deep learning or Monte Carlo studies. For simulations involving more than 1000 drones, CPU-based batching can provide up to 25x speedup compared to sequential simulation.

    To use this feature, ensure you have installed the [batched] extra and refer to examples/batched_simulation.py for implementation details.

  9. Use the Multirotor vehicle model

    main

    The Multirotor class is the primary implemented vehicle in RotorPy. It is highly flexible and supports:

    • Arbitrary numbers of rotors with arbitrary orientations relative to the body frame.
    • Aerodynamic effects (Parasitic Drag, Rotor Drag, Blade Flapping, Induced Drag, Translational Lift, and Translational Drag).
    • First-order motor dynamics to simulate delay and lag.
    • Built-in support for parameter files, plotting, and animation utilities.
  10. How to run and manage a RotorPy simulation

    main

    To execute a simulation, you interact with two primary components:

    1. environment.py: Use this module for high-level orchestration. It contains functions for instantiating the simulation, executing it, and plotting or saving the results.
    2. simulate.py: This is the core engine that steps the vehicle forward in time. It manages the integration of dynamics, trajectory following, controller execution, and sensor measurement updates.

    The output of a simulation is a dictionary containing the relevant state, input, and measurements indexed by time.

  11. Configure an external motion capture sensor

    main
    The external motion capture sensor (found in external_mocap.py) provides noisy measurements of pose and twist. It is automatically placed at the center of mass and aligned with the body axes. It includes an "artifacts" parameter to simulate spikes caused by numerical differentiation or system glitches.