 |
 |
| View previous topic :: View next topic |
| Author |
Message |
talhahs
Joined: 14 Oct 2010 Posts: 14
|
|
Posted: Tue Mar 08, 2011 12:26 pm |
|
|
Hi John,
Yeah its a remote controlled UGV and I would like to add GPS to it so that I can get its lat and long tracked...just to make it look comprehensive...I would then show it up on satellite view using google maps in my VB GUI.
I am already done with its drive part, it currently uses Xbee modules and Hardware USART was in use. Data packets are small as you have seen the chars up in the code, VB 6 sends a char for every move.
Ok, I would have to change PC port to soft USART, i am still thinking whether I can buffer GPS sentences and extract lat,long so that its drive mechanism would remain unharmed (bcz it is in real time). |
|
 |
tr6coug
Joined: 31 Oct 2011 Posts: 1
|
|
Posted: Sun Nov 06, 2011 12:14 pm |
|
|
| ezflyr wrote: | Hi,
You might want to consider using a GPS "engine", rather than the eTrex unit. A number of good modules can be found at Sparkfun.com for around $50 USD. These modules typically have TTL interfaces, and the NMEA data stream can be configured.......
To exclude all but the desired string from your circular buffer, you can implement a "state machine" in your serial interrupt handler. It starts with a State = 0, and stores no characters in this state. Once the '$' character is received, this character is stored, and then State is incremented. With State = 1, the next character must be a 'G', and if so, the character is stored, and the state is incremented. With State = 2, the next character must be a 'P', and if so, the character is stored, and the state is incremented. If at anytime, you don't have a match, reset State = 0. Keep doing this until you have enough of the NMEA string to ensure you've got the correct one. At that State value, just store all the incoming characters until the 'CR' character is received, and then start all over.
You'll learn a lot more if you code it yourself, but here is a small code fragment from my ISR to get you going:
| Code: |
TempChar = fgetc(GPS);
switch (RxState)
{
Case 0:
if (TempChar == '$')
RxState++; //"$" received, so RxState = 1
break;
Case 1:
if (TempChar == 'G')
RxState++; //"G" received, so RxState = 2
else
RxState=0; //wrong character received, so we reset RxState
break;
|
John |
Wow, thanks. That really solved my problem of filtering out the GPRMC sentence.  |
|
 |
bkamen
Joined: 07 Jan 2004 Posts: 1619 Location: Central Illinois, USA
|
|
Posted: Sun Nov 06, 2011 12:31 pm |
|
|
For what it's worth...
I do something very similar in my GPS Serial ISR where I start saving the string at the start when the $ is received... (rather than just a ring buffer)
When the string is done, the ISR sets a flag and stop collecting.. (I use more than one string, so I can't use the ISR to filter unless I want to make it arguably long - remember, ISR's should be simple!)
My entire ISR looks like this:
| Code: |
#INT_RDA
void isr_gps ( void ) {
unsigned char c;
gps_timeout = GPS_TIMEOUT_VALUE;
c = rcreg;
switch (gps_state) {
case 0: if (! gps_have_packet) {
if (c == '$') {
gps_index = 0;
gps_string[gps_index] = c;
gps_index = 1;
gps_state = 1;;
}
}
break;
case 1: gps_string[gps_index] = c;
if ( (c == 0x0A) || (c == 0x0D) ) {
gps_have_packet = 1;
gps_string[gps_index + 1] = 0;
gps_state = 0;
}
if ( gps_index >= sizeof(gps_string)-1 ) {
gps_string[gps_index + 1] = 0;
gps_have_packet = 1;
gps_state = 0;
} else {
gps_index++;
}
break;
default: gps_state = 0;
break;
}
}
|
if life were timing critical, I would set up 2 buffers to allow the ISR to ping-pong between them.
but it's not..
So....
In the main loop, an IF catches the signal and sends the string to be processed.
From there, The processing function immediately makes a copy and releases the ISR to continue capturing.
Then compares the first field all the $GP strings of interest) against a const string array with the items I want to process and I copy them to a temp string one by one and then use strcmp() via strtok().
From there, based on which string found, process the rest of the fields accordingly.
A little different, definitely more code, but then I'm also processing more strings.
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|