| 
									
										
										
										
											2010-01-16 09:16:59 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  *  @file  testPlanarSLAM.cpp | 
					
						
							|  |  |  |  *  @authors Frank Dellaert | 
					
						
							|  |  |  |  **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | #include <CppUnitLite/TestHarness.h>
 | 
					
						
							| 
									
										
										
										
											2010-01-18 13:38:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-16 09:16:59 +08:00
										 |  |  | #include "planarSLAM.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // some shared test values
 | 
					
						
							| 
									
										
										
										
											2010-01-18 13:38:53 +08:00
										 |  |  | static Pose2 x1, x2(1, 1, 0), x3(1, 1, M_PI_4); | 
					
						
							|  |  |  | static Point2 l1(1, 0), l2(1, 1), l3(2, 2), l4(1, 3); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-23 01:36:57 +08:00
										 |  |  | SharedGaussian | 
					
						
							| 
									
										
										
										
											2010-01-18 13:38:53 +08:00
										 |  |  | 	sigma(noiseModel::Isotropic::Sigma(1,0.1)), | 
					
						
							|  |  |  | 	I3(noiseModel::Unit::Create(3)); | 
					
						
							| 
									
										
										
										
											2010-01-16 09:16:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( planarSLAM, BearingFactor ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// Create factor
 | 
					
						
							|  |  |  | 	Rot2 z(M_PI_4 + 0.1); // h(x) - z = -0.1
 | 
					
						
							|  |  |  | 	planarSLAM::Bearing factor(2, 3, z, sigma); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// create config
 | 
					
						
							|  |  |  | 	planarSLAM::Config c; | 
					
						
							|  |  |  | 	c.insert(2, x2); | 
					
						
							|  |  |  | 	c.insert(3, l3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Check error
 | 
					
						
							| 
									
										
										
										
											2010-01-18 13:38:53 +08:00
										 |  |  | 	Vector actual = factor.unwhitenedError(c); | 
					
						
							| 
									
										
										
										
											2010-01-16 09:16:59 +08:00
										 |  |  | 	CHECK(assert_equal(Vector_(1,-0.1),actual)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( planarSLAM, RangeFactor ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// Create factor
 | 
					
						
							|  |  |  | 	double z(sqrt(2) - 0.22); // h(x) - z = 0.22
 | 
					
						
							|  |  |  | 	planarSLAM::Range factor(2, 3, z, sigma); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// create config
 | 
					
						
							|  |  |  | 	planarSLAM::Config c; | 
					
						
							|  |  |  | 	c.insert(2, x2); | 
					
						
							|  |  |  | 	c.insert(3, l3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Check error
 | 
					
						
							| 
									
										
										
										
											2010-01-18 13:38:53 +08:00
										 |  |  | 	Vector actual = factor.unwhitenedError(c); | 
					
						
							| 
									
										
										
										
											2010-01-16 09:16:59 +08:00
										 |  |  | 	CHECK(assert_equal(Vector_(1,0.22),actual)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( planarSLAM, constructor ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// create config
 | 
					
						
							|  |  |  | 	planarSLAM::Config c; | 
					
						
							|  |  |  | 	c.insert(2, x2); | 
					
						
							|  |  |  | 	c.insert(3, x3); | 
					
						
							|  |  |  | 	c.insert(3, l3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// create graph
 | 
					
						
							|  |  |  | 	planarSLAM::Graph G; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Add pose constraint
 | 
					
						
							|  |  |  | 	G.addPoseConstraint(2, x2); // make it feasible :-)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Add odometry
 | 
					
						
							| 
									
										
										
										
											2010-01-18 13:38:53 +08:00
										 |  |  | 	G.addOdometry(2, 3, Pose2(0, 0, M_PI_4), I3); | 
					
						
							| 
									
										
										
										
											2010-01-16 09:16:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Create bearing factor
 | 
					
						
							|  |  |  | 	Rot2 z1(M_PI_4 + 0.1); // h(x) - z = -0.1
 | 
					
						
							| 
									
										
										
										
											2010-01-18 13:38:53 +08:00
										 |  |  | 	G.addBearing(2, 3, z1, sigma); | 
					
						
							| 
									
										
										
										
											2010-01-16 09:16:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Create range factor
 | 
					
						
							|  |  |  | 	double z2(sqrt(2) - 0.22); // h(x) - z = 0.22
 | 
					
						
							| 
									
										
										
										
											2010-01-18 13:38:53 +08:00
										 |  |  | 	G.addRange(2, 3, z2, sigma); | 
					
						
							| 
									
										
										
										
											2010-01-16 09:16:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Vector expected = Vector_(8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.1, 0.22); | 
					
						
							| 
									
										
										
										
											2010-01-18 13:38:53 +08:00
										 |  |  | 	CHECK(assert_equal(expected,G.unwhitenedError(c))); | 
					
						
							| 
									
										
										
										
											2010-01-16 09:16:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { | 
					
						
							|  |  |  | 	TestResult tr; | 
					
						
							|  |  |  | 	return TestRegistry::runAllTests(tr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /* ************************************************************************* */ |