Giter Club home page Giter Club logo

are-we-flying's Introduction

Are We Flying? (in Microsoft Flight Simulator 2020)

(and if feel like you got anything out of this work, consider (temporarily, even?) becoming a patron of my work over on https://www.patreon.com/bezierinfo, or send a one-time donatation to help keep this project funded. Any amount is appreciated!)

What is this?

this project is both the completed code for, and a tutorial on, writing an autopilot for MSFS that runs in Node and is controlled via a web page, by using MSFS's SimConnect SDK.

If you just want to run the code and be up and flying, clone the repo, then install all the necessary dependencies using npm install in the root dir. (Note: Node 19 or higher is required. I recommend using nvm-windows to make managing Node versions easier. Don't install Node using the nodejs.org installers).

You'll need an .env file, with the following content:

export DATA_FOLDER=
export ALOS_PORT=9000
export WEB_PORT=3000
export API_PORT=8080
export FLIGHT_OWNER_KEY=FOK-12345

The ports are really just whatever's convenient for you, but they need to exist. Also, the "flight owner key" can be whatever you like, but again it needs to exist.

Finally, the DATA_FOLDER variable is for if you went through the trouble of downloading all the data from https://www.eorc.jaxa.jp/ALOS/en/dataset/aw3d30/aw3d30_e.htm (which is free, but does require getting an equally free account because it's only downloadable after logging in). Note that this is a 150GB download spread of hundreds of files, unpacking to 450GB of GeoTIFF files and associated metadata. Space is cheap, and a lot of folks have unlimited internet these days, but even then, I suspect few people will actually download this dataset.

I'm still thinking of a way to make that less of a problem =)

Running the project

Have MSFS running, and then run run.bat in the root folder to start two command prompt instances that run the API server and web page server, respectively (which means you can kill and restart them individually if necessary)

Needless to say, you need to be on Windows for this, because MSFS doesn't run on anything else (I mean, I guess XBox? But I doubt you have git and/or Node installed on that).

Using the autopilot

There are two parts to the autopilot:

  1. the AP toggles, and
  2. the navigation map

The AP toggles are:

  • AP toggle the autopilot on or off
  • LVL toggle the wing leveler on or off
  • ALT toggle altitude hold on or off, with the altitude in feet set using the input field to the left of it
  • ATT toggle auto-throttle on or off
  • TER toggle terrain-follow on or off (note: this currently only works if you've downloaded and unpacked the ALOS 30m dataset)
  • HDG toggle heading mode on or off, with the heading in degrees set using the input field to the left of it
  • take off makes the plane take off!
  • land only exists (for now) when loading the page with ?experiment=auto-land, and will find a nearby airport to land at, then tries to land there.

The navigation map lets you control the flight plan Google Maps style:

  • click to place a waypoint
  • click an existing waypoint to set its altitude (note: altitudes are ignored when terrain follow mode is active)
  • click-drag a waypoint to move it around
  • double-click a waypoint to remove it

Waypoint navigation is based on flying legs between waypoints, with the active leg indicated by its start and end waypoint being highlighted.

Waypoint based flight plans can be saved and loaded, as well as reset (marking each waypoint as not having been visited yet) or cleared (removing all waypoints from the map)

Testing the code without even running MSFS

There is a convenient mock.bat that runs the api server in "mock mode" where it has a SimConnect shim that's just barely complete enough to fake a plane, with a shim that lets it correctly respond to get/set/autopilot instructions so you can test code without having to run MSFS. You're still going to have to test the code with MSFS running eventually, but it can save a bunch of time by not having to constantly restart flights in-game just to see if some function no longer errors out because you had a typo somewhere. A bunch of the AP code is also set up for server-side hot-reloading so that changes immediately kick in rather than having to restart the API server.

Reading the tutorial

Head on over to https://pomax.github.io/are-we-flying for the extensive tutorial

Sponsorship / donation

Writing a 150 page tutorial (book?) takes time and effort. If you can financially appreciate that, click the sponsor button to help fund this kind of work either as a one-time thing, or on an on-going basis. Anything you can spare is highly appreciated.

Questions and comments

If you found bugs, or fixed bugs, or even came up with completely new code that's cool to add (or replace existing code), file an issue!

For less serious engagement, you can also hit me up over on https://mastodon.social/@TheRealPomax

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.