Hardware-in-the-loop plugin for X-Plane 11 & 12 for INAV Flight Controller firmware:
Hardware-in-the-loop (HITL) simulation, is a technique that is used in the development and testing of complex real-time embedded systems.
X-Plane is a flight simulation engine series developed and published by Laminar Research https://www.x-plane.com/
INAV-X-Plane-HITL is plugin for X-Plane for testing and developing INAV flight controller firmware https://github.com/iNavFlight/inav.
I believe that good testing and debugging tools are key points to achieve software stability.
It is not Ok when people debug autopilot by running with RC Plane on the field ๐
I hope this plugin can help to improve INAV firmware.
While not been a main purpose, plugin can be used to improve pilot skils or getting familiar with INAV settings.
X-Plane https://www.x-plane.com/ is flight simulator with accurate physics simulation.
X-Plane is extendable with plugins. This plugin connects to Flight Controller through USB cable and passes gyroscope, accelerometer, barometer, magnethometer, GPS and Pitot tube data from X-Plane, which replace data from physical sensors.
FC sends back yaw/pitch/roll controls which are passed to X-Plane.
Simulation requires at least 50, or even better 100, solid FPS without freezing. While X-Plane 12 has better visual appearance, X-Plane 11 is still recommented choice due to better performance. Also INAV Surfwing flying characteristic seems to be worse in X-Plane 12.
Plugin is Aircraft plugin.
The contents of release\Aircraft
folder should be placed in the Aircraft folder of X-Plane: X-Plane11\Aircraft\
.
This action will add INAV Surfwing flying wing model with this plugin.
IMPORTANT:: You have to flash Simulator-enabled INAV firmware. Take precompiled binaries from release https://github.com/RomanLut/INAV-X-Plane-HITL/releases/ (INAV 5.0.0 with simulator support), or build yourself from branch: https://github.com/RomanLut/inav/tree/simulator_v1.0 (INAV 5.0.0 with simulator support), or build yourself from master branch of official INAV repository . Official INAV firmware releases do not include simulator support currently. It will be included in INAV 6.
- Install X-Plane 11 demo from: https://www.x-plane.com/desktop/try-it/older/ . Demo allows to fly for 15 minutes in Seattle region. Than you have to restart the game.
- download Aircraft.zip from last release https://github.com/RomanLut/INAV-X-Plane-HITL/releases/
- If upgrading from previous version, delete folder
X-Plane 11\Aircraft\Extra Aircraft\NK_FPVSurfwing\
- Unzip, copy
Aircraft
folder toX-Plane 11\Aircraft
folder in X-Plane installation location. - Connect Flight Controller to PC using USB Cable. Make sure FC is flashed with simulator-enabled firmware https://github.com/RomanLut/INAV-X-Plane-HITL/releases/
- Configure FC (see Flight Controller configuration below)
- Start X-Plane 11
- Select "Show extra aircraft from older versions" to see INAV Surfwing
- Select INAV Surfwing, start flight
- When scenery is loaded, select Plugins->INAV HITL->Link->Connect to flight controller. Plugin should automatically detect serial port.
- Flight using RC Controller, setup PIDs etc.
Note: Use "Internal View/Forward with No Display" for full immersion FPV flights:
For Linux, all steps are analogous to Windows.
Sorry, MacOs in not supported currently (assistance needed to build plugin for MacOs, see development.md).
Flight controller should be fully configured like for the real flight. There is no need to configure mixer and motors output.
Configure Platform type: Flying wing for INAV Sufwing in INAV Configurator.
It is possible to use plugin with any other airplane (copy HITL plugin from NK_FRVSurfWing\plugins\INAV-X-Plane-HITL
to corresponding Aircraft subfolder of other airplane).
Platforms other than "Airplane" are not supported.
Note: If FC is mounted on UAV, you can use profiles to have different PIDs for simulated airplane. Motor and Servo outputs are disabled in simulation mode.
Note: There is no need to connect battery, if receiver is powered from USB connection.
See recommended starting pids for INAV SurfWing (Platform: Flying wing) nkfpvsurfwing.md
Plugin will simulate sensors, enabled in FC's configuration.
In minimal case, you need FC with some kind of receiver attached.
No real barometer and GPS sensors are required.
FC with analog OSD is highly recommended. If FC does not have OSD chip, there will be no OSD in simulator.
There are two modes of simulation:
- simplified simulation: attitude is passed from X-Plane.
- full simulation: attitude is estimated from sensors data
Due to slow update rate (update rate can not be larger then X-Plane FPS) and no synchronization beetween INAV cycles and X-Plane FPS, full emulation mode will show noticeable problems with estimation ( drifting horizon ). Simplified emulation is recommended for debugging code not related to IMU.
Sensors not listed below are not simulated. Please disable in INAV configuration.
Real acceleromerer should be calibrated in INAV Configurator. Accelerometer orientation settings are not relevant for simulation.
Barometer will be simulated if enabled in INAV Configurator. If real barometer is not present, select "FAKE" type.
GPS functionality will be emulated if enabled in INAV Configurator. It is not required to have real GPS sensor connected.
X-Plane simulated world is build based on real world map data. GPS coordinates in game correspond to real locations.
Simulated GPS Fix can be switched in menu:
Magnetometer is simulated if selected in INAV configurator. It is not required to connect real sensor. Select QMC5883 if there is no real sensor present. Calibration is not required.
For convience, it is possible to simulate 3S battery presense:
- infinite 3s battery
- discharged 3s battery
- a battery which lasts a period of time on full throtle, 2x time on 50% throtle etc.
If enabled in menu, airspeed from X-Plane will replace readings of pitot.
Pitot should be enabled in INav Configurator.
It is possible to use VIRTUAL pitot device.
Note: VIRTUAL pitot is not supported on 411 and 722 CPUs (you will not be able to arm).
Note: VIRTUAL pitot will fail initialize if GPS sensor is disabled in configuration.
OSD is rendered in X-Plane exactly as configured in INAV Configurator.
It is highly recommended to use Flight Controller with OSD to see system messages on screen.
The following requirements should be met to have OSD drawn in X-Plane:
- OSD should be configured as
AUTO
,PAL
orNTSC
type in "OSD" tab in INAV Configurator. - OSD should be enabled in "Configuration->Other features->OSD" in INAV Configurator.
- OSD chip should be present on Flight Controller (MAX7456). OSD will not work without MAX7456 compatible chip. OSD will not work if HD Zero, DJI or Pixel OSD selected in configuration.
The following options are present in menu:
- None: disable OSD rendering
- AUTO: number of OSD lines is provided by FC
- PAL: force rendering of 16 OSD lines
- NTSC: force rendering of 13 OSD lines
- Smoothing: Nearest: Use nearest pixels for characters rendering
- Smoothing: Linear: Use linear smoothing for characters rendering
OSD is using Bold font from INAV Configurator. It is possible to replace font (\plugins\INAV-X-Plane-HITL\64\assets\osd_font.png)
with other font from INAV Configurator https://github.com/iNavFlight/inav-configurator/tree/master/resources/osd
For convience, it is possible to mute beeper in simulation mode:
Plugin will simulate analog video link quality acccording to setting. Home point is independent from FC home point. Home point is set to position on ARM.
Plugin can draw flight path on X-Plane map.
Coordinates can be extracted from:
- Latitude/Longitude from OSD - extracted from OSD. Note that these number have low accuracy and are not updated synchronously. Path will have jittering under zoom.
- debug[0]/debug[1] as Latitude/Longitude - assumed that coordinates are provided in debug[0]/debug[1] variables by custom INAV build (int32_t, int32_t).
Other menu options:
- Download waypoints from FC - this option will download Mission waypoints from FC and show on X-Plane map (in pink color)
- Teleport to location - https://github.com/RomanLut/INAV-X-Plane-HITL/edit/main/README.md#teleporting-to-gps-coordinates
Path is drawn on "INAV HITL" layer:
An option in Map menu allows to teleport plane to any GPS location from clipboard.
Right click in Google Maps, then click on the coordinates to copy them to clipboard:
Then select Plugin->INAV HITL->Map->Teleport to location (from clipboard)
This works Ok for small distances. If you teleport to the other side of the Earth, you may find yourself in the empty space. Try to teleport again, it usually works.
Autotrim and servo autotrim have no effect in simulation (TODO).
See development.md
Many thanks to:
- Sergii Sevriugin for initial implementation and a lot of testing
- NKDesign for NK FPV SurfWing RC plane for X-Plane
- b14ckyy for Surfwing 3D model
-
X-Plane INAV HITL prototype has been orignally implemented by Sergii Sevriugin:
https://github.com/sevrugin/inav/tree/master-simulator-xplane
https://github.com/sevrugin/inav-configurator/tree/master-simulator-xplane
-
NK_FPV Surfwing V2 | RC Plane 2.2.0
https://forums.x-plane.org/index.php?/files/file/43974-nk_fpv-surfwing-v2-rc-plane/
-
X PLANE TUTORIAL: MaxiSwift installation with X Plane v9.70 for HIL simulations
-
Quadrotor UAV simulation modelling using X-Plane simulation software
http://www.iraj.in/journal/journal_file/journal_pdf/2-448-152361879882-85.pdf