aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorThomas Gubler <thomasgubler@gmail.com>2014-05-22 13:15:29 +0200
committerThomas Gubler <thomasgubler@gmail.com>2014-05-22 13:26:15 +0200
commite0042ec12cdccd157d181d5b9410fbeedfe3ce72 (patch)
tree22345d159f926719c8d3ec05c46d7ba8f6ed80f7 /src/lib
parent05648d80d25febd220bac503aad3756d6dc5401b (diff)
downloadpx4-firmware-e0042ec12cdccd157d181d5b9410fbeedfe3ce72.tar.gz
px4-firmware-e0042ec12cdccd157d181d5b9410fbeedfe3ce72.tar.bz2
px4-firmware-e0042ec12cdccd157d181d5b9410fbeedfe3ce72.zip
geo: add functions to get global projection/transformation reference values
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/geo/geo.c39
-rw-r--r--src/lib/geo/geo.h10
2 files changed, 49 insertions, 0 deletions
diff --git a/src/lib/geo/geo.c b/src/lib/geo/geo.c
index c9d48491e..b1e038323 100644
--- a/src/lib/geo/geo.c
+++ b/src/lib/geo/geo.c
@@ -186,6 +186,23 @@ __EXPORT int map_projection_reproject(const struct map_projection_reference_s *r
return 0;
}
+__EXPORT int map_projection_global_getref(double *lat_0, double *lon_0)
+{
+ if (!map_projection_global_initialized()) {
+ return -1;
+ }
+
+ if (lat_0 != NULL) {
+ *lat_0 = M_RAD_TO_DEG * mp_ref.lat_rad;
+ }
+
+ if (lon_0 != NULL) {
+ *lon_0 = M_RAD_TO_DEG * mp_ref.lon_rad;
+ }
+
+ return 0;
+
+}
__EXPORT int globallocalconverter_init(double lat_0, double lon_0, float alt_0, uint64_t timestamp)
{
if (strcmp("commander", getprogname() == 0)) {
@@ -210,6 +227,8 @@ __EXPORT int globallocalconverter_tolocal(double lat, double lon, float alt, flo
map_projection_global_project(lat, lon, x, y);
*z = gl_ref.alt - alt;
+
+ return 0;
}
__EXPORT int globallocalconverter_toglobal(float x, float y, float z, double *lat, double *lon, float *alt)
@@ -220,6 +239,26 @@ __EXPORT int globallocalconverter_toglobal(float x, float y, float z, double *l
map_projection_global_reproject(x, y, lat, lon);
*alt = gl_ref.alt - z;
+
+ return 0;
+}
+
+__EXPORT int globallocalconverter_getref(double *lat_0, double *lon_0, float *alt_0)
+{
+ if (!map_projection_global_initialized()) {
+ return -1;
+ }
+
+ if (map_projection_global_getref(lat_0, lon_0))
+ {
+ return -1;
+ }
+
+ if (alt_0 != NULL) {
+ *alt_0 = gl_ref.alt;
+ }
+
+ return 0;
}
__EXPORT float get_distance_to_next_waypoint(double lat_now, double lon_now, double lat_next, double lon_next)
diff --git a/src/lib/geo/geo.h b/src/lib/geo/geo.h
index 98dfbd14b..4bc3cc17c 100644
--- a/src/lib/geo/geo.h
+++ b/src/lib/geo/geo.h
@@ -196,6 +196,11 @@ __EXPORT int map_projection_global_reproject(float x, float y, double *lat, doub
__EXPORT int map_projection_reproject(const struct map_projection_reference_s *ref, float x, float y, double *lat, double *lon);
/**
+ * Get reference position of the global map projection
+ */
+__EXPORT int map_projection_global_getref(double *lat_0, double *lon_0);
+
+/**
* Initialize the global mapping between global position (spherical) and local position (NED).
*/
__EXPORT int globallocalconverter_init(double lat_0, double lon_0, float alt_0, uint64_t timestamp);
@@ -217,6 +222,11 @@ __EXPORT int globallocalconverter_tolocal(double lat, double lon, float alt, flo
__EXPORT int globallocalconverter_toglobal(float x, float y, float z, double *lat, double *lon, float *alt);
/**
+ * Get reference position of the global to local converter
+ */
+__EXPORT int globallocalconverter_getref(double *lat_0, double *lon_0, float *alt_0);
+
+/**
* Returns the distance to the next waypoint in meters.
*
* @param lat_now current position in degrees (47.1234567°, not 471234567°)