The simFlight Network Forums

# Offset 0570 (altitude) conversion

## Recommended Posts

Hi guys!

Sorry for this rather stupid question... :-)

Could anybody here give me a hint how to convert the ALTITUDE values obtained from offsets 0570/0574 into one precise value? I am using VB6 and simply can't find the correct way to combine the HIGH 32-bit integer and the LO 32-bit integer into one precise value...

Any help would be highly appreciated!

Thanks a lot!

Speedbirdie ;-)

##### Share on other sites

Hi Speedbirdie,

You can calculate aircraft altitude (ft, AMSL) with the following VB code

Public Const FtToM as double=0.3048 (in the declaration section of any module)

Dim AltLow as long (long at &H570)

Dim AltHigh as long (long at &H574)

Dim td as as double (temp variable)

Dim AltAMSL as double (result, ft)

td=CDbl(AltLow)/65536/65536

If td<0 then td=td+1

AltAMSL=(CDbl(AltHigh)+td)/FtToM

Hope it will do your job

Hervé

##### Share on other sites

You can calculate aircraft altitude (ft, AMSL) with the following VB code

Just watch out when the altitude is negative (which it won't be often, but it is possible in some parts of the world). Test the High part for < 0 and if it is you need to take extra steps because both parts are negative but only the high part is signed. I don't know VB enough to code it for you.

Compilers that support 64 bit integers ("long long" or "_int64") types are an advantage in these cases.

Regards,

Pete

##### Share on other sites

Hi Herve and Pete!

When using Herve's code I have one problem: the calculated altitude in feet is not really "precise", in fact it changes in steps of about 3 feet. I guess that's due to the ALT->FT conversion, but is there a way to correct this and calculate the *precise* altitude value?

Best Regards,

Speedbirdie

##### Share on other sites

When using Herve's code I have one problem: the calculated altitude in feet is not really "precise", in fact it changes in steps of about 3 feet. I guess that's due to the ALT->FT conversion, but is there a way to correct this and calculate the *precise* altitude value?

It should be precise -- the "about 3 feet" is probably one metre (3.28084 feet). The High value of the Altitude (the 32-bit integer at offset 0574) is in metres. The Low value, the 32-bit (unsigned) integer at 0570 is in units of 1/65536ths of a metre, or about 0.00005 feet (though I doubt if it ever goes that accurate).

It sounds like you are not reading, or are losing somewhere in the calculation, the fractional part of the value.

Of course, measuring an aircraft's altitude to the exact millimetre or inch is a bit daft without defining it more in any case -- where are you measuring it from? The pilot's eye, the centre of the prop, the CofG? I don't usually bother with the fraction myself, the value in metres seems quite adequate for most purposes.

Regards,

Pete

##### Share on other sites

Pete,

thanks very much! You were absolutely right...there was a stupid little typo in my VB6 code which caused the calculation loose the fractional part. Corrected now and working. Perfect!

Many, many thanks!

Speedbirdie

##### Share on other sites

Just a thought.... somewhere in the fsuipc sdk there's a VB example how to get the LAT of an aircraft with one 64 bit variable: currency. Maybe that can be used for this as well

Ray

##### Share on other sites

Oh well, maybe that's worth a try! Hope I will be able to find the VB6 code example you mentioned! :-)

Thanks for the hint!

Speedbirdie

## Create an account

Register a new account

×

• #### Activity

×
• Create New...