Jump to content
The simFlight Network Forums

Unexpected Value from Gyro Heading


Recommended Posts

Hello Mr. Dowson,

I don't know who else to turn to. I know you're not familiar with VB but if something stands out... I'd like your thoughts if you have the time and inclination.

I'm using VB to read FS Values through FSUIPC. I had another read section working once during an experiment, but now I'm getting none or strange results, so I can only conclude I've changed something somewhere.

I've been double checking, making sure I'm using the correct Data Types

If FSUIPC_Read(&H2B00, 8, VarPtr(RetResult), dwResult) Then

At first glance, does this look right? I have the RetResult and dwResult as Long

Here's the function...

Function FSUIPC_Read(dwOffset As Long, dwSize As Long, pDest As Long, ByRef dwResult As Long) As Boolean

The value I'm getting from RetResult is 2122637696 when the gryo is 359.65686 OR -1411192591 the the Gyro is 0.58321

I don't know what the VarPtr() does, but I get zero if I don't use it.

Do you need to see all of the codes to get the context?

I'd appreciate any ideas.

Thanks for your time and efforts,

Joe

Link to comment
Share on other sites

I've been double checking, making sure I'm using the correct Data Types

If FSUIPC_Read(&H2B00, 8, VarPtr(RetResult), dwResult) Then

At first glance, does this look right? I have the RetResult and dwResult as Long

I don't think "Long" is a 64-bit floating point value, but a 64-bit integer instead. I just googled it and came up with this:

Use the Long data type to contain integer numbers that are too large to fit in the Integer data type.

which certainly seems to confirm it.

Don't you have any VB references you can use to look up data types you don't know?

The value I'm getting from RetResult is 2122637696 when the gryo is 359.65686 OR -1411192591 the the Gyro is 0.58321

I'm not surprised since integer types cannot hold fractions at all. You are misinterpreting it altogether.

Surely you have some sort of help or documentation for VB? Otherwise how else do you manage to program it?

Regards

Pete

Link to comment
Share on other sites

I don't think "Long" is a 64-bit floating point value, but a 64-bit integer instead.

Gosh! I hate it when I make myself look stupid... Of course I can't use the Long type. There's an example I have, that reads the Latitude of the a/c. It uses the Currency type because it's a 64bit

Currency variables are stored as 64-bit (8-byte) numbers in an integer format, scaled by 10,000 to give a fixed-point number with 15 digits to the left of the decimal point and 4 digits to the right.

In my example they use the formulas...

Latitude = Fake64Bit * 10000#

Latitude = Latitude * 90# / (10001750# * 65536# * 65536#)

They had to force it to Double to avoid Overflow.

So by changing my receiving variable to Fake64bit as Currency and Heading as Double, using Heading = Fake64Bit * 10000# I get 4.64344496340982E+18

So now I just need to figure out what I need to do, to turn it into degrees.

Thanks for the reality check!

Link to comment
Share on other sites

I also tried this...

Dim Hi64bitValue As Double
Dim Lo64bitValue As Double
Dim dwResult As Long
Dim Heading As Double
                If FSUIPC_Read(&H2B04, 4, VarPtr(Hi64bitValue), dwResult) Then
                    If FSUIPC_Read(&H2B00, 4, VarPtr(Lo64bitValue), dwResult) Then
                        If FSUIPC_Process(dwResult) Then
                            Lo64bitValue = Lo64bitValue / (65536# * 65536#)
                            Heading = Hi64bitValue + Lo64bitValue
                            GF45Display(1).Caption = Format(Heading)

So now I get 5.34152294420603E-315

Link to comment
Share on other sites

Joe,

The currency (fake 64bit) ruse is for handling 64bit Integers. This is because VB6 and earlier does not have 64bit integers.

The offset 0x2B00 is marked in the documentation as 64bit Floating point, not integer. You therefore need a Double type variable to hold the data (ie, Dim RetResult As Double).

VB6 supports double types but I seem to remember you are using VB4 which might not, but try it and see.

Paul

Link to comment
Share on other sites

Gosh! I hate it when I make myself look stupid... Of course I can't use the Long type. There's an example I have, that reads the Latitude of the a/c. It uses the Currency type because it's a 64bit

The latitude and longitudes are actually 64 bit integers, so a 64-bit "Long" suits them perfectly. I think the Currency examples date to the version of VB where the Long was 32 bits -- or maybe it depends whether you are using a 64-bit or 32-bit compiler.

In my example they use the formulas...

Latitude = Fake64Bit * 10000#

Latitude = Latitude * 90# / (10001750# * 65536# * 65536#)

They had to force it to Double to avoid Overflow.

Ah. "Double" will be the 64-bit floating point -- in C/C++ it is called "double" too, just no capital. You really need any number which contains fractions as floating point, because integers cannot contain them.

So by changing my receiving variable to Fake64bit as Currency and Heading as Double, using Heading = Fake64Bit * 10000# I get 4.64344496340982E+18

So now I just need to figure out what I need to do, to turn it into degrees.

No, that is still completely wrong. no amount of messing with that will get it right! 64-bit floating point numbers are NOT integers x 10000. They have a sign bit, an exponent field and a mantissa field. Any other way of interpreting them will always be wrong!

Now you've found the VB 64-bit floating point variable name, why not simply declare the variable as double? Then you'll get it in degrees with no calculation needed whatsoever!

I'm sure you can look these things up in some VB reference somewhere. If you program in VB you should surely at least become wise about the different number formats it supports? The Intel and AMD processors support 32-bit and 64-bit processors in their mult-div sections. I'm pretty sure that all languages compiling for such processors support those types. In C/C++ they are "float" and "double" respectively.

Pete

Link to comment
Share on other sites

I have a few VB books, I mostly use the built-in help. I've never had to use these type of number/variables before so it's been a steep learning curve.

As suggested I changed my receiving variable to a Double and what do you know? It's working!

This humble feeling I have is powerful.

I knew that an integer didn't contain decimal points and since I wanted a heading without a decimal, I thought that's what I needed. Now I really know what a floating-point is, because the "decimal point" can be anywhere. Well, that may not be accurate, but the analogy works for me.

I want to thank you both, Pete and Paul. This lesson has been very valuable and I appreciate your patience.

By the way, what happened to Mary?

Link to comment
Share on other sites

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.