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

ArGPS.h

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 
00027 #ifndef ARGPS_H
00028 #define ARGPS_H
00029 
00030 #include "ariaTypedefs.h"
00031 #include "ArFunctor.h"
00032 #include "ariaUtil.h"
00033 #include <string>
00034 #include <vector>
00035 
00036 class ArDeviceConnection; // for pointer in ArGPS
00037 
00078 class ArGPS {
00079 
00080 public:
00081     AREXPORT ArGPS();
00082     AREXPORT virtual ~ArGPS();
00083 
00085     AREXPORT void setDeviceConnection(ArDeviceConnection* deviceConn) { myDevice = deviceConn; }
00086 
00088     AREXPORT ArDeviceConnection* getDeviceConnection(ArDeviceConnection* deviceConn) const { return myDevice; }
00089 
00090 
00100     AREXPORT virtual bool connect();
00101 
00110     AREXPORT bool blockingConnect(unsigned long connectTimeout = 8000);
00111 
00112     
00119     typedef enum { 
00120       ReadFinished = 0,
00121       ReadError = 1, 
00122       ReadData = 2,
00123       ReadUpdated = 4
00124     } ReadFlags;
00125 
00133     AREXPORT virtual int read();
00134 
00136     AREXPORT void setIgnoreChecksum(bool ignore) { ignoreChecksum = ignore; }
00137 
00139     AREXPORT void logData() const;
00140 
00142     AREXPORT void printData() const;
00143 
00146     // @{
00147  
00148     typedef enum {  
00149         NoFix, BadFix, GPSFix, DGPSFix, PPSFix, 
00150         RTKinFix, FloatRTKinFix, DeadReckFix, 
00151         ManualFix, SimulatedFix, UnknownFixType 
00152      } FixType;
00153 
00154     AREXPORT FixType getFixType() const { return myFixType; }
00155     AREXPORT const char* getFixTypeName() const;
00156 
00157     AREXPORT bool havePosition() const { return myHavePosition; }
00158     AREXPORT bool haveLatitude() const { return myHavePosition; }
00159     AREXPORT bool haveLongitude() const { return myHavePosition; }
00160 
00162     AREXPORT double getLatitude() const { return myLatitude; }
00163 
00165     AREXPORT double getLongitude() const { return myLongitude; }
00166 
00168     AREXPORT ArTime getTimeReceivedPosition() const { return myTimeGotPosition; }
00169 
00170     AREXPORT bool haveSpeed() const { return myHaveSpeed; }
00171 
00173     AREXPORT double getSpeed() const { return mySpeed; }
00174 
00175     AREXPORT unsigned short getGPSPositionTimestamp() const { return myGPSPositionTimestamp; }
00176 
00177     AREXPORT unsigned short getNumSatellitesTracked() const { return myNumSatellitesTracked; }
00178     AREXPORT bool haveDGPSStation() const { return myHaveDGPSStation; }
00179     AREXPORT unsigned short getDGPSStationID() const { return myDGPSStationID; }
00180 
00182     AREXPORT bool havePositionError() const { return myHavePositionError; }
00184     AREXPORT double getPositionError() const { return myPositionError; }
00186     AREXPORT bool haveVerticalPositionError() const { return myHaveVerticalPositionError; }
00188     AREXPORT double getVerticalPositionError() const { return myVerticalPositionError; }
00189 
00191     AREXPORT bool haveCompassHeading() const { return myHaveCompassHeading; }
00193     AREXPORT double getCompassHeading() const { return myCompassHeading; }
00194 
00195     AREXPORT bool haveAltitude() const { return myHaveAltitude; }
00196     AREXPORT double getAltitude() const { return myAltitude; }
00197 
00198     AREXPORT bool haveHDOP() const { return myHaveHDOP; }
00199     AREXPORT double getHDOP() const { return myHDOP; }
00200     AREXPORT bool haveVDOP() const { return myHaveVDOP; }
00201     AREXPORT double getVDOP() const { return myVDOP; }
00202     AREXPORT bool havePDOP() const { return myHavePDOP; }
00203     AREXPORT double getPDOP() const { return myPDOP; }
00205 
00206 protected:
00207     /* Last data received */
00208     double myLatitude;
00209     double myLongitude;
00210     bool myHavePosition;
00211     ArTime myTimeGotPosition;   // Time we got the data
00212     double mySpeed;
00213     bool myHaveSpeed;
00214     unsigned short myGPSPositionTimestamp;   // Timestamp provided by GPS device
00215     FixType myFixType;
00216     unsigned short myNumSatellitesTracked;
00217     double myAltitude;
00218     bool myHaveAltitude;
00219     unsigned short myDGPSStationID;
00220     bool myHaveDGPSStation;
00221     double myPositionError;
00222     bool myHavePositionError;
00223     double myVerticalPositionError;
00224     bool myHaveVerticalPositionError;
00225     double myCompassHeading;
00226     bool myHaveCompassHeading;
00227     bool myHaveHDOP;
00228     double myHDOP;
00229     bool myHaveVDOP;
00230     double myVDOP;
00231     bool myHavePDOP;
00232     double myPDOP;
00233 
00234     /* Read a doubleing point number out of a std::string, if possible.
00235      * @return true if the string was nonempty and @a target was modified.
00236      */
00237     bool readFloatFromString(std::string& str, double* target, double(*convf)(double) = NULL);
00238 
00239     /* Read an unsigned short integer out of a std::string, if possible.
00240      * @return true if the string was nonempty and @a target was modified.
00241      */
00242     bool readUShortFromString(std::string& str, unsigned short* target, unsigned short (*convf)(unsigned short) = NULL);
00243 
00244 
00245     /* Read a double from a member of a vector of strings, if it exists. */
00246     bool readFloatFromStringVec(std::vector<std::string>* vec, size_t i, double* target, double (*convf)(double) = NULL);
00247 
00248     /* Read a double from a member of a vector of strings, if it exists. */
00249     bool readUShortFromStringVec(std::vector<std::string>* vec, size_t i, unsigned short* target, unsigned short (*convf)(unsigned short) = NULL);
00250 
00251     /* Convert DDDMM.MMMM to decimal degrees */
00252     static double gpsDegminToDegrees(double degmin);
00253 
00254     /* Convert US nautical knots to meters/sec */
00255     static double knotsToMPS(double knots);
00256  
00257     /* Convert meters/sec to miles/hour */
00258     static double mpsToMph(double mps) { return mps * 2.23693629; }
00259 
00260     /* Convert meters to US feet */
00261     static double metersToFeet(double m) { return m * 3.2808399; }
00262 
00263     /* Convert US feet  to meters */
00264     static double feetToMeters(double f) { return f / 3.2808399; }
00265     
00266 
00267     /* Connection info */
00268     ArDeviceConnection *myDevice;
00269     bool myCreatedOwnDeviceCon;
00270     ArRetFunctorC<bool, ArGPS> myParseArgsCallback; 
00271     ArArgumentParser* myArgParser;
00272     
00273     /* NMEA message, divided into parts.  */
00274     typedef std::vector<std::string> MessageVector;
00275 
00276     /* NMEA message handler type. 
00277      * XXX Is the reference OK for ArFunctor?  
00278      */
00279     typedef ArFunctor1C<ArGPS, MessageVector*> Handler;
00280 
00281     /* Map of message identifiers to handler functors */
00282     typedef std::map<std::string, Handler*> HandlerMap;
00283 
00284     /* NMEA message handlers used by ArGPS */
00285     HandlerMap myHandlers;
00286 
00287     void handleGPRMC(MessageVector* message);
00288     Handler myGPRMCHandler;
00289 
00290     void handleGPGGA(MessageVector* message);
00291     Handler myGPGGAHandler;
00292 
00293     void handlePGRME(MessageVector* message);
00294     Handler myPGRMEHandler;
00295 
00296     void handlePGRMZ(MessageVector* message);
00297     Handler myPGRMZHandler;
00298 
00299     void handleHCHDG(MessageVector* message);
00300     Handler myHCHDGHandler;
00301 
00302     void handleGPGSA(MessageVector* message);
00303     Handler myGPGSAHandler;
00304 
00305     /*  NMEA scanner state.
00306      *  There are possabilities for opmitization here, such 
00307      *  as just storing the read data in a buffer and handling
00308      *  each field as it is found in the buffer, or building
00309      *  a list of char* for each field pointing into the buffer
00310      *  instead of copying each field into a std::string in the
00311      *  currentMessage vector, etc. etc.
00312      */
00313     const unsigned short MaxNumFields;
00314     const unsigned short MaxFieldSize; // bytes
00315     bool ignoreChecksum;
00316 
00317     MessageVector currentMessage;
00318     std::string currentField;
00319     char checksumBuf[3];
00320     short checksumBufOffset;
00321     bool inChecksum;
00322     bool inMessage;
00323     char currentChecksum;
00324     bool gotCR;
00325 
00326       // update state
00327     void beginMessage();
00328     void endMessage();
00329     void nextField();
00330     void beginChecksum();
00331 
00332 };
00333 
00334 #endif // ifdef ARGPS_H

Generated on Tue Feb 20 10:51:40 2007 for Aria by  doxygen 1.4.0