superdudes Posted March 4, 2010 Report Posted March 4, 2010 Hi There Was just wondering if someone could help me, I am trying to read the aircraft heading from FS. Ive set the variable up but having issues with converting it from raw to the heading! Could anyone post their code to do this or tell me what the conversion is! Many thnks Chris
Pete Dowson Posted March 4, 2010 Report Posted March 4, 2010 Ive set the variable up but having issues with converting it from raw to the heading! No one should need to tell you "what the conversion is!" as it is documented clearly where it should be. Are you not referring to any of the supplied documentation? Assuming you mean the aircraft heading in the 32-bit unsigned word ("DWORD") at offset 0580, then as documented that is converted to degrees by * 360 / (65536 * 65536) which simply means "multiply by 360 then divide by 65536 twice (or by 4294967296 once, which is the same thing)". Couldn't you find that? What documents are you using? Best to copy your DWORD value to a floating point variable first, otherwise you'll lose most of the value: double hdg = value_read; hdg = (hdg * 360.0) / (65536.0 * 65536.0); This gives you the heading in degrees TRUE. If you want MAG heading you also need to read the mag var from 02A0 and make the adjustment. Since the mag var is in the same units as the heading (only 65536 time less because it fits in a 16-bit WORD instead of a 32bit one), you'd best deal with that first. Assuming you read 0580 into the DWORD hdg_read, and 02A0 into magvar_read, and you'd do: DWORD value_read = magvar_read; // Place 16 bit value into 32 bit, ready value_read = value_read * 65536; // Make same units as heading hdg_read = hdg_read - value_read; // Convert hdg from TRUE to MAG // Now convert to degrees double hdg = hdg_read; hdg = (hdg * 360.0) / (65536.0 * 65536.0); Regards Pete
superdudes Posted March 4, 2010 Author Report Posted March 4, 2010 Couldn't you find that? What documents are you using? OK, Maybe I didnt expain everything correctly, but I did use the documentation provided and also the FS Intergrate program. double hdg = value_read; hdg = (hdg * 360.0) / (65536.0 * 65536.0); This is what I tired, however the actual heading value when it was between 360 and 180 was a few degrees out (which wasnt really a problem), it was when it went between 180 and 360 that I had the issues of a negative number
Pete Dowson Posted March 4, 2010 Report Posted March 4, 2010 This is what I tired, however the actual heading value when it was between 360 and 180 was a few degrees out (which wasnt really a problem) That sounds like you were comparing it with the MAG heading -- the difference will be the Magnetic Variation, as I explained. In the Seattle area it would be 20 degrees out, in some areas it would be completely accurate. If you want magnetic headings (as shown on your compass) you need to deal with the variation. it was when it went between 180 and 360 that I had the issues of a negative number It cannot possibly go negative if you use unsigned variables, as you should of course. However, if you look at a compass rose you would surely see that a heading of -1 is the same as a heading of 359, and so 0n, so all you have to do is add 360 to anything coming out negative. Though, as I say, since all this is unsigned it should never happen except by programming error. Pete
superdudes Posted March 4, 2010 Author Report Posted March 4, 2010 Ah right ok, thanks for the explanation ! Must have been a programming error on my point. Ive managed to get everything else working from the documentation no problems and just couldnt get this to work!
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