Jump to content

GPS code translator


JonBMN
 Share

Recommended Posts

I have a program that opens up the COM5 port of a usb GPS that spits GPS codes like

$GPGGA,151735.000,4103.4706,N,08515.8331,W,1,08,0.9,276.5,M,-33.7,M,,0000*64

$GPGSA,A,3,28,07,11,19,08,06,26,13,,,,,1.7,0.9,1.4*35

$GPRMC,151735.000,A,4103.4706,N,08515.8331,W,0.51,70.27,110912,,,A*47

$GPGGA,151736.000,4103.4707,N,08515.8330,W,1,08,0.9,276.1,M,-33.7,M,,0000*63

$GPGSA,A,3,28,07,11,19,08,06,26,13,,,,,1.7,0.9,1.4*35

I'm trying to translate them into their actual usage.. ie...

$GPRMC-Recommended minimum specific GPS/Transit data

144102.803-time stamp

A- validity- a=ok, v=invalid

4103.4634- current latitude

N- north or south

08515.8030- current longitude

W-east or west

0.00-speed in knots

blank- true course

110912- date stamp

blank- variation

blank- east or west

a*60- checksum

I'm having a hard time starting this because I've scoured the internet and not seen a thing on it(I don't know if I was looking in the right place, but I couldn't seem to find anything on the subject.)

I've started it translating using strings, but I'm not sure how to make it so when it gives different numerical values it just reads 000000.000 and not just 144102.803

If anyone can give me some pointers I'd greatly appreciate it!

At this point I've got what I need to to decode GPS signals; now I need help understanding using trigonometry to find the MPH from the Latitude and Longitude. If I could have some help understanding how to do this it would be greatly appreciated.

Edited by JonBMN
Link to comment
Share on other sites

  • Replies 44
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

This link might get you started.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

And as far as the parsing goes, you can safely StringSplit each string on the comma and loop through the resulting array.

Local $aGPS = StringSplit('$GPGGA,151735.000,4103.4706,N,08515.8331,W,1,08,0.9,276.5,M,-33.7,M,,0000*64', ',')
For $i = 1 To $aGPS[0]
    ; Do something with the entry. If it's blank insert a default value or skip it.
Next

...but I'm not sure how to make it so when it gives different numerical values it just reads 000000.000 and not just 144102.803

I do not quite understand what you mean by this...

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Link to comment
Share on other sites

Thank you BrewManNH, great refences.

to dany..

Great code, but with GPS codes they change as in where you are by longitude and latitude lets say you are at 144102.803 and move to 133453.463 your stringsplit would not work because the values have changed.

Link to comment
Share on other sites

They also have something called a timestamp. This will change depending on what time of the day it is. I want to make it so the the substring timestamp value gets put into a variable and is then parsed from the old string and created into a new string that reads something like timestamp=1124123.

Don't know if that was syntactically correct, but I hope you get the idea.

Link to comment
Share on other sites

To your last two posts: Yea well obviously :) I mean pull the string from that USB device into a variable and StringSplit that and not something hardcoded off course. I just gave a basic example, nothing more.

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Link to comment
Share on other sites

What exactly are you trying to get from the string and what do you plan on doing with it once you get it? Understanding how it's going to be used is important to figuring out how you want it presented to you. Right now, we know you need the string split into it's component parts, a simple stringsplit with the comma as a deliminator as dany showed is the easiest way to get it into an array, but we have no idea what you're going to do with it once it's been split.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I was trying to create variables in all the funtions to catagorize the gps code into readable text that anyone can read. I've parsed it so I can choose each catagory by variable name, but I want to create some funtions that take the last longitude and latitude and current lat and long and make it so they find the distance between how far you've traveled. Also create a timer that calculates that distance with a time then make it into mph.

Link to comment
Share on other sites

The time part is simple using the information you received from the GPS signal. The distance part is going to take a lot of math to accomplish and I'm not 100% sure that AutoIt has the precision needed, but should be close enough. Here is a site that gives you all the math in all of its glory.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The speed is already given by the GPS. No need to calculate it. It is the 8th data from the GPRMC sentence. In your example, it is 0.51. This is in Knots. Multiply this by 1.150779 to get Mph or multiply it by 1.852 to get Km/h.

This would give a speed of 0.94 Km per hour. In fact, the GPS is probably not moving at all. You will see some very small variations on the Latitudes, Longitudes, speed and on some other datas too when the GPS is not moving. This is normal and, if I remember well, even my 2 GARMIN handheld GPS are doing the same. (On edit, I just check one of my Garmin GPS and the speed can show a few Km/h when it is not moving.)

Have a look at my thread to see how I retreive the GPS datas using Autoit.:

