Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

ArGPS Class Reference

#include <ArGPS.h>

Inheritance diagram for ArGPS:

ArNovatelGPS List of all members.

Detailed Description

GPS Device Interface.

Connects to GPS device over a serial port or other device connection and reads data. Supports GPS devices sending standard NMEA format data (specifically the GPRMC, GPGGA, GPGSA, GPGRME, and optionally PGRMZ, PGRME, and HCHDG messages). If your GPS device supports several data formats or modes, select NMEA output in its configuration.

The preferred method of creating and setting up a new ArGPS object is to use ArGPSConnector, which creates an instance of ArGPS or a subclass, and creates and opens its device connection, based on command-line parameters. (To manually create an ArGPS object, create an ArDeviceConnection instance and call setDeviceConnection(), then open that device connection and call connect() or blockingConnect().)

For either method, to get new data from the GPS, must call read() periodically, ideally at a rate equal to or faster than your GPS sends data (usually one second). read() returns flags indicating whether it received partial data from the GPS, a complete "message" of data that it used to update stored data, or an error. You can use an ArRobot synchronized task callback functor to call read(), or you can run a loop in a new thread. If you are calling read() from a loop in a new thread, the loop ought to include a call to ArUtil::sleep() for at least several hundred miliseconds to avoid starving other threads, since read() will return immediately if there is no data to read rather than blocking.

See also:
gpsExample::cpp
This class is not thread safe. Stored data is updated by read(), so you can use an ArMutex to lock around data accessors (the getXXX methods) and also around calls to read().

Note:
ArGPS only provides access to the data reported by a GPS. The position reported by a GPS is in degrees on the surface of the earth, not in the cartesian coordinate system used by the robot odometry or ArMap, and Aria does not yet provide mechanisms for registering and projecting maps geographically or transforming positions between the two coordinate systems.
Examples:

gpsExample.cpp.

Definition at line 78 of file ArGPS.h.

[NOHEADER]

enum  FixType {
  NoFix, BadFix, GPSFix, DGPSFix,
  PPSFix, RTKinFix, FloatRTKinFix, DeadReckFix,
  ManualFix, SimulatedFix, UnknownFixType
}
double getAltitude () const
double getCompassHeading () const
 Heading from magnetic north.
unsigned short getDGPSStationID () const
FixType getFixType () const
const char * getFixTypeName () const
unsigned short getGPSPositionTimestamp () const
double getHDOP () const
double getLatitude () const
double getLongitude () const
unsigned short getNumSatellitesTracked () const
double getPDOP () const
double getPositionError () const
double getSpeed () const
ArTime getTimeReceivedPosition () const
double getVDOP () const
double getVerticalPositionError () const
 GPS device's error estimation in meters.
bool haveAltitude () const
bool haveCompassHeading () const
 Have a compass heading value.
bool haveDGPSStation () const
bool haveHDOP () const
bool haveLatitude () const
bool haveLongitude () const
bool havePDOP () const
bool havePosition () const
bool havePositionError () const
bool haveSpeed () const
bool haveVDOP () const
bool haveVerticalPositionError () const

Public Types

enum  ReadFlags { ReadFinished = 0, ReadError = 1, ReadData = 2, ReadUpdated = 4 }
 Flags to indicates what the read() method did. i.e. If nothing was done, then the result will be 0. To check a read() return result result to see if data was updated, use (result & ReadUpdated). To check if there was an error, use (result & ReadError).

Public Member Functions

 ArGPS ()
bool blockingConnect (unsigned long connectTimeout=8000)
 Call connect(), then keep attempting to read data. If no valid data is received and parsed (resulting in a stored data update) within the timeout period, return false.
virtual bool connect ()
 Check that the device connection is open, and get ready to read data from the GPS. If a non-standard device type was set, then device-specific initialization commands may be sent.
ArDeviceConnectiongetDeviceConnection (ArDeviceConnection *deviceConn) const
 Return device connection in use (or NULL if none).
void logData () const
 Log last received data using ArLog.
void printData () const
virtual int read ()
 Read some data from the device connection, and update stored data as complete messages are received. Return when no more data is available.
void setDeviceConnection (ArDeviceConnection *deviceConn)
 Set device connection to use.
void setIgnoreChecksum (bool ignore)
 Set whether checksum sent with NMEA messages is ignored.

Protected Types

typedef ArFunctor1C< ArGPS,
MessageVector * > 
Handler
typedef std::map< std::string,
Handler * > 
HandlerMap
typedef std::vector< std::string > MessageVector

Protected Member Functions

void beginChecksum ()
void beginMessage ()
void endMessage ()
void handleGPGGA (MessageVector *message)
void handleGPGSA (MessageVector *message)
void handleGPRMC (MessageVector *message)
void handleHCHDG (MessageVector *message)
void handlePGRME (MessageVector *message)
void handlePGRMZ (MessageVector *message)
void nextField ()
bool readFloatFromString (std::string &str, double *target, double(*convf)(double)=NULL)
bool readFloatFromStringVec (std::vector< std::string > *vec, size_t i, double *target, double(*convf)(double)=NULL)
bool readUShortFromString (std::string &str, unsigned short *target, unsigned short(*convf)(unsigned short)=NULL)
bool readUShortFromStringVec (std::vector< std::string > *vec, size_t i, unsigned short *target, unsigned short(*convf)(unsigned short)=NULL)

