flybywiresim / aircraft

The A32NX & A380X Project are community driven open source projects to create free Airbus aircraft in Microsoft Flight Simulator that are as close to reality as possible.
https://flybywiresim.com
GNU General Public License v3.0
5.13k stars 1.12k forks source link

[META] Flight Plan Management and Guidance #4028

Closed beheh closed 2 years ago

beheh commented 3 years ago

Problem

The default flight plan manager is severely limited in multiple ways:

As it uses native APIs to manage the flight plan, we cannot modify or improve it significantly.

First Approach: Working Title Flight Plan Manager

To fix that, we've been rewriting it and have started from the Working Title (WT) code (MIT-licensed) as the basis, but need to still adjust lots of parts in it and make specific to our aircraft. The WT implementation lays a lot of effort on keeping the flight plan manager API compatible with the default code, but this has various limitations.

It works like this:

While this is a significant improvement, we're still far from being able to write accurate guidance:

Next Steps

Work is happening on the autopilot-fpm branch and being coordinated in #ata-22-fms on Discord. Please indicate when you're starting work on a specific part here, so there is no conflicts! There could also be multiple people working on the same thing, it just needs to be coordinated.

Here's a list of specific tasks that can be picked up in the autopilot-fpm branch:

Flight Plan

Guidance

CBGonzalez commented 3 years ago

You say "The default nav data is missing information like turn direction" but as far as I have seen, the legs are fully encoded (including turn direction when relevant). I´ve been looking into the nav data (directly in the BGL files) but haven´t found a way to access it from within the sim... There´s probably a loss of data when it goes to the built-in gps thingy (noticeable, for example, by the lack of RF legs in displayed approaches, although they are encoded in the BGL)

Benjozork commented 3 years ago

That is precisely the issue. The navdata APIs from inside the sim are lacking and do not provide all the information stored in the bgl.

pareil6 commented 3 years ago

Implement turn anticipation distance for type 1 transitions. Right now, as soon as you've entered the type 1 transition segment we send a hard bank command to the autoflight systems. This is both extreme and unrealistic, as the aircraft can not go from level flight to fully. We need to start the turn earlier and rather than sending bank angle 0 -> 0 -> 25 -> 25 we need to construct a geometric path that actually turns the aircraft in (0 -> 5 -> 15 -> 25). This will make our curves smoother and more accurate.

Apologies if anyone else has already looked at this, but I got nerd-sniped by this problem last night (having tried to solve it in the past but never having got very far) - and ended up with a quick and dirty empirical algorithm for doing it. I'm writing this here for the sake of not losing it (in case it ends up being useful), but will not be offended if someone has a cleaner solution!

The current implementation was my solution last time I tried to solve this (pick a turn radius, form a circle arc between the entry and exit points, then turn around the centre of that circle maintaining a fixed radius), and given it's relatively easy to implement, I tried smoothing the turn by increasing the turn radius as we enter it and decreasing it as we exit it. A quick example for a 90 degree turn, with the black line being a fixed-radius curve, and the grey lines being various smoothed versions of it:

Screenshot 2021-04-06 at 09 45 15

(Advance warning: there's some actual maths here, and also note that anywhere I'm talking about an angle, it's being calculated in radians, even if I talk about it in degrees, since degrees are easier for most people to visualise).

The empirical bit: as we go through the turn, we want to extend the radius initially to a peak half way through the turn, then pull the radius back in as we bank out of the turn - which happens to be roughly the shape we'd get from an offset inverted cosine (and happens to be the only function I can think of with the properties we want, having slept through a lot of my maths lectures at university...).

So - for an initial turn radius of r_0, a turn angle of \theta_0, a current 'turn' angle of \theta (ie. the angle between the radius line and horizontal on the graph above) and a smoothing gain k, we end up with something like:

Screenshot 2021-04-06 at 10 04 12

What value for k? It depends - too small and we end up turning quickly anyway, but too large and we end up turning away first (ie. the cosine term becomes larger than the base radius term). There's some fun maths involved in figuring out what that limit is - but eventually you end up at k being between zero and (\theta_0 / 2\pi)^2, with zero giving no correction (we're back to just flying a circle arc) and (\theta_0 / 2\pi)^2 giving us the maximum correction this algorithm allows without turning the wrong direction first. For a 90 degree turn (\pi/2 radians) we end up with a limit of 1/16 for k, which gives us the right-most curve in that graph above.

The second part of this (which I didn't do) was calculating the target heading at each point on that curve - I know how to calculate it, I just haven't done the work yet. Once I have, I'll look at doing a PR adding this unless anyone has a better solution before then.

(Also, I never thought I'd find myself wanting LaTeX equation formatting in a GitHub comment...)

tracernz commented 3 years ago

@pareil6 The other consideration is wind. If that isn't accounted for we may end up well off track by the end of a long turn.

BlueberryKing commented 2 years ago

I think this is no longer relevant with all of the changes that have been made to the FMS in the meantime. I will close this issue, but feel free to reopen if you feel it's justified.