Edited by AlainB
Link to comment
Share on other sites

I do have another question. I'm trying to calculate the distance from the starting lat long and ending lat long but really don't know how to save a the beginning and then the programming knowing when the end is. The math is going to be simple for me, but the problem I'm having is how to get $LastLongitude to keep its value from the beginning of going somewhere and then plugging in current to find the distance.

Link to comment
Share on other sites

Post the code you have so far, it's easier when we can see how you're storing and updating the variables.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create a function that returns the GPS data, and return them to seperate, split variables. Or create a 2D array, and enumerate the different returns

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Most Console writes are for debugging, that's why they're commented out. but I've created the variables to do this, I just don't know how to implement.

AutoItWinSetTitle("ArchangelProgram")
AutoItSetOption("MouseCoordMode", 1) ;1=absolute, 0=relative, 2=client
AutoItSetOption("MustDeclareVars", 1)
#include-once
#include
Opt("TrayMenuMode", 1)
HotKeySet("{ESC}", "Quit")
$Debug = False
Global $CommPort = "COM5", $Baudrate = 4800, $Received, $GPSHeader, $CurrentLongitude, $CurrentLatitude, $LastLongitude, $LastLatitude, $LastTime, $CurrentTime, $Longitude, $Latitude
$HerbieError = True
While 1 ; Haven't accounted for Under/Under
If $HerbieError = True Then
InitializeCommunications()
EndIf
$Received = _CommReceiveString(100, 5000, @CR)
$GPSHeader = Parse()
if $GPSHeader == "$GPGSA" Then
DecodeGPGSA()
EndIf
if $GPSHeader == "$GPRMC" Then
DecodeGPRMC()
EndIf
if $GPSHeader == "$GPGGA" Then
DecodeGPGGA()
EndIf
if $GPSHeader == "GPGSV" Then
DecodeGPGSV()
EndIf

;ConsoleWrite($Received & @CR)
Sleep(500)
WEnd
Func Quit()
If $SerialPortHandle <> -1 Then
_CommClose()
EndIf
Exit
EndFunc

Func DecodeGPGSA()
Local $AMode, $2Mode, $blank1, $blank2, $blank3, $blank4, $blank5, $blank6, $blank7, $blank8, $blank9, $blank10, $blank11, $blank12, $PDOP, $HDOP, $VDOP
$AMode = Parse()
$2Mode = Parse()
$blank1 = Parse()
$blank2 = Parse()
$blank3 = Parse()
$blank4 = Parse()
$blank5 = Parse()
$blank6 = Parse()
$blank7 = Parse()
$blank8 = Parse()
$blank9 = Parse()
$blank10 = Parse()
$blank11 = Parse()
$blank12 = Parse()
$PDOP = Parse()
$HDOP = Parse()
$VDOP = Parse()
;ConsoleWrite($AMode & $2Mode & $blank1 & $blank2 & $blank3 & $blank4 & $blank5 & $blank6 & $blank7 & $blank8 & $blank9 & $blank10 & $blank11 & $blank12 & $PDOP & $HDOP & $VDOP & @CR)
EndFunc
Func DecodeGPRMC()
Local $TimeStamp, $Validity, $LatitudeRMC, $NorS, $LongitudeRMC, $WorE, $Knots, $TrueCourse, $DateStamp, $Variation, $EorW, $Checksum
$TimeStamp = Parse()
$Validity = Parse()
$LatitudeRMC = Parse()
$NorS = Parse()
$LongitudeRMC = Parse()
$WorE = Parse()
$Knots = Parse()
$TrueCourse = Parse()
$DateStamp = Parse()
$Variation = Parse()
$EorW = Parse()
$Checksum = Parse()
;ConsoleWrite($TimeStamp & $Validity & $Latitude & $NorS & $Longitude & $WorE & $Knots & $TrueCourse & $DateStamp & $Variation & $EorW & $Checksum & @CR)
EndFunc
Func DecodeGPGGA()
Local $UTCposition, $NorS, $EorW, $QualityIndicator, $SatellitesInUse, $HorizontalDilution, $SeaLevel, $Meters, $GeoidalSeparation, $MetersSep, $SecLastUpdate, $StationIDchecksum
$UTCposition = Parse()
$Latitude = Parse()
$NorS = Parse()
$Longitude = Parse()
$EorW = Parse()
$QualityIndicator = Parse()
$SatellitesInUse = Parse()
$HorizontalDilution = Parse()
$SeaLevel = Parse()
$Meters = Parse()
$GeoidalSeparation = Parse()
$MetersSep = Parse()
$SecLastUpdate = Parse()
$StationIDchecksum = Parse()
;ConsoleWrite($UTCposition & $Latitude & $NorS & $Longitude & $EorW & $QualityIndicator & $SatellitesInUse & $HorizontalDilution & $SeaLevel & $Meters & $GeoidalSeparation & $MetersSep & $SecLastUpdate & $StationIDchecksum & @CR)
;ConsoleWrite($SeaLevel & @CR)
EndFunc
Func DecodeGPGSV()
Local $MessagesCycle, $MessageNumber, $TotalSVs, $SVprn, $ElevationDegrees, $TrueNorth, $SNR, $SecondSV1, $SecondSV2, $SecondSV3, $SecondSV4, $ThirdSV1, $ThirdSV2, $ThirdSV3, $ThirdSV4, $FourthSV1, $FourthSV2, $FourthSV3, $FourthSV4
$MessagesCycle = Parse()
$MessageNumber = Parse()
$TotalSVs = Parse()
$SVprn = Parse()
$ElevationDegrees = Parse()
$TrueNorth = Parse()
$SNR = Parse()
$SecondSV1 = Parse()
$SecondSV2 = Parse()
$SecondSV3 = Parse()
$SecondSV4 = Parse()
$ThirdSV1 = Parse()
$ThirdSV2 = Parse()
$ThirdSV3 = Parse()
$ThirdSV4 = Parse()
$FourthSV1 = Parse()
$FourthSV2 = Parse()
$FourthSV3 = Parse()
$FourthSV4 = Parse()
;ConsoleWrite($MessagesCycle & $MessageNumber & $TotalSVs & $SVprn & $ElevationDegrees & $TrueNorth & $SNR & $SecondSV1 & $SecondSV2 & $SecondSV3 & $SecondSV4 & $ThirdSV1 & $ThirdSV2 & $ThirdSV3 & $ThirdSV4 & $FourthSV1 & $FourthSV2 & $FourthSV3 & $FourthSV4 & @CR)
EndFunc
Func Parse()
Local $CommaPos, $Result
$Result = ""
$CommaPos = StringInStr($Received, ",")
If $CommaPos == 0 Then
Return $Result
EndIf
$Result = StringLeft($Received, $CommaPos - 1)
$Received = StringRight($Received, StringLen($Received) - $CommaPos)
Return $Result
EndFunc
Edited by JonBMN
Link to comment
Share on other sites

