Changing GPS co-ordinates into Degrees-Minutes-Seconds


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by FromTheCockpit View Post
    ...Seems little complicated for now.

    But I still wanted to ask you that how do I checksum the data in PIC? I mean my PIC gets everything in a string which is comming from the GPS in the first place. Why it is a number, what does this number do?

    Can you please put up the code you have done as it will be far far easier to understand somthing working than perform a reverse engineering technique on it. From a beginners point of view what you explained above about checksum has gone past way above my head.
    Well, I didn't post my code because I do something a little different. I convert from deg min.min to deg.deg so I can perform some math on the waypoints. My code is very ugly and sometimes confuses me.

    I think it is very helpfull for people to be able to write code, and "make it their own". That is the only way they will be able to progress, and really make the code do things they want. So I try to give enough data for people to start playing around with the parts of code. The link to MeLabs sites GPS code is a fully functional code that will not have to be reverse engineered. Only needs to be edited slightly to read different digits by changing the skip 34, and a few other small things.

    I suggest you ignore pretty much everything I have written below this line for now, and get your hands fully around the above code by playing around with the serin2 command, and seeing what you can get to print out to your computer.

    This is NOT the code that I suggest playing around with, but if you must see it, here is a snippet. Darrell and others would probably say they needed a lot of toilet paper and a few Amodiums to go with it. If after seing it, you don't get sick to your stomach, I will try to explain the garbage. I would not say it is advanced. It is just too messy to explain properly. There are a couple errors I need to fix, with a few parenthesis in the wrong place, etc.

    This is assuming you use an array called gpsdata.....
    Code:
            IF gpsdata[char_A] = "A" Then              'was 9, Needs to be 13 for EB-85A                                       
                lathome_hi = ((gpsdata[char_A+2] - 48) *10)+((gpsdata[char_A+3] - 48))
                lathome_low = ((((gpsdata[char_A+4] -48)*1000)+((gpsdata[char_A+5]-48)*100)+((gpsdata[char_A+7]-48)*10)+(gpsdata[char_A+8]-48))*5)/3
                    lathome_min = ((((gpsdata[char_A+9]-48)*10) + (gpsdata[char_A+10]-48))*5)/3    'lathome_min
                    lathome_min = lathome_min + 33*((((gpsdata[char_A+4] -48)*1000)+((gpsdata[char_A+5]-48)*100)+((gpsdata[char_A+7]-48)*10)+(gpsdata[char_A+8]-48))*5)//3
                    tempbyte = lathome_min /100
                    lathome_low = lathome_low + tempbyte
                    lathome_min = lathome_min //100
                if gpsdata[char_A+12]=78 then north =1         '="N"
                lonhome_hi = ((gpsdata[char_A+14]-48)*100)+((gpsdata[char_A+15]-48)*10)+(gpsdata[char_A+16]-48)
                lonhome_low = ((((gpsdata[char_A+17]-48)*1000)+((gpsdata[char_A+18]-48)*100)+((gpsdata[char_A+20]-48)*10)+(gpsdata[char_A+21]-48))*5)/3
                    lonhome_min = ((((gpsdata[char_A+22]-48)*10) + (gpsdata[char_A+23]-48))* 5)/3
                    lonhome_min = lonhome_min + 33*((((gpsdata[char_A+17]-48)*1000)+((gpsdata[char_A+18]-48)*100)+((gpsdata[char_A+20]-48)*10)+(gpsdata[char_A+21]-48))*5)//3
                    tempbyte = lonhome_min/100
                    lonhome_low = lonhome_low + tempbyte
                    lonhome_min = lonhome_min//100
                if gpsdata[char_A+25] = 87 then west = 1 'check to see if we are W or E char 87 = "W"

    Ok, now you got that, have your wife or girlfriend grab you another roll of toilet paper, and we will move on to checksums.....

    I also, purposely did not go into check sums. You really only need to worry about checksums if your life, or your equipment is at risk because of the way you are using your GPS data. The reason it can be important, is that the NMEA sentences can be rather long. The one you are working with is in the neighborhood of 70 to 80 characters, though I have not counted. There are plenty of chances that by transmission through wires, or wireless, that one bit here or there could be missed, giving you a completely different location. Your equipment might not realize there was an error, unless it compared the checksum from the gps to its own calculated checksum on the data received.

    Basically, the checksum is a sum of all the data in the NMEA sentence. It does something similar to adding up all the ascii codes.

    I have some example code from an RCAP autopilot project, but this too is not really important if you are not making an autopilot, a hazard avoidance product, etc. So it can pretty much be left out of the equation for most applications.

    Code:
    DoCS:
        i = 0                             ' Initialize the position counter
                    
        While gpsdata[i] != "*"           ' Count everthing until the *
            cs = cs ^gpsdata[i]           ' XOR for checksum
            i = i + 1                     ' Increment position counter
        Wend
    
        ' A quick and easy atoh function
        ' Make it a seperate label if we add more atoh conversions in the future
        LookDown gpsdata[i+1],["0123456789ABCDEF"],tempbyte
        gpscs = tempbyte * 16        
        LookDown gpsdata[i+2],["0123456789ABCDEF"],tempbyte                
        gpscs = gpscs + tempbyte
            
        ' Flag bad data "V" if checksum doesn't add up. 
        ' Or if the sentence is less then 20 chars long
        ' Which means there is no active waypoint to go to.
        ' Should be "A" otherwise.
        IF (cs != gpscs) OR (i < 20 )Then 
              gpsvalid = 0
        Else 
              gpsvalid = 1
        EndIF  
    
    Return
    Last edited by ScaleRobotics; - 27th October 2009 at 18:01.
    http://www.scalerobotics.com

  2. #2


    Did you find this post helpful? Yes | No

    Question

    You are right. Toilet paper is over now. I am going to play with the code for next day or two and will put my findings and problems here. Thanks for the advise.

  3. #3


    Did you find this post helpful? Yes | No

    Question back with results

    Hi, Ok, I have the following code now:

    STRING: $GPRMC,123339.000,A,5134.2770,N,00007.8480,E,1.14, 254.38,271009,,*09

    ab:
    DEBUGIN 2000,ab,[WAIT("$GPRMC"),skip 14,DEC2 ladeg,DEC2 lamin,skip 1,DEC4 lasec1,skip 3,DEC3 lodeg,DEC2 lomin,skip 1,DEC4 losec1]
    losec=lasec1 * 6 : lasec=lasec1 * 6
    pause 1000
    DEBUG "Lat ",DEC2 ladeg," Deg ", DEC2 lamin," Min ",DEC2 lasec," Sec ",10,"Lon ",DEC3 lodeg, " Deg ", DEC2 lomin," Min ",DEC2 losec," Sec ",13,10,10
    goto ab

    And the WRONG result on my screen is the following:
    Lat 51 Deg 34 Min 36 Sec
    Lon 000 Deg 07 Min 36 Sec

    Can you advise me please of what am I doing wrong here?

  4. #4


    Did you find this post helpful? Yes | No

    Talking I got it working

    I got the co-ordinates working now. Just wondering how to go about getting the speed into variable as it keeps changing, 1.14 knots now, may be 100.20 knots later!
    Last edited by FromTheCockpit; - 2nd November 2009 at 00:57.

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by FromTheCockpit View Post
    I got the co-ordinates working now. Just wondering how to go about getting the speed into variable as it keeps changing, 1.14 knots now, may be 100.20 knots later!
    That's great!

    To convert knots to Km/h:


    Code:
    knots var word 'xx.x knots is going to have to become xxx knots for this math
    kmph var word
    temp var word
    
    temp = knots * 1852            'first part of div32 function
    kmph = div32 1000              'this result should be printed out with one decimal
                                   'in other words result xxx should be printed as xx.x km/h
    so for above example, if you had 30.0 knots as speed then
    knots = 300
    temp = knots * 1852 = 555600

    (you may notice this is bigger than 16 bits, but that's ok. The div32 lets us have up to a 31 bit number, so not to worry).

    555600/1000 = 555

    So, the answer must be printed out in decimal as 55.5 km/h

    which is the pbp way to do knots * 1.852 = km/h
    Last edited by ScaleRobotics; - 2nd November 2009 at 03:34.
    http://www.scalerobotics.com

  6. #6


    Did you find this post helpful? Yes | No

    Question

    Code:
    knots var word 'xx.x knots is going to have to become xxx knots for this math
    kmph var word
    temp var word
    
    temp = knots * 1852            'first part of div32 function
    kmph = div32 1000              'this result should be printed out with one decimal
                                   'in other words result xxx should be printed as xx.x km/h
    How can I get xx.x into xxx as there is an "." in the middle and also the datasheet says about only one digit before decimal -Which I wonder WHY? as speed will become two digits once it goes above 9 knots. How do I use the SKIP in a problem like this where decimal will change place?

  7. #7
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by FromTheCockpit View Post
    How can I get xx.x into xxx as there is an "." in the middle and also the datasheet says about only one digit before decimal -Which I wonder WHY? as speed will become two digits once it goes above 9 knots. How do I use the SKIP in a problem like this where decimal will change place?
    I get what you are saying now. I think my gps example had a static xxx.x output, but most of the new (non handheld) ones (like yours) do not.
    This should do the trick, hopefully not too much trouble shooting involved.

    It reads in 5 characters to the array named raw_speed[x]. Then it counts decimal places to the "." character. Then adds the digits together after multiplying them by the right power of 10.

    Code:
    raw_speed var byte[5] 'create an array to put each possible character for speed
    i var byte
    decimal var byte
    speed var word
    
    DEBUGIN 2000,ab,[WAIT("$GPRMC"),skip 14,DEC2 ladeg,DEC2 lamin,skip 1,DEC3 lasec1,skip 4,DEC3 lodeg,DEC2 lomin,skip 1,DEC3 losec1,skip 4,raw_speed[0],raw_speed[1],raw_speed[2],raw_speed[3],raw_speed[4]]
    
    for i = 1 to 3
        'find which character is the decimal point
        if raw_speed[i]="." then decimal = i
    next i
    
    'combine single digits to form whole speed number. Varies from 0.0 to 999.0
    select case decimal 
             'if our gps gives us 1.4, then this will convert it to 14
             'the -48 is a way to convert an ascii number to a number
        case 1 'decimal is in x.x position
            speed=(10*(raw_speed[0]-48))+(raw_speed[2]-48)
        case 2 'decimal is in xx.x position
            speed=(100*(raw_speed[0]-48))+(10*(raw_speed[1]-48))+(raw_speed[3]-48)
        case 3 'decimal is in xxx.x position
            speed=(1000*(raw_speed[0]-48))+(100*(raw_speed[1]-48))+(10*(raw_speed[2]-48))+(raw_speed[4]-48)
    end select
    Last edited by ScaleRobotics; - 3rd November 2009 at 07:14.
    http://www.scalerobotics.com

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 09:47
  2. Virtual LED Clock For Windows By Trent Jackson
    By T.Jackson in forum Code Examples
    Replies: 8
    Last Post: - 10th November 2009, 08:20
  3. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  4. GPS clock timing !
    By bethr in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 3rd July 2008, 20:11
  5. DS1994 Memory/Time iButton
    By NavMicroSystems in forum mel PIC BASIC Pro
    Replies: 47
    Last Post: - 22nd October 2006, 11:55

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts