Sign in to follow this  
WarpD

GPS variable

Recommended Posts

Happy New Year everyone.I'm having a "problem".When trying to develop some gauges for a panel, I went to use the variables GPS_POSITION_LAT and GPS_POSITION_LON.The latitude works fine... however the longitude doesn't. So I created a couple of strings to display the values FS9 returns forPLANE_LONGITUDE -4653815.5GPS_POSITION_LON -847201280.0As you can see, they are not the same.Can anyone tell me:1) Why2) How do I get the correct longitude with GPS_POSITION_LON?Thank you.Ed Wilson

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Ed,I just tinkered with this a little, and...Plane_Longitude -4653815.5 * 11930464.71111 * 360 / (65536 * 65536 * 65536) = -71.01158905GPS_Position_Lon -847201280.0 * 360 / (65536 * 65536) = -71.01159096EasyGauge messes with the Plane Longitude by dividing it by 11930464.71111 I have the programmers edition; here is the code:FLOAT64 FSAPI callback3( PELEMENT_STRING pelement){float rwert=pelement->source_var[0].var_value.n;rwert=rwert / 11930464.71111;sprintf(pelement->string,"%014.0f PL",rwert);return 0;}Best regards,Doug Dawson

Share this post


Link to post
Share on other sites

Thank you.It's been driving me "insane" for a while now.Ed Wilson

Share this post


Link to post
Share on other sites

>EasyGauge messes with the Plane Longitude by dividing it by>11930464.71111 I have the programmers edition; here is the>code:>>FLOAT64 FSAPI callback3( PELEMENT_STRING pelement)>{float rwert=pelement->source_var[0].var_value.n;>rwert=rwert / 11930464.71111;>sprintf(pelement->string,"%014.0f PL",rwert);>return 0;}Now that's just plain bizzare! Why the heck does EG do such a silly thing? I've wasted hours on this problem. Thank God for the "Search" function here at AVSIM.COM! :)BTW, it's far easier to use the macro's in the gaugesFS2002.h file to 'translate' lat and lon into degrees:FS_LATITUDE_DEG ( PLANE_LATITUDEvar.var_value.n ) FS_LONGITUDE_DEG( PLANE_LONGITUDEvar.var_value.n ) ;

Share this post


Link to post
Share on other sites

BTW, "fixing" the PLANE_LONGITUDE variable in EG is as simple as editing the tokensFS2002.est file.Edit Record 101 to "Special=" and remove the silly "multiplier" they put in there! :)

Share this post


Link to post
Share on other sites

That's why I put them in. If you use the new fs9 gaugs.h make sure to copy those macros. I'm not sure, but there might be different factors for PLANE_.. and GPS_... .Arne Bartels

Share this post


Link to post
Share on other sites

>That's why I put them in. If you use the new fs9 gaugs.h make>sure to copy those macros. I'm not sure, but there might be>different factors for PLANE_.. and GPS_... .Hi Arne!Actually, Doug was referring to the code generated by EasyGauge. For some reason, "they" put some silly value into the tokenFS2002.est file (which is where they define FS token variables and their parameters that're used when the program "exports" the various .c, .h, .rc and G.c files for the compiler to use.They take the FS variable PLANE_LONGITUDE and divide it by 1930464.71111... :( Why they did that is anyone's guess, but it's dead wrong...I was simply telling Doug to edit the tokenFS2002.est file to remove the wrong value, and also to use the macros so thoughtfully provided... :)

Share this post


Link to post
Share on other sites

Hey Bill,It is not as silly as it looks. If you look at gps_info.h, which was already included in the 2002 SDK, you will find a function by the name of ANGL48_TO_DEGREES. This function takes a value in the ANGL48 format, multiplies it by 360, and divides it by 65536^2. If you invert 360/65536^2, you get 11930464.7111111.Since EG divides by 11930464.7111111, it is the same as multiplying by 360/65536^2, which is what ANGL48_TO_DEGREES does, so we are back full circle.So EG uses what MS uses also, just written in a float format. MS uses it in integer format since ints are much faster to do mathematical operations with. Floats are processed by the FPU (the math processor), which takes much longer than integers.P.S. Thanks to Oleksiy Frolov for the info on the floating point calculations

Share this post


Link to post
Share on other sites

Thanks Fabio, I figured that part out late last night. Unfortunately, it still will provide inconsistent and inaccurate values in many circumstances, especially when one wants to produce the final result as follows:Lat: N38

Share this post


Link to post
Share on other sites

It seems I working on a related project.In this tread there is a good discussion on the math to convert the Longitude but what about the Latitude?I've tried to rearranging the the functions in the SDK but I can't get the conversion factor worked out. Any help?

Share this post


Link to post
Share on other sites

latitude in degrees = PLANE_LATITUDE / 111130.555557Or even easier if you are working in C:lat_deg = FS_LATITUDE_DEG ( PLANE_LATITUDE ) ;To convert the lat_deg variable to dd:mm:ss format, simply keep dividing the fractional remainder by 60, as in the example below:51.42857143 --> 51 deg and 0.42857143*60 min --> 51 deg 25.7142858 min --> 51 deg 25 min and 0.7142858*60 sec --> 51 deg 25 min 42.857148 sec --> 51 deg 25 min 43 sec

Share this post


Link to post
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
Sign in to follow this