| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file testRelativeElevationFactor.cpp | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @date Aug 17, 2012 | 
					
						
							|  |  |  |  * @author Alex Cunningham | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <CppUnitLite/TestHarness.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <gtsam_unstable/slam/RelativeElevationFactor.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <gtsam/base/numericalDerivative.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SharedNoiseModel model1 = noiseModel::Unit::Create(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const double tol = 1e-5; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const Pose3 pose1(Rot3(), Point3(2.0, 3.0, 4.0)); | 
					
						
							|  |  |  | const Pose3 pose2(Rot3::pitch(-M_PI_2), Point3(2.0, 3.0, 4.0)); | 
					
						
							|  |  |  | const Pose3 pose3(Rot3::RzRyRx(0.1, 0.2, 0.3), Point3(2.0, 3.0, 4.0)); | 
					
						
							|  |  |  | const Point3 point1(3.0, 4.0, 2.0); | 
					
						
							|  |  |  | const gtsam::Key poseKey = 1, pointKey = 2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | LieVector evalFactorError(const RelativeElevationFactor& factor, const Pose3& x, const Point3& p) { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   return LieVector(factor.evaluateError(x, p)); | 
					
						
							| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( testRelativeElevationFactor, level_zero_error ) { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // Zero error
 | 
					
						
							|  |  |  |   double measured = 2.0; | 
					
						
							|  |  |  |   RelativeElevationFactor factor(poseKey, pointKey, measured, model1); | 
					
						
							|  |  |  |   Matrix actH1, actH2; | 
					
						
							|  |  |  |   EXPECT(assert_equal(zero(1), factor.evaluateError(pose1, point1, actH1, actH2))); | 
					
						
							|  |  |  |   Matrix expH1 = numericalDerivative21<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose1, point1, 1e-5); | 
					
						
							|  |  |  |   Matrix expH2 = numericalDerivative22<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose1, point1, 1e-5); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH1, actH1, tol)); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH2, actH2, tol)); | 
					
						
							| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( testRelativeElevationFactor, level_positive ) { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // Positive meas
 | 
					
						
							|  |  |  |   double measured = 0.0; | 
					
						
							|  |  |  |   RelativeElevationFactor factor(poseKey, pointKey, measured, model1); | 
					
						
							|  |  |  |   Matrix actH1, actH2; | 
					
						
							| 
									
										
										
										
											2013-12-17 05:33:12 +08:00
										 |  |  |   EXPECT(assert_equal((Vector(1) << 2.0), factor.evaluateError(pose1, point1, actH1, actH2))); | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   Matrix expH1 = numericalDerivative21<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose1, point1, 1e-5); | 
					
						
							|  |  |  |   Matrix expH2 = numericalDerivative22<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose1, point1, 1e-5); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH1, actH1, tol)); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH2, actH2, tol)); | 
					
						
							| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( testRelativeElevationFactor, level_negative ) { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // Negative meas
 | 
					
						
							|  |  |  |   double measured = -1.0; | 
					
						
							|  |  |  |   RelativeElevationFactor factor(poseKey, pointKey, measured, model1); | 
					
						
							|  |  |  |   Matrix actH1, actH2; | 
					
						
							| 
									
										
										
										
											2013-12-17 05:33:12 +08:00
										 |  |  |   EXPECT(assert_equal((Vector(1) << 3.0), factor.evaluateError(pose1, point1, actH1, actH2))); | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   Matrix expH1 = numericalDerivative21<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose1, point1, 1e-5); | 
					
						
							|  |  |  |   Matrix expH2 = numericalDerivative22<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose1, point1, 1e-5); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH1, actH1, tol)); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH2, actH2, tol)); | 
					
						
							| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( testRelativeElevationFactor, rotated_zero_error ) { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // Zero error
 | 
					
						
							|  |  |  |   double measured = 2.0; | 
					
						
							|  |  |  |   RelativeElevationFactor factor(poseKey, pointKey, measured, model1); | 
					
						
							|  |  |  |   Matrix actH1, actH2; | 
					
						
							|  |  |  |   EXPECT(assert_equal(zero(1), factor.evaluateError(pose2, point1, actH1, actH2))); | 
					
						
							|  |  |  |   Matrix expH1 = numericalDerivative21<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose2, point1, 1e-5); | 
					
						
							|  |  |  |   Matrix expH2 = numericalDerivative22<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose2, point1, 1e-5); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH1, actH1, tol)); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH2, actH2, tol)); | 
					
						
							| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( testRelativeElevationFactor, rotated_positive ) { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // Positive meas
 | 
					
						
							|  |  |  |   double measured = 0.0; | 
					
						
							|  |  |  |   RelativeElevationFactor factor(poseKey, pointKey, measured, model1); | 
					
						
							|  |  |  |   Matrix actH1, actH2; | 
					
						
							| 
									
										
										
										
											2013-12-17 05:33:12 +08:00
										 |  |  |   EXPECT(assert_equal((Vector(1) << 2.0), factor.evaluateError(pose2, point1, actH1, actH2))); | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   Matrix expH1 = numericalDerivative21<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose2, point1, 1e-5); | 
					
						
							|  |  |  |   Matrix expH2 = numericalDerivative22<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose2, point1, 1e-5); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH1, actH1, tol)); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH2, actH2, tol)); | 
					
						
							| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( testRelativeElevationFactor, rotated_negative1 ) { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // Negative meas
 | 
					
						
							|  |  |  |   double measured = -1.0; | 
					
						
							|  |  |  |   RelativeElevationFactor factor(poseKey, pointKey, measured, model1); | 
					
						
							|  |  |  |   Matrix actH1, actH2; | 
					
						
							| 
									
										
										
										
											2013-12-17 05:33:12 +08:00
										 |  |  |   EXPECT(assert_equal((Vector(1) << 3.0), factor.evaluateError(pose2, point1, actH1, actH2))); | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   Matrix expH1 = numericalDerivative21<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose2, point1, 1e-5); | 
					
						
							|  |  |  |   Matrix expH2 = numericalDerivative22<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose2, point1, 1e-5); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH1, actH1, tol)); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH2, actH2, tol)); | 
					
						
							| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( testRelativeElevationFactor, rotated_negative2 ) { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // Negative meas
 | 
					
						
							|  |  |  |   double measured = -1.0; | 
					
						
							|  |  |  |   RelativeElevationFactor factor(poseKey, pointKey, measured, model1); | 
					
						
							|  |  |  |   Matrix actH1, actH2; | 
					
						
							| 
									
										
										
										
											2013-12-17 05:33:12 +08:00
										 |  |  |   EXPECT(assert_equal((Vector(1) << 3.0), factor.evaluateError(pose3, point1, actH1, actH2))); | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   Matrix expH1 = numericalDerivative21<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose3, point1, 1e-5); | 
					
						
							|  |  |  |   Matrix expH2 = numericalDerivative22<LieVector,Pose3,Point3>( | 
					
						
							|  |  |  |       boost::bind(evalFactorError, factor, _1, _2), pose3, point1, 1e-5); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH1, actH1, tol)); | 
					
						
							|  |  |  |   EXPECT(assert_equal(expH2, actH2, tol)); | 
					
						
							| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { TestResult tr; return TestRegistry::runAllTests(tr); } | 
					
						
							|  |  |  | /* ************************************************************************* */ |