First, your Parse function should be returning an array of the string received, and then you won't have to call it 10 times for each variable. Plus, you won't have to keep deleting sections of the $Received string for each piece, very inefficient.

Second, unless you're 100% sure that the header strings are always going to be in uppercase, you shouldn't be using a case sensitive string comparison to check them.

Third, if you're recording a start position, you should create variables that hold the Lat/Long of the start position and never alter it until you want to update your start position. Just update the current Lat/Long and compare them to the original values.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

First, I understand but I'd like to finish this program before I start doing major changes(Understanding every part; then I can go on to creating arrays etc..)

Secondly I'm 100% sure.

Third, I have created variable to do this, it was to ask how I would implement them. ie an example

Thank you

Link to comment
Share on other sites

I can't really give you an example because I don't see anywhere in your code where you're trying to find a start position and checking it against a new position. You want to get a reading of a longitude, and then assign it to a variable called (for example) $StartLongitude, then as you're moving you update the current position and assign it to a new variable called (for example) $CurrentLongitude, do the math on the difference between $StartLongitude and $CurrentLongitude to get the distance travelled. If you are wanting to create waypoints along the way, then you're going to need to store those in variables, or better yet an array, and update as required.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

BrewManNH you are very knowlegable but I have to reitterate this again. I have included variables that do this if you look in the 11th line global variables include $CurrentLongitude, $CurrentLatitude, $LastLongitude, $LastLatitude, $LastTime, $CurrentTime

Also, I do not understand how to do this, this is why I'm asking for an example. I don't know how to make a variable hold a certain number when the gps codes constantly update it. So, to be as specific as possible how do you make the $LastLongitude hold its value while the program is running. I'm not asking you to go try and find this function in my code because I don't have it ie I have no idea how to make it.

Edited by JonBMN
Link to comment
Share on other sites

You need TWO variables, one that holds the starting position, and one that gets updated while you're moving. Just assign the values of the longitude or latitude to the starting position variable once, then you update the current position by assigning the Lon/Lat to the second variable. The following is about as simple as I can make it.

;example of how to update variables
$Start = 0 ; my starting position
$Current = $Start
For $I = 1 To 1000 ; this simulates you moving 1000 steps
     $Current = $I ; this simulates the current latitude/longitude
     If $Current <> $Start Then
          ConsoleWrite("My current position is " & $Current & @LF & "I have moved " &  $Current - $Start & " steps since beginning" & @LF)
     EndIf
Next

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...