[HN Gopher] Creating an autopilot in X-Plane using Python
       ___________________________________________________________________
        
       Creating an autopilot in X-Plane using Python
        
       Author : signa11
       Score  : 131 points
       Date   : 2024-03-24 05:07 UTC (17 hours ago)
        
 (HTM) web link (austinsnerdythings.com)
 (TXT) w3m dump (austinsnerdythings.com)
        
       | t0mas88 wrote:
       | The Connect API for X-plane is a great toy. I wrote a "recover
       | from upset" script some years ago after having a discussion on
       | the best methods for upset recovery by human pilots. You can
       | easily implement something that does what a human would do and
       | then compare other options that may be possible.
       | 
       | The one thing that does make it a bit "easy mode" is that all
       | data is clean and exactly as you would expect mathematically.
       | While real input data for avionics is more noisy and has several
       | types of sensor errors.
        
         | sokoloff wrote:
         | It also seems like the chance of having had sensor failure or
         | disagreements is higher in cases where a human pilot (or
         | autopilot) has lost control of the airplane or exceeded
         | autopilot limits. (It's by no means all cases, but some LoC
         | incidents are initiated/contributed to by a sensor or avionics
         | failure.)
        
           | t0mas88 wrote:
           | Absolutely. I've had an instrument failure (invalid attitude
           | indication) cause an autopilot issue that put the aircraft in
           | an upset state in seconds. From there you're manually
           | recovering based on limited data. Fortunately this is a key
           | part of training and unlike the autopilot a human pilot knows
           | to look at the backup instruments and make a judgement on
           | what data is correct.
           | 
           | But that judgement is very hard to code into an automated
           | system. Because there is also a bit of trial and error
           | involved. If indications don't follow your inputs, you're
           | going to assume those indications are wrong and put more
           | weight on the others.
        
         | auspiv wrote:
         | The numbers coming from X-Plane are indeed super "clean" and
         | very mathematically expected. No lag on VSI, etc
        
       | Havoc wrote:
       | Wow. Wouldn't have guessed that a commercial game gets used in
       | certified simulators
        
         | Gare wrote:
         | Kind of makes sense that a company with relevant expert domain
         | knowledge can double-dip making both pro and game stuff.
        
       | DarkmSparks wrote:
       | if you want more than just an autopilot I have a almost all 747
       | 400 systems modelled in lua open sourced for xplane 12 at
       | 
       | https://github.com/mSparks43/747-400
       | 
       | CBTs linked in an issues milestone.
        
         | thecosmicfrog wrote:
         | Sparky!
        
         | mdaniel wrote:
         | > CBTs
         | 
         | I wasn't familiar with what that acronym meant in the context
         | of X-Plane but it seems to be "Computer Based Training", and
         | after watching one of them I'm thankful for the 2x playback
         | rate on youtube because whew
        
       | stavros wrote:
       | Oh man, this is creating a new itch in me, thanks! I hope it's a
       | gateway for me to write a flight controller for my RC planes.
        
       | markb139 wrote:
       | 25 years ago I did the same thing with MS flightsim as an
       | interesting project. I took a similar approach except I was using
       | Java. I got as far as being able to navigate to lat/long fixes.
       | Learnt quite a bit in the process
        
       | saulrh wrote:
       | You can also do this for Kerbal Space Program using the kRPC mod:
       | https://forum.kerbalspaceprogram.com/topic/130742-18x-to-112....
       | It's a much less polished experience, but you get more of the
       | experience of an actual avionics/robotics project doing it this
       | way - multiple sensors that may not necessarily agree with each
       | other (for example, IIRC accelerometers installed at different
       | ends of the ship will register different readings!), you have to
       | be quite a bit more careful when interfacing with engines and may
       | not have access to a simple "go left" control input, you have to
       | deal with whatever nightmare vehicle you built that you need a
       | computer to handle, that kind of thing.
        
         | mattsan wrote:
         | If you want a simpler intro into learning the math/logic behind
         | rocket guidance systems, kOS is an alternative mod.
         | 
         | The main difference is that it has a pretty good base
         | autopilot, such that you can give it a direction vector to
         | point to.
         | 
         | The downside is that you have to learn a specific language for
         | it, but you can also make your own language that transpiles as
         | a fun project :)
         | 
         | Example of what's possible:
         | https://www.youtube.com/watch?v=szsIL_0m2Qo
        
           | saulrh wrote:
           | kOS is good stuff, yeah. Very... immersive, heh. It has all
           | of these weird design decisions from having been built to do
           | relatively simple spaceship sequencing tasks first, rather
           | than as a general purpose programming language, and having
           | grown over time to do arbitrary stuff. That history gives it
           | this really uniquely crunchy feeling that you just wouldn't
           | get with a more modern, ergonomic system.
        
             | mattsan wrote:
             | To be fair, theres also the kIPC mod that bridges and
             | connects both kOS and kRPC together. I personally like the
             | kerbal-y equivalent of Ada with kOS though ahaha
        
       | auspiv wrote:
       | Austin from Austin's Nerdy Things here - super stoked to see my
       | blog's traffic at 7x the daily average at 7am! Thanks to all the
       | visitors!
       | 
       | I actually revisited this series a few weeks ago. I added a
       | Flask/html frontend to control the autopilot setpoints (much
       | easier/fluid than editing the code and restarting) using Redis as
       | a quick intermediate "database" to store the setpoints.
       | 
       | I whipped up a post this morning demonstrating this to get it out
       | there due to the volume of visitors who might find it
       | interesting! Hopefully I find time to polish the post later.
       | 
       | Here it is https://austinsnerdythings.com/2024/03/24/adding-some-
       | polish...
        
       | Hortinstein wrote:
       | I have been wanting to play around with drone swarm simulated
       | behavior, does anyone know of a sim that would let me do
       | something like this with 10 or so drones?
        
         | lijaf wrote:
         | How about https://github.com/utiasDSL/gym-pybullet-drones
        
       | MPSimmons wrote:
       | This reminds me of when I discovered the kRPC plugin for Kerbal
       | Space Program and I wrote a state machine for it -
       | https://github.com/standaloneSA/krpc_state_machine
        
       | FMCalisto wrote:
       | Cool stuff, Austin! Really liked how you upgraded the X-Plane
       | autopilot with Flask and Redis. Makes tweaking those set points
       | way smoother. It's neat to see Python take on complex tasks like
       | this. Ever think of messing with this setup for other sims, or
       | throwing in some trickier algorithms? Cheers for laying it all
       | out there!
        
       | kotaKat wrote:
       | You've reminded me of the actual autopilot that was based on some
       | X-Plane shenanigans too ;)
       | 
       | https://www.x-plane.com/hardware/evo/9_seeker/Seeker.html
        
       | andrehacker wrote:
       | O wow. I was not aware of the NASA plugin. I wanted to build a
       | simple dashboard on a separate screen for a while (I run X-plane
       | with a cheap projector which is good enough for the scenery but
       | not for the 6 pack). Each time I explored this I end up with what
       | seems to be windows-only solutions.
       | 
       | The NASA plugin supports a Mac version and it exposes a
       | bidirectional interface to X-plane served up through UDP.... then
       | they provide sample clients.
       | 
       | This worked out of the box, on the Mac I did have to run X-plane
       | in Rosetta2 but I was able to wire this up in a Python web server
       | (native) so now I can display flight data real time in a web
       | browser, nice.
       | 
       | Thanks for getting me on track and good job on the autopilot,
       | will check that out later.
        
       ___________________________________________________________________
       (page generated 2024-03-24 23:00 UTC)