Permalink
Browse files

Initial pass at adding UTM coordinate support (requires GeographicLib)

  • Loading branch information...
David Kyle
David Kyle committed Dec 22, 2015
1 parent 2bbad73 commit a3fa33dafc137facc55cf75572ed15b76c8fd056
Showing with 669 additions and 4 deletions.
  1. +6 −2 default.features
  2. +2 −1 gams.mpc
  3. +111 −1 src/gams/utility/Location.h
  4. +126 −0 src/gams/utility/UTMFrame.cpp
  5. +240 −0 src/gams/utility/UTMFrame.h
  6. +179 −0 src/gams/utility/UTMFrame.inl
  7. +5 −0 using_utm.mpb
@@ -22,11 +22,15 @@ dronerk = 0
/// Enable this feature if you want to support the VREP simulator
vrep = 1
/// @feature vrep
/// @feature utm
/// Enable this feature if you want to support the UTM coordinate system using GeographicLib
utm = 0
/// @feature java
/// Enable this feature if you want to support Java
java = 0
/// @feature vrep
/// @feature android
/// Enable this feature if you want to support Android (requires java=1)
android = 0
@@ -1,4 +1,4 @@
project (gams) : using_madara, using_ace, using_dronerk, vrep_lib, ros_lib, port/java/using_android, port/java/using_java, port/java/using_openjdk {
project (gams) : using_madara, using_ace, using_utm, using_dronerk, vrep_lib, ros_lib, port/java/using_android, port/java/using_java, port/java/using_openjdk {
libout = lib
sharedname = GAMS
includes += src
@@ -36,6 +36,7 @@ project (gams) : using_madara, using_ace, using_dronerk, vrep_lib, ros_lib, port
using_ace.mpb
using_madara.mpb
using_gams.mpb
using_utm.mpb
using_dronerk.mpb
using_vrep.mpb
using_ros.mpb
@@ -77,8 +77,9 @@ namespace gams
* lng/lat/alt for GPS-style systems
* rho/phi/r for Cylindrical systems
* theta/phi/r for Spherical systems
* northing/easting/zone/hemi/alt for UTM/USP systems
*
* Each of the above are bound to x/y/z respectively.
* Each of the above are bound to x/y/z respectively
**/
class LocationVector
{
@@ -304,6 +305,108 @@ namespace gams
**/
double r(double new_r);
#ifdef GAMS_UTM
/**
* Gets the UTM northing for this location.
* Will return arbitrary value if this location is not bound to a UTMFrame
*
* Defined in UTMFrame.inl
**/
constexpr double northing() const;
/**
* Gets the UTM easting for this location.
* Will return arbitrary value if this location is not bound to a UTMFrame
*
* Defined in UTMFrame.inl
**/
constexpr double easting() const;
/**
* Gets the UTM zone (longitudinal) for this location: 0 if USP (near
* poles) otherwise in range [1, 60]
* Will return arbitrary value if this location is not bound to a UTMFrame
*
* Defined in UTMFrame.inl
**/
constexpr int zone() const;
/**
* Gets the UTM hemisphere for this location. True if northern.
* Will return arbitrary value if this location is not bound to a UTMFrame
*
* Defined in UTMFrame.inl
**/
constexpr bool hemi() const;
/**
* Set UTM northing and hemisphere (true is northern) simultaneously
*
* Defined in UTMFrame.inl
*
* @param n the new northing
* @param h the new hemisphere
**/
void northing(double n, bool h);
/**
* Set UTM northing only; do not change hemisphere
*
* Defined in UTMFrame.inl
*
* @param n the new northing
**/
void northing(double n);
/**
* Set UTM hemisphere (true is northern) only; do not change northing
*
* Defined in UTMFrame.inl
*
* @param h the new hemisphere
**/
void hemi(bool h);
/**
* Set UTM easting and zone simultaneously
*
* Defined in UTMFrame.inl
*
* @param e the new easting
* @param z the new zone; 0 for USP (polar regions), otherwise [1,60]
**/
void easting(double e, int z);
/**
* Set UTM easting only; do not change zone
*
* Defined in UTMFrame.inl
*
* @param e the new easting
**/
void easting(double e);
/**
* Set UTM zone only; do not change easting
*
* Defined in UTMFrame.inl
*
* @param z the new zone; 0 for USP (polar regions), otherwise [1,60]
**/
void zone(int z);
/**
* Get the NATO band code for the latitude of this UTM location
*
* Defined in UTMFrame.inl
*
* @return an uppercase letter according to NATO standards
**/
char nato_band();
#endif // GAMS_UTM
/**
* Number of elements in this tuple
*
@@ -363,8 +466,15 @@ namespace gams
* lng/lat/alt for GPS-style systems
* rho/phi/r for Cylindrical systems
* theta/phi/r for Spherical systems
* northing/easting/zone/hemi/alt for UTM/USP systems
*
* Each of the above are bound to x/y/z respectively.
*
* Note that no checking is done to ensure that the correct accessors are
* used based on the actual ReferenceFrame type this Location is bound
* to. In particular, the UTM/USP accessors may produce strange values if
* the Location is not actually bound to a UTMFrame, but will not cause
* exceptions.
**/
class Location : public LocationVector, public Coordinate<Location>
{
@@ -0,0 +1,126 @@
/**
* Copyright (c) 2015 Carnegie Mellon University. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following acknowledgments and disclaimers.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The names "Carnegie Mellon University," "SEI" and/or "Software
* Engineering Institute" shall not be used to endorse or promote products
* derived from this software without prior written permission. For written
* permission, please contact permission@sei.cmu.edu.
*
* 4. Products derived from this software may not be called "SEI" nor may "SEI"
* appear in their names without prior written permission of
* permission@sei.cmu.edu.
*
* 5. Redistributions of any form whatsoever must retain the following
* acknowledgment:
*
* This material is based upon work funded and supported by the Department
* of Defense under Contract No. FA8721-05-C-0003 with Carnegie Mellon
* University for the operation of the Software Engineering Institute, a
* federally funded research and development center. Any opinions,
* findings and conclusions or recommendations expressed in this material
* are those of the author(s) and do not necessarily reflect the views of
* the United States Department of Defense.
*
* NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING
* INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON
* UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR
* IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF
* FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS
* OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES
* NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT,
* TRADEMARK, OR COPYRIGHT INFRINGEMENT.
*
* This material has been approved for public release and unlimited
* distribution.
**/
/**
* @file UTMFrame.cpp
* @author James Edmondson <jedmondson@gmail.com>
*
* This file contains the UTM reference frame class
**/
#ifdef GAMS_UTM
#include "UTMFrame.h"
#include "GPSFrame.h"
#include <GeographicLib/UTMUPS.hpp>
using namespace gams::utility;
using namespace GeographicLib;
const double UTMFrame::ZONE_WIDTH = 1000000;
const double UTMFrame::SOUTH_OFFSET = 10000000;
const double UTMFrame::MAX_Y = 9600000;
const double UTMFrame::MIN_Y = -9600000;
void UTMFrame::transform_location_to_origin(
double &x, double &y, double &z) const
{
GAMS_WITH_FRAME_TYPE(origin(), GPSFrame, frame)
{
UTMUPS::Reverse(to_zone(x), to_hemi(y),
to_easting(x), to_northing(y), y, x);
return;
}
throw undefined_transform(*this, origin().frame(), true);
}
void UTMFrame::transform_location_from_origin(
double &x, double &y, double &z) const
{
GAMS_WITH_FRAME_TYPE(origin(), GPSFrame, frame)
{
int zone;
bool hemi;
double eas, nor;
UTMUPS::Forward(y, x, zone, hemi, eas, nor, zone_);
x = from_easting(eas, zone);
y = from_northing(nor, hemi);
return;
}
throw undefined_transform(*this, origin().frame(), true);
}
double UTMFrame::calc_distance(
double x1, double y1, double z1,
double x2, double y2, double z2) const
{
if(to_zone(x1) == to_zone(x2))
{
double x_dist = x2 - x1;
double y_dist = y2 - y1;
double z_dist = z2 - z2;
return sqrt(x_dist * x_dist + y_dist * y_dist + z_dist * z_dist);
}
GAMS_WITH_FRAME_TYPE(origin(), GPSFrame, frame)
{
Location l1(*this, x1, y1, z1);
Location l2(*this, x2, y2, z2);
l1.transform_this_to(*frame);
l2.transform_this_to(*frame);
return l1.distance_to(l2);
}
}
void UTMFrame::do_normalize_location(
double &x, double &y, double &z) const
{ }
#endif
Oops, something went wrong.

0 comments on commit a3fa33d

Please sign in to comment.