Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza787b authored Oct 25, 2023
1 parent 257a703 commit 77ef944
Showing 1 changed file with 53 additions and 52 deletions.
105 changes: 53 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,80 @@
# PX4 X-Plane Plugin

This repository contains the source code for a robust, modular, and user-friendly X-Plane plugin designed to enable seamless interaction with PX4 Software In The Loop (SITL). The plugin facilitates Software-In-The-Loop (SITL) simulation for drone software development and testing.
This project establishes a connection between X-Plane and PX4 SITL (Software In The Loop) to simulate drone flight in the X-Plane environment. The goal is to provide a realistic simulation environment where PX4 can control a drone in the X-Plane simulator.

## Introduction

The PX4 X-Plane plugin communicates with PX4 using the Simulator MAVLink API. This API defines a set of MAVLink messages that supply sensor data from the simulated world to PX4 and return motor and actuator values from the flight code that will be applied to the simulated vehicle. The plugin communicates with PX4 over TCP connections. The simulator's local TCP Port, 4560, is used for communication with PX4. The simulator listens to this port, and PX4 initiates a TCP connection to it.
All simulators, with the exception of Gazebo, communicate with PX4 using the Simulator MAVLink API. This API defines a set of MAVLink messages that provide sensor data from the simulated environment to PX4 and return motor and actuator values from the flight code that will be applied to the simulated vehicle.

