Skip to content

Commit 437b57e

Browse files
authored
Merge pull request #37 from Roboterbastler/js/fix_pose_conversion
Fix UTMPose to GeoPose conversion
2 parents c3db37b + cb62001 commit 437b57e

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

geodesy/src/conv/utm_conversions.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ static char UTMBand(double Lat, double Lon)
113113
*
114114
* Equations from USGS Bulletin 1532
115115
*
116-
* @param from WGS 84 point message.
117-
* @return UTM point.
116+
* @param from UTM point.
117+
* @return WGS 84 point message.
118118
*/
119119
geographic_msgs::GeoPoint toMsg(const UTMPoint &from)
120120
{
@@ -285,6 +285,19 @@ UTMPoint::UTMPoint(const geographic_msgs::GeoPoint &pt)
285285
fromMsg(pt, *this);
286286
}
287287

288+
/** Convert UTM pose to WGS 84 geodetic pose.
289+
*
290+
* @param from UTM pose.
291+
* @return WGS 84 pose message.
292+
*/
293+
geographic_msgs::GeoPose toMsg(const UTMPose &from)
294+
{
295+
geographic_msgs::GeoPose to;
296+
to.position = toMsg(from.position);
297+
to.orientation = from.orientation;
298+
return to;
299+
}
300+
288301
/** Convert WGS 84 geodetic pose to UTM pose.
289302
*
290303
* @param from WGS 84 pose message.

geodesy/tests/test_utm.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include <sstream>
3838
#include <gtest/gtest.h>
39+
#include <angles/angles.h>
3940
#include "geodesy/utm.h"
4041

4142

@@ -299,6 +300,34 @@ TEST(UTMPose, quaternionValidation)
299300
EXPECT_FALSE(geodesy::isValid(pose4));
300301
}
301302

303+
// Test UTM pose conversion
304+
TEST(UTMConvert, fromUtmPoseToLatLongAndBack)
305+
{
306+
double e = 500000.0; // central meridian of each zone
307+
double n = 1000.0;
308+
double alt = 100.0;
309+
char b = 'N';
310+
311+
// try every possible zone of longitude
312+
for (uint8_t z = 1; z <= 60; ++z)
313+
{
314+
for (unsigned int heading = 0; heading < 360; heading++)
315+
{
316+
geodesy::UTMPose ps1(geodesy::UTMPoint(e, n, alt, z, b),
317+
tf::createQuaternionMsgFromYaw(angles::from_degrees(heading)));
318+
geographic_msgs::GeoPose ll;
319+
convert(ps1, ll);
320+
geodesy::UTMPose ps2;
321+
convert(ll, ps2);
322+
323+
EXPECT_TRUE(geodesy::isValid(ps1));
324+
EXPECT_TRUE(geodesy::isValid(ps2));
325+
check_utm_near(ps1.position, ps2.position, 0.000001);
326+
EXPECT_DOUBLE_EQ(tf::getYaw(ps1.orientation), tf::getYaw(ps2.orientation));
327+
}
328+
}
329+
}
330+
302331
// Test conversion from UTM to WGS 84 and back
303332
TEST(UTMConvert, fromUtmToLatLongAndBack)
304333
{

0 commit comments

Comments
 (0)