Jump to content
The simFlight Network Forums

Recommended Posts

Posted

i've just noticed a "bug" in my program  as the heading value goes above 360 .... and its sometimes in accurate by a couple of degrees  here's my code:

 

Dim HDG As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H580) ' aircraft heading


Dim Heading As Double = (HDG.Value * 360 / 65536 * 65536)
            TxtHDG.Text = Heading.ToString("0" & "°")

 

Posted

You should probably declare the offset as UInteger because the value is unsigned (it will never be -20 degrees for example).

Dim HDG As Offset(Of UInteger) = New FSUIPC.Offset(Of UInteger)(&H580) ' aircraft heading

When you say it's inaccurate, what are you comparing it to? This offset gives the True heading, not the magnetic heading shown on the aircraft instruments.

Paul

Posted
1 hour ago, sniperfull said:

What about the HDG going over 360 Degrees?

The value actually in 0580 cannot ever represent anything over 359.999999 ... degrees. 360 would be zero in any case.

The units in the 32-bit offset 0580 are the actual heading (0-359.9999...) divided by 360 (so it is completely fractional) then multiplied by 4294967296 (the maximum possible unsigned value in 32-bits), so making full use of those 32 bits. Thus the largest value, converted back to degrees, cannot be 360 or anything higher.

Pete

 

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.