Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.

Dependencies:   Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo

Committer:
shimniok
Date:
Wed Jun 20 14:57:48 2012 +0000
Revision:
0:826c6171fc1b
Updated documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:826c6171fc1b 1 #ifndef __GEOPOSITION_H
shimniok 0:826c6171fc1b 2 #define __GEOPOSITION_H
shimniok 0:826c6171fc1b 3
shimniok 0:826c6171fc1b 4 #ifndef _PI
shimniok 0:826c6171fc1b 5 #define _PI 3.141592653
shimniok 0:826c6171fc1b 6 #endif
shimniok 0:826c6171fc1b 7
shimniok 0:826c6171fc1b 8 #define degrees(x) ((x)*180/_PI)
shimniok 0:826c6171fc1b 9 #define radians(x) ((x)*_PI/180)
shimniok 0:826c6171fc1b 10
shimniok 0:826c6171fc1b 11 /** Geographical position and calculation. Most of this comes from http://www.movable-type.co.uk/scripts/latlong.html
shimniok 0:826c6171fc1b 12 *
shimniok 0:826c6171fc1b 13 */
shimniok 0:826c6171fc1b 14 class GeoPosition {
shimniok 0:826c6171fc1b 15 public:
shimniok 0:826c6171fc1b 16
shimniok 0:826c6171fc1b 17 /** Create a new emtpy position object
shimniok 0:826c6171fc1b 18 *
shimniok 0:826c6171fc1b 19 */
shimniok 0:826c6171fc1b 20 GeoPosition();
shimniok 0:826c6171fc1b 21
shimniok 0:826c6171fc1b 22 /** Create a new position with the specified latitude and longitude. See set()
shimniok 0:826c6171fc1b 23 *
shimniok 0:826c6171fc1b 24 * @param latitude is the latitude to set
shimniok 0:826c6171fc1b 25 * @param longitude is the longitude to set
shimniok 0:826c6171fc1b 26 */
shimniok 0:826c6171fc1b 27 GeoPosition(double latitude, double longitude);
shimniok 0:826c6171fc1b 28
shimniok 0:826c6171fc1b 29 /** Get the position's latitude
shimniok 0:826c6171fc1b 30 *
shimniok 0:826c6171fc1b 31 * @returns the position's latitude
shimniok 0:826c6171fc1b 32 */
shimniok 0:826c6171fc1b 33 double latitude();
shimniok 0:826c6171fc1b 34
shimniok 0:826c6171fc1b 35 /** Get the position's longitude
shimniok 0:826c6171fc1b 36 *
shimniok 0:826c6171fc1b 37 * @returns the position's longitude
shimniok 0:826c6171fc1b 38 */
shimniok 0:826c6171fc1b 39 double longitude();
shimniok 0:826c6171fc1b 40
shimniok 0:826c6171fc1b 41 /** Set the position's location to another position's coordinates
shimniok 0:826c6171fc1b 42 *
shimniok 0:826c6171fc1b 43 * @param pos is another position from which coordinates will be copied
shimniok 0:826c6171fc1b 44 */
shimniok 0:826c6171fc1b 45 void set(GeoPosition pos);
shimniok 0:826c6171fc1b 46
shimniok 0:826c6171fc1b 47 /** Set the position's location to the specified coordinates
shimniok 0:826c6171fc1b 48 *
shimniok 0:826c6171fc1b 49 * @param latitude is the new latitude to set
shimniok 0:826c6171fc1b 50 * @param longitude is the new longitude to set
shimniok 0:826c6171fc1b 51 */
shimniok 0:826c6171fc1b 52 void set(double latitude, double longitude);
shimniok 0:826c6171fc1b 53
shimniok 0:826c6171fc1b 54 /** Move the location of the position by the specified distance and in
shimniok 0:826c6171fc1b 55 * the specified direction
shimniok 0:826c6171fc1b 56 *
shimniok 0:826c6171fc1b 57 * @param course is the direction of movement in degrees, absolute not relative
shimniok 0:826c6171fc1b 58 * @param distance is the distance of movement along the specified course in meters
shimniok 0:826c6171fc1b 59 */
shimniok 0:826c6171fc1b 60 void move(float course, float distance);
shimniok 0:826c6171fc1b 61
shimniok 0:826c6171fc1b 62 /** Get the bearing from the specified origin position to this position. To get
shimniok 0:826c6171fc1b 63 * relative bearing, subtract the result from your heading.
shimniok 0:826c6171fc1b 64 *
shimniok 0:826c6171fc1b 65 * @param from is the position from which to calculate bearing
shimniok 0:826c6171fc1b 66 * @returns the bearing in degrees
shimniok 0:826c6171fc1b 67 */
shimniok 0:826c6171fc1b 68 float bearing(GeoPosition from);
shimniok 0:826c6171fc1b 69
shimniok 0:826c6171fc1b 70 float bearingFrom(GeoPosition from);
shimniok 0:826c6171fc1b 71
shimniok 0:826c6171fc1b 72 float bearingTo(GeoPosition to);
shimniok 0:826c6171fc1b 73
shimniok 0:826c6171fc1b 74 /** Get the distance from the specified origin position to this position
shimniok 0:826c6171fc1b 75 *
shimniok 0:826c6171fc1b 76 * @param from is the position from which to calculate distance
shimniok 0:826c6171fc1b 77 * @returns the distance in meters
shimniok 0:826c6171fc1b 78 */
shimniok 0:826c6171fc1b 79 float distance(GeoPosition from);
shimniok 0:826c6171fc1b 80
shimniok 0:826c6171fc1b 81 float distanceTo(GeoPosition to);
shimniok 0:826c6171fc1b 82
shimniok 0:826c6171fc1b 83 float distanceFrom(GeoPosition from);
shimniok 0:826c6171fc1b 84
shimniok 0:826c6171fc1b 85 /** Set an arbitrary timestamp on the position
shimniok 0:826c6171fc1b 86 *
shimniok 0:826c6171fc1b 87 * @param timestamp is an integer timestamp, eg., seconds, milliseconds, or whatever
shimniok 0:826c6171fc1b 88 */
shimniok 0:826c6171fc1b 89 void setTimestamp(int time);
shimniok 0:826c6171fc1b 90
shimniok 0:826c6171fc1b 91 /** Return a previously set timestamp on the position
shimniok 0:826c6171fc1b 92 *
shimniok 0:826c6171fc1b 93 * @returns the timestamp (e.g., seconds, milliseconds, etc.)
shimniok 0:826c6171fc1b 94 */
shimniok 0:826c6171fc1b 95 int getTimestamp(void);
shimniok 0:826c6171fc1b 96
shimniok 0:826c6171fc1b 97 private:
shimniok 0:826c6171fc1b 98 double _R; /** Earth's mean radius */
shimniok 0:826c6171fc1b 99 double _latitude; /** The position's latitude */
shimniok 0:826c6171fc1b 100 double _longitude; /** The position's longitude */
shimniok 0:826c6171fc1b 101 double _northing; /** The position's UTM northing coordinate */
shimniok 0:826c6171fc1b 102 double _easting; /** The position's UTM easting coordinate */
shimniok 0:826c6171fc1b 103 int _time; /** Timestamp */
shimniok 0:826c6171fc1b 104 };
shimniok 0:826c6171fc1b 105
shimniok 0:826c6171fc1b 106 #endif