string/decimal question
mikea
Posts: 283
in Propeller 1
In the gps objects, why are coordinates converted and displayed as strings and not just left as decimals?
term.str(gps.s_longitude) 'gps basic demo ///////////////////////////////////////////////////// DBG.Str(STRING(" Latitude in degres as FLOAT : ")) 'gps float lite demo fv := GPS.Float_Latitude_Deg IF fv <> floatNaN DBG.Str(FS.FloatToString(fv))
Comments
So every good NMEA GPS follow the NMEA protocol.
You get first asci strings out of the NMEA GPS.
If you want to do math, you have to convert to decimal or floating.
www.fcc.g
Mike
floatval := FDiv( FFloat(fromStr(str)) , 100)
-Phil
Mike
We're talking about the Propeller here, and it does not have a floating-point processor. Moreover, your comment about "cryptic fixed point math that doesn't work" is way off the mark. Floating-point math has precision and round-off issues that the casual user -- regardless of its so-called "simplicity" -- can get trapped by. If you can define units for which integer precision is adequate (in my case microdegrees), you're way better off using integer math.
-Phil
-Phil
Sending it the coordinates 3848.7563,N,12117.7583,W results in 4414593 x -12196263.
I took a closer look at the get_udegrees method and something looks off.
fds.dec(get_udegrees(string("0600.0000"),"N")) results in 1_000_000
fds.dec(get_udegrees(string("1000.0000"),"N")) also results in 1_000_000
mikea,
I'm a little late to the party, but I just uploaded this single cog GPS receiver / parser / converter to the obex, written in PASM with a Spin handler. In addition to ASCII strings, it also provides lat and lon in minutes (degrees x 600_000 + minutes to 4 decimal places), and in degrees/decimal minutes x 10_000.
The string sent to get_udegrees needs to be in this format:
ddmm.mmmmm
i.e. five decimal places for the minutes, not four. If your GPS only returns four, then get_udegrees will need to be changed. Sorry for the mix-up. It was tailored for my GPS, but I should've made it more general-purpose.
-Phil
It should accept strings of any length in the form ddmm.m... or dddmm.m..., where the number of decimal places in minutes is computed by the method instead of being fixed.
-Phil
A GPS that returns minutes to five decimal places is precise to 1.67 microdegrees, so there's no loss of precision in converting to that integer scale from such a device.
-Phil
Thanks for that trivial info. Never really thought about it, other than 1 minute is 1nm at the equator for longitude and anywhere for latitude - essential facts for ocean sailing
One minute of latitude = 1.84 km or 1.15 miles, according to http://longitudestore.com/how-big-is-one-gps-degree.html
1nm is in the x ray band of wavelengths (0.01nm to 10nm).
I think Ray meant Nautical Mile (NM).
LOL, I thought it was probably something like that, but not being much of a sailor nautical miles did not occur to me. On the plus side I now know the how and why of the nautical mile.
-Phil
And the history according to Wikipedia: https://en.wikipedia.org/wiki/Nautical_mile#History
Heh, a bit further down it mentions that the degrees of latitudes aren't exact NM either due to Earth not being completely spherical.
-Phil
IIRC Hawaii moved 0.5 miles on the map when we got GPS. Cruise ships never had a problem finding it tho, even before GPS.
-Phil
Still think navigating up/down the coast using land formations is quite scary. I couldn’t really recognise landforms reliably. Did this before i got GPS on my boat. Just used paper charts to navigate. Now the GPS and electronic charts are so nice. But there are inaccuracies in those charts still.
Reported a bug years ago that when you zoomed in a rock outcrop disappeared from the chart. Big trap for the unwary!
https://edwilliams.org/avform.htm
That site is a goldmine. It has been bailing me out of spherical trig problems for better than 20 years and is the basis of my GPS libraries.