| 
									
										
										
										
											2012-06-03 13:26:30 +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 | 
					
						
							|  |  |  | % | 
					
						
							|  |  |  | % @brief Read graph from file and perform GraphSLAM | 
					
						
							|  |  |  | % @author Frank Dellaert | 
					
						
							|  |  |  | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | %% Initialize graph, initial estimate, and odometry noise | 
					
						
							|  |  |  | model = gtsamSharedNoiseModel_Sigmas([0.05; 0.05; 5*pi/180]); | 
					
						
							|  |  |  | [graph,initial]=load2D('../Data/w100-odom.graph',model); | 
					
						
							| 
									
										
										
										
											2012-06-04 04:12:12 +08:00
										 |  |  | initial.print(sprintf('Initial estimate:\n')); | 
					
						
							| 
									
										
										
										
											2012-06-03 13:26:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | %% Add a Gaussian prior on pose x_1 | 
					
						
							|  |  |  | priorMean = gtsamPose2(0.0, 0.0, 0.0); % prior mean is at origin | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | priorNoise = gtsamSharedNoiseModel_Sigmas([0.01; 0.01; 0.01]); | 
					
						
							| 
									
										
										
										
											2012-06-03 13:26:30 +08:00
										 |  |  | graph.addPrior(0, priorMean, priorNoise); % add directly to graph | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | %% Plot Initial Estimate | 
					
						
							| 
									
										
										
										
											2012-06-03 23:44:39 +08:00
										 |  |  | figure(1);clf | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | plot(initial.xs(),initial.ys(),'g-*'); axis equal | 
					
						
							| 
									
										
										
										
											2012-06-03 13:26:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | %% Optimize using Levenberg-Marquardt optimization with an ordering from colamd | 
					
						
							| 
									
										
										
										
											2012-06-03 23:44:39 +08:00
										 |  |  | result = graph.optimize(initial); | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | hold on; plot(result.xs(),result.ys(),'b-*') | 
					
						
							| 
									
										
										
										
											2012-06-04 04:12:12 +08:00
										 |  |  | result.print(sprintf('\nFinal result:\n')); | 
					
						
							| 
									
										
										
										
											2012-06-03 13:26:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | %% Plot Covariance Ellipses | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | marginals = graph.marginals(result); | 
					
						
							|  |  |  | for i=1:result.size()-1 | 
					
						
							|  |  |  |     pose_i = result.pose(i); | 
					
						
							|  |  |  |     P{i}=marginals.marginalCovariance(i); | 
					
						
							| 
									
										
										
										
											2012-06-05 08:17:37 +08:00
										 |  |  |     plotPose2(pose_i,'b',P{i}) | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | end | 
					
						
							|  |  |  | fprintf(1,'%.5f %.5f %.5f\n',P{99}) |