Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello,

I've had a long standing bug in my code that I really need to figure out.

Let me first say that math is absolutely not my strong point.

When calculating magnetic heading, my result will read as over 360 once the heading wraps around. So, 5 degrees might read as 365, 15 might read as 375.

I've used the same calculation as what is listed in the fsuipc record to CSV lua script, but I'm not getting the same results.

My code is in python. All the other offsets I'm using (well over 100 now), are working great. It's just this one that's tripping me up.

Here is the code I'm using. I really hope someone can sort this out.

The variables mentioned are grabbing the raw offset data from fsuipc.

                self.headingTrue = self.instr['Heading'] * 360 / (65536 * 65536)
                self.headingCorrected = self.instr['Heading'] - (self.instr['MagneticVariation'] * 65536)
                self.headingCorrected = self.headingCorrected * 360 / (65536 * 65536)

 

 

Posted

In pseudo code, similar to the built in flight sim XML DNOR function. (degrees normalize)
Don't know python ((

If self.headingCorrected > 360 then
              self.headingCorrected = self.headingCorrected - 360
End

If self.headingCorrected < 0 then
              self.headingCorrected = self.headingCorrected + 360
End


Roman

Posted

In the FSUIPC offsets the heading is probably, don't really know, "normalized" already.
Once you bring in the MagVar into the equation* it could become non-normalized.

*self.headingCorrected = self.instr['Heading'] - (self.instr['MagneticVariation'] * 65536)

Another option is just to get the magnetic heading and not deal with MagVar for self.headingCorrected -
self.headingCorrected = 0x2B00 (Gyro compass heading (magnetic), including any drift. 64-bit floating point.) 

Roman

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

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.