Jump to content
The simFlight Network Forums

0578 - Pitch Control


Recommended Posts

Hi,

Pete, I think there's a small error in the documentation...

0578, Pitch control:

FSInterrogate gives: 4,261,696,370 (-2.78874 Factored)

Documentation says: Pitch * 360 / (65546 * 65536). Ok, now let's do some math.

4,261,696,370 * 360 = 1,534,210,696,440

65536 * 65536 = 4,294,967,296

1,534,210,696,440 / 4,294,967,296 = 357.21 <-- A rather steap pitch, don't ya think? :shock:

However, subtracting 360 from the answer, gives me -2.79 (Yes, my HP Calc rounds it off).

Should the formula in the documentation thus not read:

Bank * 360/(65536*65536)-360 ?

Just want to make sure I get this right :)

--

Chris.

Link to comment
Share on other sites

Pete, I think there's a small error in the documentation...

No. In this case you are interpreting the value incorrectly as unsigned when, of course, pitch and bank (and magvar) are signed. Most of these angular values are given in the same units -- such that the maximum possible precision can be accommodated in the space available.

Documentation says: Pitch * 360 / (65546 * 65536). Ok, now let's do some math.

4,261,696,370 * 360 = 1,534,210,696,440

65536 * 65536 = 4,294,967,296

1,534,210,696,440 / 4,294,967,296 = 357.21 <-- A rather steap pitch, don't ya think? :shock:

It is -2.79. Draw a circle and plot its position. You'll see that. Pirch and Bank have to be signed as they can be up/down or left/right.

Should the formula in the documentation thus not read:

Bank * 360/(65536*65536)-360 ?

No, because then a position pitch or bank would turn out to be a big negative number.

Please used signed values where that is sensible, unsigned where that is sensible.

Regards,

Pete

Link to comment
Share on other sites

I am using signed Ints Pete... :(

Int32, 4 Bytes, 32-Bit, Signed Integer, and

Long, 8 Bytes, 64-Bit, Signed Integer (Which I have to use for the calculation, otherwise VB gets Overflow errors).

For interest sakes, http://www.startvbdotnet.com/language/datatypes.aspx

Result is always the same... When pitch is 4 Degrees UP, I get 356. When it should in fact be, -4. The strange part, is that it works for Bank, as well as MagVar (virtually the same code, just different offsets and formulas where needed). It's *just* pitch that's doing this...

VB does something strange to * 360 / ( 65536 * 65536 ). Before I do the calculation, my data from FSUIPC matches on the spot with the data that FSI2 gives. After the calculation, I sit with the wrong answer.

I'm starting to hate VB more and more now... Thanks anyways Pete (as always)... Time to go learn Delphi perhaps.

--

C

Link to comment
Share on other sites

I am using signed Ints Pete... :(

But 4,261,696,370 is not a possible number in 32-bit signed format. It is FE045372 in hexadecimal. The top bit is set (2^31) which is the sign bit. The value is actually -33270926 in decimal.

((-33270926 / 65536) * 360) / 65536 = -2.7887368 according to my calculator.

[My calculator has only 8 digits so to maintain accuracy I split the two divides as you see -- you could do the same to keep it all fitting into 32 bits. But it is best to convert to floating point in any case, keeps your fractions].

VB does something strange to * 360 / ( 65536 * 65536 ).

Well, if it started with a -ve number it must finish with one, else the compiler is in error. Sounds like, if you don't have a bug, Microsoft does!

Regards,

Pete

Link to comment
Share on other sites

  • 3 weeks later...
I am using signed Ints Pete... :(

VB does something strange to * 360 / ( 65536 * 65536 ).

Well, if it started with a -ve number it must finish with one, else the compiler is in error. Sounds like, if you don't have a bug, Microsoft does!

Regards,

Pete

Not really. If you put them up like that (in integer numbers) VB will treat the values as INTS (32-bit!) and calculating 63336 squared times 360 will cause a huge overflow. I use these formulas in floating point (adding a .0 after every number) which doesn't cause the compiler to overflow in the calculations. Worked for me in C# where it didn't work if I typed the code as integers.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • 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.