Static Protected Member Functions

static double feetToMeters (double f)
static double gpsDegminToDegrees (double degmin)
static double knotsToMPS (double knots)
static double metersToFeet (double m)
static double mpsToMph (double mps)

Protected Attributes

char checksumBuf [3]
short checksumBufOffset
char currentChecksum
std::string currentField
MessageVector currentMessage
bool gotCR
bool ignoreChecksum
bool inChecksum
bool inMessage
const unsigned short MaxFieldSize
const unsigned short MaxNumFields
double myAltitude
ArArgumentParsermyArgParser
double myCompassHeading
bool myCreatedOwnDeviceCon
ArDeviceConnectionmyDevice
unsigned short myDGPSStationID
FixType myFixType
Handler myGPGGAHandler
Handler myGPGSAHandler
Handler myGPRMCHandler
unsigned short myGPSPositionTimestamp
HandlerMap myHandlers
bool myHaveAltitude
bool myHaveCompassHeading
bool myHaveDGPSStation
bool myHaveHDOP
bool myHavePDOP
bool myHavePosition
bool myHavePositionError
bool myHaveSpeed
bool myHaveVDOP
bool myHaveVerticalPositionError
Handler myHCHDGHandler
double myHDOP
double myLatitude
double myLongitude
unsigned short myNumSatellitesTracked
ArRetFunctorC< bool, ArGPSmyParseArgsCallback
double myPDOP
Handler myPGRMEHandler
Handler myPGRMZHandler
double myPositionError
double mySpeed
ArTime myTimeGotPosition
double myVDOP
double myVerticalPositionError


Member Enumeration Documentation

enum ArGPS::FixType
 

Data accessors

Definition at line 148 of file ArGPS.h.


Constructor & Destructor Documentation

ArGPS::ArGPS  ) 
 

Initialize ArGPS object with the given device connection (e.g. an ArSerialDeviceConnection or other device connection object) and options.

Parameters:
deviceConn Device connection object, e.g. ArSerialDeviceConnection. May be NULL.
argParse Argument parser to get command line argument from. If serial port command line arguments are given, then a new device connection will be created for the serial port and deviceConn will not be used.

Definition at line 90 of file ArGPS.cpp.


Member Function Documentation

bool ArGPS::blockingConnect unsigned long  connectTimeout = 8000  ) 
 

Call connect(), then keep attempting to read data. If no valid data is received and parsed (resulting in a stored data update) within the timeout period, return false.

Parameters:
connectTimeout If no data is received from the GPS within this number of miliseconds, return false.
Returns:
see connect(). In addition, return false if no data is received within the timeout period.

Definition at line 166 of file ArGPS.cpp.

bool ArGPS::connect  )  [virtual]
 

Check that the device connection is open, and get ready to read data from the GPS. If a non-standard device type was set, then device-specific initialization commands may be sent.

Returns:
false if there is no device connection or the device connection is not open, or if there is an error sending device initialization commands. Otherwise, return true.

Definition at line 146 of file ArGPS.cpp.

double ArGPS::getLatitude  )  const [inline]
 

Returns:
latitude in decimal degrees

Definition at line 162 of file ArGPS.h.

double ArGPS::getLongitude  )  const [inline]
 

Returns:
longitude in decimal degrees

Definition at line 165 of file ArGPS.h.

double ArGPS::getPositionError  )  const [inline]
 

GPS device's error estimation in meters

Definition at line 184 of file ArGPS.h.

double ArGPS::getSpeed void   )  const [inline]
 

Returns:
GPS' measured speed converted to meters per second

Definition at line 173 of file ArGPS.h.

ArTime ArGPS::getTimeReceivedPosition  )  const [inline]
 

Returns:
copy of an ArTime object set to the time that ArGPS received latitude and longitude data.

Definition at line 168 of file ArGPS.h.

bool ArGPS::havePositionError  )  const [inline]
 

Returns:
whether GPS provided a distance error estimation (only some Garmins do)

Definition at line 182 of file ArGPS.h.

bool ArGPS::haveVerticalPositionError  )  const [inline]
 

Returns:
whether GPS provided an altitude error estimation (only some Garmins do)

Definition at line 186 of file ArGPS.h.

void ArGPS::printData  )  const
 

Print basic navigation data on one line to standard output, with no newline at end.

Examples:
gpsExample.cpp.

Definition at line 495 of file ArGPS.cpp.

int ArGPS::read  )  [virtual]
 

Read some data from the device connection, and update stored data as complete messages are received. Return when no more data is available.

Returns:
ReadError if there was as error reading from the device connection, Data if some data was read, ReadNoData if there was no data to read, or ReadUpdated if data was read and the end of a message was encountered, triggering any updates of stored data.
Examples:
gpsExample.cpp.

Definition at line 216 of file ArGPS.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Feb 20 10:51:43 2007 for Aria by  doxygen 1.4.0