alireza787b / px4xplane

Integrating advanced flight simulation with PX4 SITL, this plugin adds support for hybrid VTOLs, fixed-wing, and multirotor aircraft in X-Plane. Perfect for researchers and hobbyists interested in drone and flight dynamics simulation.
31 stars 12 forks source link
drone flight-simulator mavlink px4 xplane xplane12

PX4 X-Plane Plugin

This project establishes a robust connection between X-Plane and PX4 SITL (Software In The Loop) to simulate drone flight in the X-Plane environment. Our goal is to deliver a realistic simulation experience where PX4 can control various drones within X-Plane, and with our continuous improvements, it's getting better all the time.

Latest Release - Version 2.0.0 (August 2024)

PX4 X-Plane Plugin v2.0.0 Demo

Curious about the new features in the PX4 X-Plane Plugin v2.0.0? Check out this demo video where I walk you through the simplified setup process, showcase the multi-airframe support, and test various drones like the Ehang 184, Alia 250, Cessna 172, and Bayraktar TB2. Whether you're a student, researcher, or industry professional, this quick overview will get you up and running in no time!

πŸ‘‰ Watch the full demo and installation guide here!

Untitled (7)

What's New

Check out the new features in the v2.0.0 release. YouTube video tutorial for version 2.0 will be released soon!

Video Tutorials

For setup guidance and demonstrations, visit our YouTube playlist, which includes detailed tutorials and showcases the plugin in action!

PX4 X-Plane Plugin Video Thumbnail

Introduction

We bridge X-Plane and PX4 using the Simulator MAVLink API, which facilitates the exchange of sensor and actuator data, providing a rich and accurate simulation environment.

The following table illustrates the message flow:

Message Direction Description
MAV_MODE:MAV_MODE_FLAG_HIL_ENABLED NA Mode flag when using simulation. All motors/actuators are blocked, but internal software is fully operational.
HIL_ACTUATOR_CONTROLS PX4 to Sim PX4 control outputs (to motors, actuators).
HIL_SENSOR Sim to PX4 Simulated IMU readings in SI units in NED body frame.
HIL_GPS Sim to PX4 The simulated GPS RAW sensor value.
HIL_OPTICAL_FLOW Sim to PX4 Simulated optical flow from a flow sensor (e.g., PX4FLOW or optical mouse sensor).
HIL_STATE_QUATERNION Sim to PX4 Contains the actual "simulated" vehicle position, attitude, speed, etc. This can be logged and compared to PX4's estimates for analysis and debugging.
HIL_RC_INPUTS_RAW Sim to PX4 The RAW values of the RC channels received.

Known Issues

Usage Guide

For full step-by-step instructions, follow the Version 2 Documentation.

Automated Setup Script

This automated script is optimized for using with WSL (Windows Subsystem for Linux), where X-Plane runs on Windows, and PX4 SITL runs on Linux (WSL). It should also work natively on Ubuntu and other Linux distributions.

To quickly set up PX4 with X-Plane using WSL (Ubuntu 22.04), follow this simple step:

  1. Run the setup script directly from your terminal:

    First, make sure you are in your WSL Ubuntu terminal (launch it from PowerShell), then enter the following command in your WSL terminal:

    cd ~ && curl -O https://raw.githubusercontent.com/alireza787b/px4xplane/master/setup/setup_px4_sitl.sh && bash setup_px4_sitl.sh

Important Notes:

  1. Once setup is complete, use the px4xplane command to run the simulation from anywhere in your terminal.

    Uninstall

To remove the global paths and the px4xplane command:

px4xplane --uninstall

Manual Advanced Setup

For advanced users, manually clone and set up the environment using the forked PX4 repository:

  1. Clone the repository:

    git clone https://github.com/alireza787b/PX4-Autopilot-Me.git --recursive
    cd PX4-Autopilot-Me
  2. Set up the environment:

    bash ./Tools/setup/ubuntu.sh
  3. Configure PX4 SITL:

    • In Windows Terminal, check your IP address (e.g., 172.21.144.1):
      ipconfig
    • In the WSL Terminal, inside the PX4-Autopilot directory, set the PX4 simulation hostname with your IP:
      export PX4_SIM_HOSTNAME=172.21.144.1
  4. Build the desired airframes:

    make px4_sitl xplane_ehang184

    Other airframes include:

    • xplane_alia250
    • xplane_cessna172
    • xplane_tb2

Refer to the official PX4 WSL setup documentation for more details, but use the forked repository instead of the official PX4 repo until the changes are merged.

Defining Custom Airframes

If you need to define new airframes for your simulation, follow the detailed guide here:

πŸ‘‰ How to Define Custom Airframes in PX4-XPlane

This guide will walk you through the process of setting up custom configurations, mapping PX4 channels to X-Plane datarefs, and integrating new airframes into your simulations. Whether you're using existing X-Plane models or creating new ones in Plane Maker, this guide has you covered.


Contribution and Support

Feel free to reach out to me in the issue section if you need help. Having experienced contributors is greatly appreciated!

License

This project is licensed under the MIT License. See the LICENSE file for more details.