Jason Fayre Posted March 3, 2020 Report Posted March 3, 2020 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)
spokes2112 Posted March 3, 2020 Report Posted March 3, 2020 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
Jason Fayre Posted March 3, 2020 Author Report Posted March 3, 2020 Hi, Thanks for this! That will probably help, but I don't understand why the values I'm getting are wrong.
spokes2112 Posted March 3, 2020 Report Posted March 3, 2020 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
Jason Fayre Posted March 4, 2020 Author Report Posted March 4, 2020 oh wow! I missed that one! Is that the same as subtracting the magnetic variation from the true heading? If so, I'll just use that.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now