The following MAVLink messages are used in the communication between the plugin and PX4:
![PX4 Simulator Messages](https://docs.px4.io/main/assets/img/px4_simulator_messages.f1161233.svg)

- **HIL_ACTUATOR_CONTROLS:** Sent from PX4 to the simulator. It contains PX4 control outputs (to motors, actuators).
- **HIL_SENSOR:** Sent from the simulator to PX4. It contains simulated IMU readings in SI units in NED body frame.
- **HIL_GPS:** Sent from the simulator to PX4. It contains the simulated GPS RAW sensor value.
- **HIL_OPTICAL_FLOW:** Sent from the simulator to PX4. It contains simulated optical flow from a flow sensor (e.g. PX4FLOW or optical mouse sensor).
- **HIL_STATE_QUATERNION:** Sent from the simulator to PX4. It contains the actual "simulated" vehicle position, attitude, speed etc. This can be logged and compared to PX4's estimates for analysis and debugging (for example, checking how well an estimator works for noisy (simulated) sensor inputs).
- **HIL_RC_INPUTS_RAW:** Sent from the simulator to PX4. It contains the RAW values of the RC channels received.
The following table illustrates the message flow:

For more information about the Simulator MAVLink API, refer to the [PX4 Developer Guide](https://docs.px4.io/main/en/simulation/).
| Message | Direction | Description |
|---------|-----------|-------------|
| [MAV_MODE:MAV_MODE_FLAG_HIL_ENABLED](https://mavlink.io/en/messages/common.html#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](https://mavlink.io/en/messages/common.html#HIL_ACTUATOR_CONTROLS) | PX4 to Sim | PX4 control outputs (to motors, actuators). |
| [HIL_SENSOR](https://mavlink.io/en/messages/common.html#HIL_SENSOR) | Sim to PX4 | Simulated IMU readings in SI units in NED body frame. |
| [HIL_GPS](https://mavlink.io/en/messages/common.html#HIL_GPS) | Sim to PX4 | The simulated GPS RAW sensor value. |
| [HIL_OPTICAL_FLOW](https://mavlink.io/en/messages/common.html#HIL_OPTICAL_FLOW) | Sim to PX4 | Simulated optical flow from a flow sensor (e.g. PX4FLOW or optical mouse sensor). |
| [HIL_STATE_QUATERNION](https://mavlink.io/en/messages/common.html#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](https://mavlink.io/en/messages/common.html#HIL_RC_INPUTS_RAW) | Sim to PX4 | The RAW values of the RC channels received. |

## Current Progress
## Features

The project is currently in the development phase with the following components implemented:
- **Xplane-PX4 SITL TCP Connection**: Establishes a TCP connection between X-Plane and PX4 SITL.
- **MAVLink Message Integration**: MAVLink messages such as HIL_SENSOR, HIL_GPS, and HIL_STATE_QUATERNION are used to communicate between the simulator and PX4.
- **Flight Modes**: Currently, you can fly a drone in Acro mode as angular rates are functional.

- **Plugin Structure:** Basic scaffolding has been established, inclusive of menu creation, a settings window, and fundamental rendering capabilities.
- **Data Management:** A `DataRefManager` class has been developed to manage X-Plane sensor data references.
- **Plugin Display:** The plugin can display sensor data within a dedicated window on startup, leveraging data obtained via the `DataRefManager`.
- **Configuration Management:** A configuration reader is implemented to read settings such as the SITL IP from a configuration file.
## Known Issues

## Future Work
- **Magnetic Field Modeling**: X-Plane doesn't model the magnetic field. Currently, it's hardcoded for Tehran City, but this needs a more generic solution.
- **Attitude Estimation**: There seems to be a discrepancy in the acceleration and magnetic field coordinate system of X-Plane compared to expectations (Body coordinate system). The potential problem lies in the coordinate transformation and definition mismatch between X-Plane and PX4.
- **Plugin Responsiveness**: Occasionally, the plugin may cause the plane to become unresponsive when attempting to exit.
- **Performance**: It's crucial to run X-Plane at a high FPS since the PX4 EKF requires fast updating of sensor data.

The following components are yet to be implemented:
## Setup and Testing

- **Connection Management:** The `ConnectionManager` class will handle the establishment, maintenance, and teardown of TCP connections with PX4 SITL.
- **MAVLink Integration:** A component will be developed to package and parse MAVLink messages, ensuring accurate and efficient communication between the plugin and PX4 SITL.
- **X-Plane Data Handling:** Functionality will be implemented to obtain, process, and convert X-Plane data references into appropriate MAVLink message formats.
- **Control Overrides:** Mechanisms will be developed to override X-Plane's autopilot settings and control surfaces based on received MAVLink messages while maintaining the ability to revert to default settings upon disconnection.
- **Enhanced Sensor Integration:** The integration will be extended to include additional sensors like barometer, airspeed, and RPM, among others.
1. **Plugin Installation**:
- Install the plugin to your plugins folder for the specific drone.

## Approach
2. **PX4 SITL Setup**:
- Clone and build `px4_sitl`. Follow the instructions provided by [PX4](https://docs.px4.io/main/en/simulation/).
- If cloning on WSL (or another system), change the hostname IP from `localhost` to where X-Plane is running:
```bash
export PX4_SIM_HOSTNAME=XPLANE_SYSTEM_IP
```
For example, if using WSL on Windows:
```bash
export PX4_SIM_HOSTNAME=172.21.160.1
```

The project follows a modular approach with each component (e.g., Connection Manager, DataRef Manager) developed as a separate, self-contained entity ensuring high cohesion and low coupling. The codebase maintains a high standard of readability, with clear naming conventions, structured formatting, and comprehensive documentation. Each component and functionality is developed and tested in isolation before integration, facilitating easier debugging and validation. The architecture is designed to accommodate future enhancements and integrations effortlessly, such as support for additional sensors and communication protocols.
3. **Running PX4 SITL**:
- Run the default `iris` (or your custom airframe) with `none_` to indicate that you'll connect your own simulator:
```bash
make px4_sitl none_iris
```
## Immediate Next Steps
4. **X-Plane Connection**:
- Launch X-Plane and load your drone.
- Navigate to `plugin -> px4xplane -> click on connect to SITL`. The simulator should now be connected.
- Under `plugin -> px4xplane -> Show Settings`, you can view live data and status.
1. Implement and test the `ConnectionManager` class.
2. Develop MAVLink message handling functionalities.
3. Implement and validate data conversion and processing functionalities for transforming X-Plane data into MAVLink messages.
4. Establish the end-to-end communication flow between the plugin and PX4 SITL.
5. **Firewall Configuration**:
- Ensure that port `4560 TCP` is not blocked by your firewall on both systems. If running on the same system, this is typically not an issue.
## Long-Term Goals
6. **QGroundControl (QGC) Connection**:
- If running on the same system, QGC should auto-connect to the drone on X-Plane.
- For WSL or another system, open QGroundControl, navigate to `Application Settings -> Comm Links`, and add a new connection to UDP port `18570`. Click `connect`, and it should work.
1. Explore the integration of UDP for enhanced performance and reliability.
2. Implement radio control overrides and investigate the integration of vision sensors.
3. Enable multi-drone simulation capabilities within the plugin.
4. Establish thorough validation mechanisms for sensor data and connectivity and ensure graceful connection handling during runtime.
## Status
## Repository Structure
This project is currently under development. Once a fully functional initial version is ready, the first beta release will be made available.
The repository contains the following key files and directories:
## Contribution and Support
- `ConnectionManager.cpp`, `ConnectionManager.h`: These files are for the ConnectionManager class, which will handle TCP connections with PX4 SITL.
- `DataRefManager.cpp`, `DataRefManager.h`: These files contain the DataRefManager class, which manages X-Plane sensor data references.
- `configReader.cpp`, `configReader.h`: These files contain the ConfigReader class, which reads settings such as the SITL IP from a configuration file.
- `px4xplane.cpp`: This is the main file for the plugin.
- `px4-xplane.sln`, `Hello-World-SDK-3.vcxproj`: These are the project files for Visual Studio.
- `SDK`: This directory contains additional code and resources related to the PX4 X-Plane plugin.
Feel free to contact in the issue section if you need help. Having experienced contributors is greatly appreciated!
## Getting Started

To get started with the project, clone the repository and open the solution file (`px4-xplane.sln`) in Visual Studio. Make sure you have the X-Plane SDK installed and configured correctly. For more information on how to do this, refer to the [X-Plane SDK Documentation](https://developer.x-plane.com/sdk/plugin-sdk-documents/).

To build the project, use the command `make px4_sitl none_iris`.

## Contributing

Contributions are welcome! Please read our contributing guidelines and code of conduct before making a pull request.
## License
Expand Down

0 comments on commit 77ef944

Please sign in to comment.