January
2001, Issue 126
Where's
Waldo?
Pinpointing
Location by Interfacing with a GPS Receiver
APPLYING
GPS
At
this point, you can begin to appreciate the amount of
computational power a GPS receiver is capable of. I
have a TF10 GPS receiver that uses a GPS-1MAL active
antenna from Laipac Technology. The default TTL serial
output is all six National Marine Electronics Association
(NMEA) messages. Every piece of data Im interested
in is contained in the RMC. The RMC data format is an
ASCII string consisting of this information: message
ID, UTC, status, latitude, N/S indicator, longitude,
E/W indicator, speed, course, date, magnetic constant,
and checksum<CR><LF>.
I
found myself thinking about several situations where
this information could be helpful. This project takes
the GPS receivers ability to pinpoint locations
along with the cell phones ability to communicate
with a home computer in a wireless fashion to create
a wireless vehicle tracker. This project could be used
to locate a stolen vehicle or to simply track a number
of delivery vehicles at any time.
Take
a look at Figure 3. A PIC
micro is used to absorb the data output from the GPS.
To simplify the software, I used the PicBasic Pro Compiler
from microEngineering Labs. So, I could use any port
pin for serial transmission and reception. This has
advantages (can use true or inverted data levels) and
disadvantages (software serial means no interrupts).
However, you dont need multiple functions happening
at once, so this approach should work well.
Follow
the program flow shown in Figure 4. This project has
five basic operationswait for an alarm, monitor
GPS output, dial the modem, send a message, and determine
what to do next. The alarm is an input port bit with
internal pull-ups enabled. A simple switch to ground
(or a logic 0 signal) activates the alarm and causes
the program to exit this loop.
|
|
| Figure 4This
flowchart reveals the operations necessary for this
project. The use of subroutines simplifies the program.
LEDs indicate when the program is in various routines,
aiding both visual status and debugging. |
The
4800-bps TTL GPS output comes straight into the PIC.
From my office window, the GPS can pick up enough satellites
to make a positive location fix in less than 1 min.
The software monitors the serial datastream until a
$GPRMC message ID match occurs. This subroutine returns
indicating success or failure. If no serial data is
received, then the GPS is reset and the routine is called
again. If the data is bad or no fix has been determined
yet, the routine is called again. If a fix has been
established, then the program continues.
If
the modem is already connected (i.e., in continuous
location reporting), the dialing routine is skipped.
However, because this is the first time through here,
the PIC uses the AT command set to dial a stored number.
This is a local number and it covers a wide area. If
the vehicle enters an area outside the local cell exchange,
the number needs to be changed to include the area code.
I didnt bother to code in an alternate number
to use when you cant connect to the local number;
this and some other advanced features are left to the
experimenter. There are a number of responses the modem
can return when a number is dialed. The connect response
(actually C) allows the program to proceed. All other
responses allow the program to hang up the modem to
try dialing again.
After
a connection is made, a message is sent to the modem
(and the called computer). Heres an excerpt from
that message:
FTB126auto locatorJeff Bachiochi
10/18/2000
UTC = 18:04:56 latitude = N41 52 04
longitude
= W072 26 52
MPH = 0 last heading = 150° 10/19/00
The
time of day is based on GMT. You need to adjust the
hours depending on your earth position. Knowing the
longitude, you might even wish to adjust this automatically,
although this may get complicated considering daylight-savings
adjustments.
When
the message has been sent, the program will make one
of three branches. If the continuous input is strapped
low, the modem connection is maintained indefinitely
and the program loops back to obtain a new GPS fix.
If the continuous input is high and the WAIT_HOUR input
is strapped low, the modem hangs up and the program
goes into a count-off-every-hour loop. After an hour,
the program loops back to check the alarm input again.
If both continuous and WAIT_HOUR inputs are high, the
program immediately jumps back to check the alarm input
again.
The
difference between this mode and the continuous mode
is that the modem hangs up here and the alarm is monitored.
In continuous mode, when the alarm triggers, the modem
remains connected and the alarm input is no longer monitored.
Choose the appropriate mode carefully, because cell
phone use adds up. Of course, if your car was stolen,
youd want to get a position fix ASAP. Talk time
is cheap compared to a lost or damaged vehicle.