Latitude/Longitude Conversions

I feel really dumb asking this, but I swear I've been looking all over the web and I can't find a definitive answer. Every website I find tells me how to convert from degrees/minutes/seconds to decimal degrees, but the Parallax GPS receiver outputs its data in degrees/minutes/fractional minutes, and I'm not sure how to convert this to decimal degrees.I looked at Chris's source code for the Geocrawler 3 but I'm pretty tired right now and can't figure out how to convert his integer method into a floating point method. He multiplies the minutes by 1,000 and divides it by 6, then divides the fractional minutes by 60 and adds them together. I can't figure out how to do this with floating point math (i.e., not multiplying the minutes by 1,000 and just doing a straight conversion).Any suggestions?(Also, the whole minutes are being stored in a byte, while the fractional minutes are stored in a word. So for example 39.2838 would be two separate variables, 39 and 2838, how would I account for the fact that the fractional minutes are now an integer?)

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Thanks Chris, I read the documentation but overlooked the fact that the conversion method was actually in the source code itself. I actually remembered the original reason why I didn't want to use your method with the FPU and then realized that doing it that way would still retain its original precision, so I'll just stick with that.

    Thanks again, this site is really a great resource.
  • Thanks Chris, but could you tell me how you would do it by hand? Like, to convert from DMS you would divide the minutes by 60 and the seconds by 3600 and add them together, but how would you do this for degrees/minutes/fractional minutes (omitting the degrees, and taking into account that the fractional minutes is an integer)?

    I am fairly confident that I can code it without a pseudocode example, but I don't know how a human would do the conversion in the first place.

    (I also don't want to use standard NMEA format, since it looks a little daunting and smart mode suits my needs)
  • I'm storing the result in the FPU's memory registers to save variable space on the Stamp, so I figured I'd do it the old fashioned way (how you would do it with a pencil, paper, and calculator) since that's how I planned it out. Working with different data types (bytes, words, etc) is a foreign concept to me so converting it to a new format might complicate things.

    I follow what you're saying up until the last paragraph, but I guess I'm too tired. I'll take a look at it in the morning :)

    Thanks Chris
  • 3D Robotics
    I don't think you need a floating point processor for this one. In an hour or so I'm going to post a integer method for this using the EM406 GPS that outputs Lat/Lon in the standard ddmm.mmmm format, which is to say ddmm is one word and mmmm is another. Then we just bit shift this so the least significant eight bits of the first word become the most significant eight bits of result word, and the most significant eight bits of the second word become the least significant bits of the result word. Like this:

    If the GPS output of ddmm.mmmm is recorded as word1.word2, then:

    word1 = word1 & %0000000011111111 'only keep least sig 8 bits
    word2 = word2 & %1111111100000000 ' only keep most sig 8 bits
    word1 = word1 << 8 ' shift left 8 bits
    word2 = word2 >> 8 ' shift right 8 bits
    result = word1 + word2 ' combine

    So a Lat of 37.790388 would read as 3779.0388 which would translate into a word that's something like 17904 (truncate the top 37 into 1, truncate the bottom 388 into 4). That should be enough precision for navigation within a few hundred mile range.
This reply was deleted.

Activity