Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.
Dependencies: Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo
GeoPosition.h
00001 #ifndef __GEOPOSITION_H 00002 #define __GEOPOSITION_H 00003 00004 #ifndef _PI 00005 #define _PI 3.141592653 00006 #endif 00007 00008 #define degrees(x) ((x)*180/_PI) 00009 #define radians(x) ((x)*_PI/180) 00010 00011 /** Geographical position and calculation. Most of this comes from http://www.movable-type.co.uk/scripts/latlong.html 00012 * 00013 */ 00014 class GeoPosition { 00015 public: 00016 00017 /** Create a new emtpy position object 00018 * 00019 */ 00020 GeoPosition(); 00021 00022 /** Create a new position with the specified latitude and longitude. See set() 00023 * 00024 * @param latitude is the latitude to set 00025 * @param longitude is the longitude to set 00026 */ 00027 GeoPosition(double latitude, double longitude); 00028 00029 /** Get the position's latitude 00030 * 00031 * @returns the position's latitude 00032 */ 00033 double latitude(); 00034 00035 /** Get the position's longitude 00036 * 00037 * @returns the position's longitude 00038 */ 00039 double longitude(); 00040 00041 /** Set the position's location to another position's coordinates 00042 * 00043 * @param pos is another position from which coordinates will be copied 00044 */ 00045 void set(GeoPosition pos); 00046 00047 /** Set the position's location to the specified coordinates 00048 * 00049 * @param latitude is the new latitude to set 00050 * @param longitude is the new longitude to set 00051 */ 00052 void set(double latitude, double longitude); 00053 00054 /** Move the location of the position by the specified distance and in 00055 * the specified direction 00056 * 00057 * @param course is the direction of movement in degrees, absolute not relative 00058 * @param distance is the distance of movement along the specified course in meters 00059 */ 00060 void move(float course, float distance); 00061 00062 /** Get the bearing from the specified origin position to this position. To get 00063 * relative bearing, subtract the result from your heading. 00064 * 00065 * @param from is the position from which to calculate bearing 00066 * @returns the bearing in degrees 00067 */ 00068 float bearing(GeoPosition from); 00069 00070 float bearingFrom(GeoPosition from); 00071 00072 float bearingTo(GeoPosition to); 00073 00074 /** Get the distance from the specified origin position to this position 00075 * 00076 * @param from is the position from which to calculate distance 00077 * @returns the distance in meters 00078 */ 00079 float distance(GeoPosition from); 00080 00081 float distanceTo(GeoPosition to); 00082 00083 float distanceFrom(GeoPosition from); 00084 00085 /** Set an arbitrary timestamp on the position 00086 * 00087 * @param timestamp is an integer timestamp, eg., seconds, milliseconds, or whatever 00088 */ 00089 void setTimestamp(int time); 00090 00091 /** Return a previously set timestamp on the position 00092 * 00093 * @returns the timestamp (e.g., seconds, milliseconds, etc.) 00094 */ 00095 int getTimestamp(void); 00096 00097 private: 00098 double _R; /** Earth's mean radius */ 00099 double _latitude; /** The position's latitude */ 00100 double _longitude; /** The position's longitude */ 00101 double _northing; /** The position's UTM northing coordinate */ 00102 double _easting; /** The position's UTM easting coordinate */ 00103 int _time; /** Timestamp */ 00104 }; 00105 00106 #endif
Generated on Tue Jul 12 2022 14:09:25 by 1.7.2