| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation, | 
					
						
							|  |  |  |  * Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  |  * All Rights Reserved | 
					
						
							|  |  |  |  * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @file Pose2SLAMExample_graph->cpp | 
					
						
							|  |  |  |  * @brief Read graph from file and perform GraphSLAM | 
					
						
							|  |  |  |  * @date June 3, 2012 | 
					
						
							|  |  |  |  * @author Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <gtsam/slam/dataset.h>
 | 
					
						
							| 
									
										
										
										
											2012-07-30 22:59:18 +08:00
										 |  |  | #include <gtsam/slam/PriorFactor.h>
 | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | #include <gtsam/nonlinear/Marginals.h>
 | 
					
						
							| 
									
										
										
										
											2012-07-30 22:59:18 +08:00
										 |  |  | #include <gtsam/nonlinear/LevenbergMarquardtOptimizer.h>
 | 
					
						
							|  |  |  | #include <gtsam/nonlinear/NonlinearFactorGraph.h>
 | 
					
						
							|  |  |  | #include <gtsam/nonlinear/Values.h>
 | 
					
						
							|  |  |  | #include <gtsam/geometry/Pose2.h>
 | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | #include <boost/tuple/tuple.hpp>
 | 
					
						
							|  |  |  | #include <cmath>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main(int argc, char** argv) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Read File and create graph and initial estimate
 | 
					
						
							|  |  |  | 	// we are in build/examples, data is in examples/Data
 | 
					
						
							| 
									
										
										
										
											2012-07-30 22:59:18 +08:00
										 |  |  | 	NonlinearFactorGraph::shared_ptr graph ; | 
					
						
							|  |  |  | 	Values::shared_ptr initial; | 
					
						
							|  |  |  | 	SharedDiagonal model = noiseModel::Diagonal::Sigmas(Vector_(3, 0.05, 0.05, 5.0*M_PI/180.0)); | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | 	boost::tie(graph,initial) = load2D("../../examples/Data/w100-odom.graph",model); | 
					
						
							|  |  |  | 	initial->print("Initial estimate:\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Add a Gaussian prior on first poses
 | 
					
						
							|  |  |  | 	Pose2 priorMean(0.0, 0.0, 0.0); // prior at origin
 | 
					
						
							| 
									
										
										
										
											2012-07-30 22:59:18 +08:00
										 |  |  | 	SharedDiagonal priorNoise = noiseModel::Diagonal::Sigmas(Vector_(3, 0.01, 0.01, 0.01)); | 
					
						
							|  |  |  | 	graph->add(PriorFactor<Pose2>(0, priorMean, priorNoise)); | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Single Step Optimization using Levenberg-Marquardt
 | 
					
						
							| 
									
										
										
										
											2012-07-30 22:59:18 +08:00
										 |  |  | 	Values result = LevenbergMarquardtOptimizer(*graph, *initial).optimize(); | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | 	result.print("\nFinal result:\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Plot the covariance of the last pose
 | 
					
						
							|  |  |  | 	Marginals marginals(*graph, result); | 
					
						
							|  |  |  | 	cout.precision(2); | 
					
						
							|  |  |  |   cout << "\nP3:\n" << marginals.marginalCovariance(99) << endl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | return 0; | 
					
						
							|  |  |  | } |