Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza787b committed Sep 29, 2024
2 parents 13631d5 + 0ae1db2 commit 0c485d3
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 3 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ This project establishes a robust connection between X-Plane and PX4 SITL (Softw

## Latest Release - Version 2.0.0 (August 2024)

[![PX4 X-Plane Plugin v2.0.0 Demo](https://github.com/user-attachments/assets/3fb6d042-20d9-4589-8a79-44f434d5870d)](https://youtu.be/oQTlBVXqR04)

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!](https://youtu.be/oQTlBVXqR04)

![Untitled (7)](https://github.com/user-attachments/assets/3fb6d042-20d9-4589-8a79-44f434d5870d)

### What's New
- **Sensor Improvements**: Fixed many sensor problems and inconsistencies.
- **Multi-Airframe Support**: Native support for multiple airframes including:
Expand Down Expand Up @@ -116,7 +124,15 @@ For advanced users, manually clone and set up the environment using the forked P

Refer to the [official PX4 WSL setup documentation](https://docs.px4.io/main/en/simulation/) 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](https://github.com/alireza787b/px4xplane/blob/master/docs/custom-airframe-config.md)

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
Expand Down
112 changes: 112 additions & 0 deletions docs/custom-airframe-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Defining Custom Airframes in PX4-XPlane

This guide walks you through defining custom airframe configurations in PX4-XPlane using the `config.ini` file. We’ll cover key concepts, provide detailed examples, and guide you through the entire process—from configuring the file to testing your setup in X-Plane.

## Overview

To define a custom airframe configuration, follow these steps:
1. **Select or Build a Plane Model**: Choose an existing X-Plane model or create one from scratch using X-Plane’s Plane Maker.
2. **Select a Similar Airframe in PX4 or Start from Scratch**: Choose a pre-existing PX4 airframe that closely matches your custom setup, or define a new one from scratch. You can double-check channel numbers, servos, and functionalities in the dynamic mixing section of QGroundControl’s Actuator section under SITL.
3. **Configure the `config.ini` File**: Map PX4 channels to X-Plane datarefs.
4. **Understand Datarefs and Their Types**: Learn how to select and configure datarefs.
5. **Build and Test the Configuration**: Test your configuration in X-Plane and PX4.

## Step 1: Select or Build a Plane Model

### Using Existing Models

- **Pre-existing Models**: Use existing X-Plane models that closely match your custom airframe.
- **Modify Models**: Modify an existing X-Plane model to fit your requirements.

### Creating a New Model

- **Use Plane Maker**: Create a new aircraft using X-Plane’s Plane Maker tool if no existing model fits your needs.

## Step 2: Select a Similar Airframe in PX4 or Start from Scratch

### Using Pre-existing Airframes in PX4

- **Choose a Similar Airframe**: If your custom airframe is similar to an existing setup, use that as a starting point (e.g., `xplane_alia250`).
- **Dynamic Mixing in QGroundControl**: Verify and adjust channel mappings in the dynamic mixing section of the Actuator settings in QGroundControl’s SITL section.

### Starting from Scratch

- **Define in PX4 Source Code**: For complex airframes, you may prefer to define the aircraft directly in the PX4 source code and compile it.
- **Dynamic Mixing in QGroundControl**: Verify and adjust channel mappings in the dynamic mixing section of the Actuator settings in QGroundControl’s SITL section.

## Step 3: Configuring the `config.ini` File

The `config.ini` file defines how PX4’s outputs (e.g., motors, control surfaces) map to X-Plane’s inputs.

### Example Configuration for Alia 250 eVTOL

```ini
; PX4-XPlane Configuration File
; File Version: 1.3
; Last Updated: December 26, 2023
; This file configures the mapping of motor and servo channels from PX4 to X-Plane.

; Configuration Name (Displayed in UI)
config_name = Alia250

[Alia250]

; Auto-Prop Brakes: Specifies which motors have an auto-prop brake system.
; Format: Comma-separated list of motor indices in X-Plane.
autoPropBrakes = 0, 1, 2, 3

; Quadcopter Motors (1-4)
channel0 = sim/flightmodel/engine/ENGN_thro_use, floatArray, [0], [-1 1]
channel1 = sim/flightmodel/engine/ENGN_thro_use, floatArray, [1], [-1 1]
channel2 = sim/flightmodel/engine/ENGN_thro_use, floatArray, [2], [-1 1]
channel3 = sim/flightmodel/engine/ENGN_thro_use, floatArray, [3], [-1 1]

; Fixed-Wing Control Surfaces (Ailerons, Elevator, Rudder)
channel4 = sim/flightmodel/controls/wing2l_ail1def, float, 0, [-20 10] | sim/flightmodel/controls/wing2l_ail2def, float, 0, [-20 10] | sim/flightmodel/controls/wing3l_ail2def, float, 0, [-20 10]
channel5 = sim/flightmodel/controls/wing2r_ail1def, float, 0, [-20 10] | sim/flightmodel/controls/wing2r_ail2def, float, 0, [-20 10] | sim/flightmodel/controls/wing3r_ail2def, float, 0, [-20 10]
channel6 = sim/flightmodel/controls/hstab1_elv1def, float, 0, [-15 20] | sim/flightmodel/controls/hstab1_elv2def, float, 0, [-15 20]
channel7 = sim/flightmodel/controls/vstab1_rud1def, float, 0, [-15 20] | sim/flightmodel/controls/vstab2_rud2def, float, 0, [-15 20]

; Additional Forward Thrust Motor
channel8 = sim/flightmodel/engine/ENGN_thro_use, floatArray, [4], [-1 1]
```

### Key Sections Explained

- **Configuration Name**: Displayed in the PX4-XPlane UI; this helps you identify the active configuration.
- **Auto-Prop Brakes**: Reduces drag by braking the propellers when they’re not needed, useful for eVTOL configurations.
- **Channel Mappings**: Defines how each PX4 channel maps to X-Plane’s datarefs. Each channel can control a motor, control surface, or other aircraft function.

## Step 4: Understanding Datarefs and Their Types

### Dataref Types

- **`float`**: Single floating-point value, typically used for control surfaces like ailerons or rudders.
- **`floatArray`**: An array of floating-point values, often used for multi-engine aircraft or multiple control surfaces.
- **`int`**: Integer values, typically used for binary states such as landing gear.
- **`intArray`**: An array of integers, similar to `floatArray` but used for integer data.

### Selecting Datarefs

Choosing the correct dataref ensures accurate simulation behavior:
- **Throttle and Motors**: Use `sim/flightmodel/engine/ENGN_thro_use` with `floatArray`.
- **Control Surfaces**: For ailerons, elevators, and rudders, use datarefs like `sim/flightmodel/controls/wing2l_ail1def` with `float`.
- **Auto-Prop Brakes**: Define motor indices that should have auto-prop brakes to minimize drag during flight.

Use the Dataref Tool plugin in X-Plane to find the correct dataref for your setup, or refer to the [X-Plane Dataref Documentation](https://developer.x-plane.com/datarefs/) for more details.

## Step 5: Building and Testing the Configuration

### Testing

1. **Load and Test in PX4-XPlane**: Load the configuration in X-Plane and test the controls.
2. **Adjust as Needed**: Modify the `config.ini` file or PX4 parameters to fine-tune control and simulation accuracy.

### Final Notes: Custom Airframe Setup in PX4

Remember, the channel numbers should be defined in the SITL Actuator section of QGroundControl. You can either:
- **Use Dynamic Mixing**: Adjust actuator outputs directly within QGroundControl for flexibility.
- **Define in Source Code**: For more complex setups, define the airframe in the PX4 source code, build it, and then test.

By following these steps, you’ll ensure your custom airframe behaves correctly in both PX4 and X-Plane, allowing for realistic and accurate simulations.

31 changes: 28 additions & 3 deletions docs/v2.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# PX4 with X-Plane and QGroundControl Setup Guide (v2.0.0, August 2024)
# PX4 with X-Plane and QGroundControl Setup Guide (v2.0.2, August 2024)
## Watch the PX4 X-Plane Plugin v2.0.0 Demo

[![PX4 X-Plane Plugin v2.0.0 Demo](https://github.com/user-attachments/assets/3fb6d042-20d9-4589-8a79-44f434d5870d)](https://youtu.be/oQTlBVXqR04)

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!](https://youtu.be/oQTlBVXqR04)

![YouTube Video Coming Soon](https://via.placeholder.com/900x500.png?text=YouTube+Video+Coming+Soon)

Watch full setup guide and demonstration on YouTube: [PX4 X-Plane Plugin Tutorial](https://www.youtube.com/watch?v=aRJxsnf24k4).

## Table of Contents

- [Download and Install Softwares](#download-and-install-softwares)
- [Setting Up the Environment](#setting-up-the-environment)
- [Clone and Build PX4](#clone-and-build-px4)
- [Configuration](#configuration)
- [Defining Custom Airframes](#defining-custom-airframes)
- [Additional Tips](#additional-tips)

---
Expand Down Expand Up @@ -88,6 +94,16 @@ Run the setup script:
bash ./Tools/setup/ubuntu.sh
```

Configure PX4 SITL:
- In Windows Terminal, check your IP address (e.g., `172.21.144.1`):
```bash
ipconfig
```
- In the WSL Terminal, inside the PX4-Autopilot directory, set the PX4 simulation hostname with your IP:
```bash
export PX4_SIM_HOSTNAME=172.21.144.1
```

Follow the regular PX4 WSL setup instructions, replacing the official repository with the forked one. Once set up, you can build the desired airframes with commands like:

```bash
Expand Down Expand Up @@ -116,6 +132,15 @@ px4xplane

The selected airframe will automatically load in X-Plane, and you can manage the configuration through the PX4 SITL menus directly. Manual parameter loading is no longer required for the supported airframes.

---
## 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](https://github.com/alireza787b/px4xplane/blob/master/docs/custom-airframe-config.md)

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.
---
## Additional Tips
Expand Down

0 comments on commit 0c485d3

Please sign in to comment.