gpsUtils.h
Go to the documentation of this file.
1 #ifndef GPSUTILS_H
2 #define GPSUTILS_H
3 
4 #include <math.h>
5 
16 class GpsUtils
17 {
18  // WGS-84 geodetic constants
19 public:
21  {
22  a = 6378137; // WGS-84 Earth semimajor axis (m)
23  b = 6356752.3142; //WGS-84 Earth semiminor axis (m)
24  f = (a - b) / a; // Ellipsoid Flatness
25  e_sq = f * (2 - f); //Square of Eccentricity
26  }
27  ~GpsUtils() {}
28 
33  void GeodeticToEcef(double lat, double lon, double h)
34  {
35  // Convert to radians in notation consistent with the paper:
36  double lambda = DegreesToRadians(lat);
37  double phi = DegreesToRadians(lon);
38  double s = sin(lambda);
39  double N = a / sqrt(1 - e_sq * s * s);
40 
41  double sin_lambda = sin(lambda);
42  double cos_lambda = cos(lambda);
43  double cos_phi = cos(phi);
44  double sin_phi = sin(phi);
45 
46  xEcef = (h + N) * cos_lambda * cos_phi;
47  yEcef = (h + N) * cos_lambda * sin_phi;
48  zEcef = (h + (1 - e_sq) * N) * sin_lambda;
49  }
50 
56  void EcefToEnu(double lat0, double lon0, double h0)
57  {
58  // Convert to radians in notation consistent with the paper:
59  double lambda = DegreesToRadians(lat0);
60  double phi = DegreesToRadians(lon0);
61  double s = sin(lambda);
62  double N = a / sqrt(1 - e_sq * s * s);
63 
64  double sin_lambda = sin(lambda);
65  double cos_lambda = cos(lambda);
66  double cos_phi = cos(phi);
67  double sin_phi = sin(phi);
68 
69  double x0 = (h0 + N) * cos_lambda * cos_phi;
70  double y0 = (h0 + N) * cos_lambda * sin_phi;
71  double z0 = (h0 + (1 - e_sq) * N) * sin_lambda;
72 
73  double xd, yd, zd;
74  xd = xEcef - x0;
75  yd = yEcef - y0;
76  zd = zEcef - z0;
77 
78  // This is the matrix multiplication
79  xEast = -sin_phi * xd + cos_phi * yd;
80  yNorth = -cos_phi * sin_lambda * xd - sin_lambda * sin_phi * yd +
81  cos_lambda * zd;
82  zUp = cos_lambda * cos_phi * xd + cos_lambda * sin_phi * yd +
83  sin_lambda * zd;
84  }
85 
90  void GeodeticToEnu(double lat, double lon, double h, double lat0,
91  double lon0, double h0)
92  {
93  GeodeticToEcef(lat, lon, h);
94  EcefToEnu(lat0, lon0, h0);
95  }
99  bool AreClose(double x0, double x1)
100  {
101  double d = x1 - x0;
102  return (d * d) < 1e-2;
103  }
107  double DegreesToRadians(double degrees) { return M_PI / 180.0 * degrees; }
111  double RadiansToDegrees(double radians) { return 180.0 / M_PI * radians; }
112  double xEast;
113  double yNorth;
114  double zUp;
115 
116 private:
117  double a;
118  double b;
119  double f;
120  double e_sq;
121  double xEcef;
122  double yEcef;
123  double zEcef;
124 };
125 
126 #endif
GpsUtils::yEcef
double yEcef
Earth-Centered Earth-Fixed (ECEF) coordinates y.
Definition: gpsUtils.h:122
GpsUtils::xEast
double xEast
East-North-Up coordinates x in a Local Tangent Plane.
Definition: gpsUtils.h:112
GpsUtils::e_sq
double e_sq
Square of Eccentricity.
Definition: gpsUtils.h:120
GpsUtils::EcefToEnu
void EcefToEnu(double lat0, double lon0, double h0)
Converts the Earth-Centered Earth-Fixed (ECEF) coordinates (x, y, z) to East-North-Up coordinates in ...
Definition: gpsUtils.h:56
GpsUtils::RadiansToDegrees
double RadiansToDegrees(double radians)
convert radians to degrees
Definition: gpsUtils.h:111
GpsUtils::GpsUtils
GpsUtils()
Definition: gpsUtils.h:20
GpsUtils
Some helpers for converting GPS readings from the WGS84 geodetic system to a local North-East-Up cart...
Definition: gpsUtils.h:17
GpsUtils::yNorth
double yNorth
East-North-Up coordinates y in a Local Tangent Plane.
Definition: gpsUtils.h:113
GpsUtils::AreClose
bool AreClose(double x0, double x1)
check whether two values are too close (less than 1e-2)
Definition: gpsUtils.h:99
GpsUtils::~GpsUtils
~GpsUtils()
Definition: gpsUtils.h:27
GpsUtils::a
double a
WGS-84 Earth semimajor axis (m)
Definition: gpsUtils.h:117
GpsUtils::f
double f
Ellipsoid Flatness.
Definition: gpsUtils.h:119
GpsUtils::xEcef
double xEcef
Earth-Centered Earth-Fixed (ECEF) coordinates x.
Definition: gpsUtils.h:121
GpsUtils::b
double b
WGS-84 Earth semiminor axis (m)
Definition: gpsUtils.h:118
GpsUtils::DegreesToRadians
double DegreesToRadians(double degrees)
convert degrees to radians
Definition: gpsUtils.h:107
GpsUtils::zEcef
double zEcef
Earth-Centered Earth-Fixed (ECEF) coordinates z.
Definition: gpsUtils.h:123
GpsUtils::GeodeticToEcef
void GeodeticToEcef(double lat, double lon, double h)
Converts WGS-84 Geodetic point (lat, lon, h) to the Earth-Centered Earth-Fixed (ECEF) coordinates (x,...
Definition: gpsUtils.h:33
GpsUtils::GeodeticToEnu
void GeodeticToEnu(double lat, double lon, double h, double lat0, double lon0, double h0)
Converts the geodetic WGS-84 coordinated (lat, lon, h) to East-North-Up coordinates in a Local Tangen...
Definition: gpsUtils.h:90
GpsUtils::zUp
double zUp
East-North-Up coordinates z in a Local Tangent Plane.
Definition: gpsUtils.h:114


ddrone_task_manager
Author(s):
autogenerated on Thu Jul 30 2020 17:17:04