Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

GPS/GPS.h

Go to the documentation of this file.
00001 #ifndef GPS_h_GAURD_123412341
00002 #define GPS_h_GAURD_123412341
00003 
00004 #include <math.h>
00005 
00016 class GPS {
00017   public:
00018         enum {Static=1, Quasi_Static=2, Walking=3, Ship=4, Automobile=5, Aircraft=6};
00019         
00020         
00022         // The constuctor will open and initialize serial port. You should use reset() 
00023         // after this function to reset the GPS. 
00024         GPS(const char* serial, int noWait=1);
00025 
00027         // This will create a empty class, ReadNoWait will not work, but the parsePOS and
00028         // parseUTM functions can be used for parsing POS or UTM messages; Usefull for 
00029         // debugging 
00030         GPS(void);  
00031 
00033         // This function will reset and initialize GPS settings, it will take about 
00034         // 10-20 seconds for this fucntion to compelete.  After being intialized the GPS 
00035         // should start sending data almost immediately, but it will take about 
00036         // 60+ seconds for the GPS unit to get a lock on enough satelites to provide  
00037         // position data
00038         int init(float period=5.0, int dynamicMode=Quasi_Static);
00039     
00041         // Will read data from GPS. Tf there is new data it save it and return 1.
00042         // If there is no new data it will return 0;
00043         int Read(void);
00044   
00046         // Message access functions : If last called to ReadNoWait() returned 1, then 
00047         // The data that was collected can be found here.  When there is not enough
00048         // satellites availible the may not be accurate position or velocity data availible
00049         // so use the hasPositions() and hasVelocities() functions to check this.
00051         // returns non-zero if there was position data availble with last read
00052         // the postion data can be obtained with xPos() yPos() and zPos()
00053         inline int hasPositions(void) {return has_positions;}
00054         inline double xPos(void) {return x;}
00055         inline double yPos(void) {return y;}
00056         inline double zPos(void) {return z;}
00058         // returns non-zero if there was velocity data availble with last read
00059         // the velocity data can be obtained with xVel() yVel() and zVel()
00060         inline int hasVelocities(void) {return has_velocities;}
00061         inline double xVel(void) {return xvel;}
00062         inline double yVel(void) {return yvel;}
00063         inline double zVel(void) {return zvel;}
00065         inline double pDOP(void) {return pdop;}
00066         inline double hDOP(void) {return hdop;}
00067         inline double vDOP(void) {return vdop;}
00068         inline double tDOP(void) {return tdop;}
00070         // number of satelites that were seen with last read
00071         inline int getNumSat(void) {return numsat;}  
00073         inline double getLatitude(void) {return latitude;}
00074         inline double getLongitude(void) {return longitude;}
00076         // Returns a pointer to last message read from GPS.  Could be use for logging 
00077         // data to a file.
00078         inline const char* getMsg(void) {return msgbuf;}
00079         inline int getFD(void) {return gps_fd;}
00081         // These functions will parse different types of messages from 
00082         int dispatchMsg(const char *msg); //dispatch to correct message parsing type
00083         int parsePOS(const char *msg);
00084         int parseUTM(const char *msg);
00085 
00086         // Prints out data from last GPS message (for debugging)
00087         void printData(void);
00088 
00089 
00090 
00092         // INTERNAL STUFF
00094 
00095   private:
00096         void initVars(void);
00097 
00098   protected:
00099         char msgbuf[200];
00100         int msglen;
00101         int gps_fd;
00102         int reading;  //set if class is reading input
00103         int using_file;  //set if the input if comming from a file (not the GPS through serial)
00104 
00105         //parsed data
00106         int numsat;
00107         char NorS, EorW;
00108         double latitude, longitude, altitude;
00109         double x,y,z;
00110         double hVelocity, vVelocity, direction;
00111         double xvel, yvel, zvel;
00112         double pdop, hdop, vdop, tdop;  
00113 
00114         //flags
00115         int is_corrected;
00116         int has_positions, has_velocities;
00117         int nowait;
00118 
00119         static const double minutes2radians = (M_PI / 180.0 / 60.0);
00120         static const double degrees2radians = (M_PI / 180.0f);
00121         static const double knots2mps = 0.5144444;  //mps = meters per second
00122         static double invalid;; // use as invalid value? - what about NAN?
00123         static const double earthRadius = 6378137.0f; //in meters
00124 
00125         static const double zeroLatitude = 0.700076f;
00126         static const double zeroLongitude = 1.53984f;
00127 
00128         //internal functions
00129         int readLine(void);
00130         int writeLine(const char* msg);
00131         int checkAck(void);
00132 
00133         inline float cos(float f) {return ::cosf(f);}
00134         inline double cos(double f) {return ::cos(f);}
00135         inline float sin(float f) {return ::sinf(f);}
00136         inline double sin(double f) {return ::sin(f);}
00137         
00138   public:
00139         ~GPS();
00140 
00141 };
00142 
00143 
00144 #endif

Generated on Fri Sep 1 14:25:44 2006 for Raptor by  doxygen 1.4.4