| 
									
										
										
										
											2009-12-11 07:45:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*STL/C++*/ | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <CppUnitLite/TestHarness.h>
 | 
					
						
							|  |  |  | #include "Pose2Graph.h"
 | 
					
						
							| 
									
										
										
										
											2009-12-12 03:32:46 +08:00
										 |  |  | #include "NonlinearFactorGraph-inl.h"
 | 
					
						
							|  |  |  | #include "GaussianFactorGraph.h"
 | 
					
						
							| 
									
										
										
										
											2009-12-11 07:45:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST( Pose2Graph, constructor ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// create a factor between unknown poses p1 and p2
 | 
					
						
							|  |  |  | 	Pose2 measured(2,2,M_PI_2); | 
					
						
							|  |  |  | 	Matrix measurement_covariance = Matrix_(3,3, | 
					
						
							|  |  |  | 			0.25, 0.0, 0.0, | 
					
						
							|  |  |  | 			0.0, 0.25, 0.0, | 
					
						
							|  |  |  | 			0.0, 0.0, 0.01 | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2009-12-12 03:32:46 +08:00
										 |  |  | 	Pose2Factor constraint("x1","x2",measured, measurement_covariance); | 
					
						
							| 
									
										
										
										
											2009-12-11 07:45:38 +08:00
										 |  |  | 	Pose2Graph graph; | 
					
						
							| 
									
										
										
										
											2009-12-12 03:32:46 +08:00
										 |  |  | 	graph.push_back(Pose2Factor::shared_ptr(new Pose2Factor("x1","x2",measured, measurement_covariance))); | 
					
						
							| 
									
										
										
										
											2009-12-11 07:45:38 +08:00
										 |  |  | 	// get the size of the graph
 | 
					
						
							|  |  |  | 	size_t actual = graph.size(); | 
					
						
							|  |  |  | 	// verify
 | 
					
						
							|  |  |  | 	size_t expected = 1; | 
					
						
							|  |  |  | 	CHECK(actual == expected); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-12 03:32:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | TEST( Pose2Graph, linerization ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// create a factor between unknown poses p1 and p2
 | 
					
						
							|  |  |  | 	Pose2 measured(2,2,M_PI_2); | 
					
						
							|  |  |  | 	Matrix measurement_covariance = Matrix_(3,3, | 
					
						
							|  |  |  | 			0.25, 0.0, 0.0, | 
					
						
							|  |  |  | 			0.0, 0.25, 0.0, | 
					
						
							|  |  |  | 			0.0, 0.0, 0.01 | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 	Pose2Factor constraint("x1","x2",measured, measurement_covariance); | 
					
						
							|  |  |  | 	Pose2Graph graph; | 
					
						
							|  |  |  | 	graph.push_back(Pose2Factor::shared_ptr(new Pose2Factor("x1","x2",measured, measurement_covariance))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Choose a linearization point
 | 
					
						
							|  |  |  | 	Pose2 p1(1.1,2,M_PI_2); // robot at (1.1,2) looking towards y (ground truth is at 1,2, see testPose2)
 | 
					
						
							|  |  |  | 	Pose2 p2(-1,4.1,M_PI);  // robot at (-1,4) looking at negative (ground truth is at 4.1,2)
 | 
					
						
							|  |  |  | 	Pose2Config config; | 
					
						
							|  |  |  | 	config.insert("x1",p1); | 
					
						
							|  |  |  | 	config.insert("x2",p2); | 
					
						
							|  |  |  | 	// Linearize
 | 
					
						
							|  |  |  | 	GaussianFactorGraph lfg_linearized = graph.linearize(config); | 
					
						
							| 
									
										
										
										
											2009-12-12 14:18:59 +08:00
										 |  |  | 	//lfg_linearized.print("lfg_actual");
 | 
					
						
							| 
									
										
										
										
											2009-12-12 03:32:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// the expected linear factor
 | 
					
						
							|  |  |  | 	GaussianFactorGraph lfg_expected; | 
					
						
							|  |  |  | 	Matrix A1 = Matrix_(3,3, | 
					
						
							| 
									
										
										
										
											2009-12-22 00:43:23 +08:00
										 |  |  | 	    0.0, 2.0, 4.2, | 
					
						
							|  |  |  | 	    -2.0, 0.0, 4.2, | 
					
						
							|  |  |  | 	    0.0, 0.0, 10.0); | 
					
						
							| 
									
										
										
										
											2009-12-12 03:32:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Matrix A2 = Matrix_(3,3, | 
					
						
							| 
									
										
										
										
											2009-12-22 00:43:23 +08:00
										 |  |  | 	    -2.0, 0.0,  0.0, | 
					
						
							|  |  |  | 	    0.0,-2.0,  0.0, | 
					
						
							|  |  |  | 	    0.0, 0.0, -10.0); | 
					
						
							| 
									
										
										
										
											2009-12-12 03:32:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	double sigma = 1; | 
					
						
							| 
									
										
										
										
											2009-12-22 00:43:23 +08:00
										 |  |  | 	Vector b = Vector_(3,0.1,-0.1,0.0); | 
					
						
							| 
									
										
										
										
											2009-12-12 03:32:46 +08:00
										 |  |  | 	lfg_expected.add("x1", A1, "x2", A2, b, sigma); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-22 00:43:23 +08:00
										 |  |  | 	CHECK(assert_equal(lfg_expected, lfg_linearized)); | 
					
						
							| 
									
										
										
										
											2009-12-12 03:32:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-11 07:45:38 +08:00
										 |  |  | } | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { | 
					
						
							|  |  |  | 	TestResult tr; | 
					
						
							|  |  |  | 	return TestRegistry::runAllTests(tr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /* ************************************************************************* */ |