inav
inav copied to clipboard
Support for Hardware In The Loop simulator in X-Plane 11
Support for HITL in X-Plane 11: https://github.com/RomanLut/INAV-X-Plane-HITL
~24 bytes of RAM and ~2600 bytes of flash.
It would be awesome to be able to use Inav in the sim.
Fantastic Work! As it is raining today I will give it a try right now. One question. the guide says that loop time and FPS are not synced and full simulation can cause IMU discrepancies. Would it help to set the loop time to 60Hz as well as the Sim? Or loop time to something with an integer ratio like 120 or 180Hz?
So with a constant vsynced X-Plane at 60fps and default 1000Hz loop time everything works as expected with the full simulated sensors on. I was able to compare default settings AHI drift with my updated settings and see a clear difference the same way as in real craft. All in all it works really well. https://youtu.be/RsXRItJaiLw
I had tried this before, and I liked it... But, it would be interesting if we could test multirotors too, how can we do that?
@JulioCesarMatias I guess someone has to create a Multirotor model. We also need more plane models. The wing works fine but is not maintained anymore and has weird arodynamics. Lot of yaw wiggle. And had to adjust the control surface throws to get some reasonable rates and FF values. But autotune works well.
The Plane Maker works with tons of shortcut names of variables and a lot of parameters that have to be adjusted but I will try to work myself into it. Maybe I am able to create some craft.
Hmmm, how soon can we get this in master!!! @DzikuVx ok with you?
Fantastic Work! As it is raining today I will give it a try right now. One question. the guide says that loop time and FPS are not synced and full simulation can cause IMU discrepancies. Would it help to set the loop time to 60Hz as well as the Sim? Or loop time to something with an integer ratio like 120 or 180Hz?
Well situation can be enchanced but will never will be replacement to the real world.
In real flight, FC is sampling and integrating sensors with high frequency. Each sample is correct(noisy) value.
In simulator, FC is reading constant values which were passed with the last update from simulator. Theese are not values which will be used by simulator to calculate next attitude. In active ACRO flight errors accumulate quickly producing completely broken horizon. I have seen situation where horizon was rotating like a fan, not able to converge :)
Theoretically it could be possible calculate sensor values in FC in a way that they integrate to the attitude passed from simulator. However at this point it gets too complicated.
I think current implementation is Ok already to test math, signs and scales, to check ideas like this https://github.com/iNavFlight/inav/pull/4371
and perfect for checking issues not realted to IMU like this https://github.com/iNavFlight/inav/pull/8228
I had tried this before, and I liked it... But, it would be interesting if we could test multirotors too, how can we do that?
X-Plane airflow simulation is not good for qudcopters, and for small planes too unfortunatelly :( Also note that sensors update rate can not be faster than X-plane FPS.
Anyway, if someone wants to try it, here is some information: https://github.com/RomanLut/INAV-X-Plane-HITL/issues/7
The wing works fine but is not maintained anymore and has weird arodynamics. Lot of yaw wiggle. And had to adjust the control surface throws to get some reasonable rates and FF values. But autotune works well.
Unfortunatelly X-Plane physics simulation was not designed for small planes. The author of "fpv surfwing" had to do some tweaking to make it flight Ok. This is the best RC plane model I was able to find. I was not able to find any freeware classic RC plane models.
You may try FX-61 FX-61.zip
@RomanLut I tried the FX-61. It is unfortunately completely broken. AHI is all over the place when enabling sensors and altitude and speed show insane numbers. like 1000kph+ in the osd xD
there is also this fixed wing drone thing with inverted V-Tail but there the controls are messed up. Might be fixable though
Nevermind. Your version seems to work but either the CG is too far back or the elevator throw too much or both. I have slightly adjusted the CG forward and reduced elevator throw a bit. Now the FX-61 flies like a dream after an autotune. Nice! Better than the other FPV wing with less yaw wiggle
Here is the updated version. FX-61 FPV.zip
@RomanLut Do you think the Firmware Side is in a state ready to merge? I talked to @MrD-RC and he agreed that we should merge the PR into the master for 6.0 asap, to simplify testing of new features.
from my intensive testing the last 2 days with a few hours of virtual flight time, it works very well.
Yes firmware side is ready. And I think I will not be adding more features to plugin too.
I was testing it for 2 weeks on Windows and sevrugin was testing it on linux.
The only things I miss are Airspeed sensor simulation and maybe lidar for AGL altitude measurements to test more programming stuff. Although lidar is a bit far-fetched, do you think Airspeed is possible? maybe with a later release?
-
I did not add airspeed sensor because INAV does not use it. I can add if we have some features to test. If you just want to see some numbers on OSD, you can choose VIRTUAL airspeed sensor. It will display ground speed + wind estimator speed. Beware that VIRTUAL airspeed sensor code is not included on 411 and 722 by default - you will not be able to arm). Add #define USE_PITOT_VIRTUAL.
-
Adding lidar(rangefinder) is possible - it is possible to query terrain elevation in plugin. Not possible to query Scenery height though. However, I do not know how lidar should function. Do we have use case for lidar? I would need complete description for the task.
I have a question what is https://github.com/iNavFlight/inav/blob/master/src/main/flight/hil.h?
Is this some obsolete code?
- I did not add airspeed sensor because INAV does not use it. I can add if we have some features to test. If you just want to see some numbers on OSD, you can choose VIRTUAL airspeed sensor. It will display ground speed + wind estimator speed. Beware that VIRTUAL airspeed sensor code is not included on 411 and 722 by default - you will not be able to arm). Add #define USE_PITOT_VIRTUAL.
- Adding lidar(rangefinder) is possible - it is possible to query terrain elevation in plugin. Not possible to query Scenery height though. However, I do not know how lidar should function. Do we have use case for lidar? I would need complete description for the task.
Leave the Real Pitot Tube data available on the MSP, leave it in a commented line, it will be useful in the future!
This PR is really good, but not being able to test multirotors is really bad.
I have a question what is https://github.com/iNavFlight/inav/blob/master/src/main/flight/hil.h?
Is this some obsolete code?
yes, obsolete
Ok, I implemented pitot emulation and added to PR. I will release new plugin tomorrow.
I think we should include this in the release note
Pitot tube is helpful in the future indeed but also currently as I am working on a logic function program to have a throttle loop control based on airspeed. I hesitated to do that on a real plane initially due to risk of stall with bad settings but with the HITL this would be easy peasy to test and adjust. So I can have a baseline for an airspeed controlled throttle program.
Lidar is also availale in programming and can be used to make a autoland program that is more reliable than the current system. Although this has low priority as it would still be a blind landing currently until short before touchdown.
So Pitot is the most important one from my point of view and would be a great addition.
Following on from @JulioCesarMatias comment on release notes. I also think a small md file in the docs folder with setup instructions would be handy.
Released plugin v1.0 with Pitot simulation https://github.com/RomanLut/INAV-X-Plane-HITL/blob/main/README.md#pitot
Following on from @JulioCesarMatias comment on release notes. I also think a small md file in the docs folder with setup instructions would be handy.
Oh yeah! A document with all the necessary instructions is perfect!
I just found a little issue. If Compass is disabled in INAV (set to NONE) it is still emulated by the plugin when connected. I can see it active when I shut down X-Plane and connect with the configurator without reboot.
Pitot works great btw! Now I can play with that as well.
I just found a little issue. If Compass is disabled in INAV (set to NONE) it is still emulated by the plugin when connected. I can see it active when I shut down X-Plane and connect with the configurator without reboot.
Fixed, this was configurator display issue only.
@RomanLut I played around a bit with the Telemetry viewer app, and something catches my attention. In the telemetry even with compass disabled, INAV still knows the true heading of the craft. But without compass in reality INAV uses the course heading only and does not know the nose orientation. This makes it impossible to simulate plane behavior in strong headwinds with no compass installed.
is it possible to change the plugin so INAV only receives course heading instead of true heading if compass is disabled? Like in reality?
Updated plugin. GPS data contains ground course heading now. Disable compass, set Attitude to "estimation" => inav will estimate yaw from ground course heading. With "Attitude: set from x-plane", attitude yaw is set to true heading.
Didn't really appreciate what this did but now I've got it working it is indeed an awesome bit of work, Will make testing changes so much easier and risk free. Can finally test all those emergency/failsafe functions properly not worrying about it ending in a crash.
@RomanLut I think we all can't thank you enough for this! It gets even more impressive if you compare a real flight with a simulated one and it is basically identical

@MrD-RC @b14ckyy Do we have anything else to add here? Or is this Ready To Merge?