• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FSX Turn anticipation calculation

Messages
371
Country
france
Hello,

As you know, FSX has a bad management of AP turn anticipation with big aircraft at high speed. With my FMC project, this may occur problem xith some approaches. As I am working to adapt my FMC on B747, this problem is amplified. So I decide to write code to calculate amount of turn and apply a coefficient according this amoount of turn and aircraft speed.

So, as my knowledge in mathematic is very poor, I present my code to you because I found the solution but with an empiric method and I would like to know if there is a better solution to calculate this amount.

Code:
(L:NB_list_WYPT,number) 2 >
(A:RADIO HEIGHT,feet) 2000 > and
(A:GPS WP Distance,nmiles) 10 < and
(L:Init_FMC,bool) and
(L:CSTR_hold,bool) ! and
(L:ARC_DME,bool) ! and
(L:Leg_segment,bool) ! and if{ (L:TimerCycle,number) 100 < if{ (L:TimerCycle,number) ++ (>L:TimerCycle,number) } els{ 0 (>L:TimerCycle,number) }
                                (C:fs9gps:FlightPlanActiveWaypoint) (>C:fs9gps:FlightPlanWaypointIndex)
                                (C:fs9gps:FlightPlanWaypointMagneticHeading,degrees) (>L:CurrentTrack,number)
                                (C:fs9gps:FlightPlanWaypointIndex) 1 + (>C:fs9gps:FlightPlanWaypointIndex)
                                (C:fs9gps:FlightPlanWaypointMagneticHeading,degrees) (>L:NextTrack,number)
                                (L:CurrentTrack,number) 180 < (L:NextTrack,number) 180 < and
                                (L:CurrentTrack,number) 180 > (L:NextTrack,number) 180 > and or if{ (L:CurrentTrack,number) (L:NextTrack,number) - abs (>L:DeltaTurnAnticipation,number) }
                                                                                                    els{ (L:CurrentTrack,number) (L:NextTrack,number) max (>L:Biggest,number) (L:CurrentTrack,number) (L:NextTrack,number) min (>L:Smallest,number)
                                                                                                        (L:Biggest,number) 180 - (L:Smallest,number) > if{ (L:Biggest,number) 180 - (L:Smallest,number) + (>L:DeltaTurnAnticipation,number) }
                                                                                                                                                        els{ (L:Biggest,number) (L:Smallest,number) - (>L:DeltaTurnAnticipation,number) }
                                                                                                        }
                                (L:DeltaTurnAnticipation,number) (L:DeltaTurnCoef,number) / s0 (A:GPS GROUND SPEED,knots) 200 / s1 l0 l1 * (>L:DeltaTurnAnticipationMiles,number)
                                (A:GPS WP Distance,nmiles) (L:DeltaTurnAnticipationMiles,number) < (L:TimerCycle,number) 98 > and if{ (C:fs9gps:FlightPlanActiveWaypoint) 1 + (>C:fs9gps:FlightPlanActiveWaypoint) 0 (>L:TimerCycle,number) }
                                }
I found that there is 3 ways according current heading and next heading:
first way:
if current heading and next heading are both greater or smaller than 180, the amount of turn == abs (Current heading - next heading)

if one of the headings < 180 and the other >180, there are 2 ways :
the bigger heading - 180 is greater than the smallest heading, amount of turn == (Biggest heading - 180) + smallest heading
the bigger heading -180 is smaller than the smallest heading, amount of turn == biggest heading - smallest heading.

Is there a a more simply method to get this amount ?

Thanks

Francois
 
Also: if you intend to lock the localiser with the FSX autopilot, I've found that the best time to switch from your code to the FSX localiser lock is at ten degrees before the localiser e.g. if you are turning 300 - 290 - 280 etc. and the localiser is at 250, switch to the FSX localiser hold at 260 degrees. IME this gives the smoothest transition.

If anybody wants it in C:
Code:
// --------------------------------------
// Direction of turn
int ap_turn=0;                                //Direction to turn when heading mode is engaged
int ap_delta=0;                                //Closing angle on new heading
int getAPDelta(int target)            // Target is the required heading
{
    int delta=0;

    delta=target-(int)getHdgMag();  // Current magnetic heading
    if(delta<-180)delta+=360;
    if(delta>180)delta-=360;
    if(!ap_turn)
    {
        if(delta<0)ap_turn=1;                // Left
        else if(delta>0)ap_turn=2;    // Right
    }
    return abs(delta);
}
This gives you turn left/turn right and the closing angle onto the required heading.
 
Francois,

Not sure if this answers your question, but to calculate the difference beween the current and a target heading I always use this code in xml:

XML:
(L:TargetHeading,number) (L:CurrentHeading,number)  - dnor d 180 > if{ 360 - } (>L:HeadingDifference,number)

So the HeadingDifference is normalised between -180 (negative values: turn left) and +180 (positive values: turn right) degrees, whatever the values (in degrees) of TargetHeading and CurrentHeading.
Never fails ...

Rob
 
Last edited:
Hello,

Many thanks to everybbody for your interest. Right or left turn has no importance; result must give only number of degrees of the most direct turn (<180°). My code works well but I suspected that there was a simpler, more direct solution .

Rob, you formula works perfectly !!!!! You do the job in one line, where I had 3 lines !!! Only missing to transform the final result in absolute value because formula can give a negative number.
Now, I know the reason why I was the last of my class in mathematic :)

Thank you very much
 
Francois, so the code becomes:
XML:
(L:TargetHeading,number) (L:CurrentHeading,number)  - dnor d 180 > if{ 360 - } abs (>L:HeadingDifference,number)
Rob
 
Back
Top