| 
									
										
										
										
											2012-06-04 08:41:13 +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 | 
					
						
							|  |  |  | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | %% Create a hexagon of poses | 
					
						
							|  |  |  | hexagon = pose3SLAMValues_Circle(6,1.0); | 
					
						
							|  |  |  | p0 = hexagon.pose(0); | 
					
						
							|  |  |  | p1 = hexagon.pose(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | %% create a Pose graph with one equality constraint and one measurement | 
					
						
							|  |  |  | fg = pose3SLAMGraph; | 
					
						
							| 
									
										
										
										
											2012-06-24 10:48:12 +08:00
										 |  |  | fg.addPoseConstraint(0, p0); | 
					
						
							| 
									
										
										
										
											2012-06-04 08:41:13 +08:00
										 |  |  | delta = p0.between(p1); | 
					
						
							| 
									
										
										
										
											2012-06-23 03:36:49 +08:00
										 |  |  | covariance = gtsamnoiseModelDiagonal_Sigmas([0.05; 0.05; 0.05; 5*pi/180; 5*pi/180; 5*pi/180]); | 
					
						
							| 
									
										
										
										
											2012-06-24 10:48:12 +08:00
										 |  |  | fg.addRelativePose(0,1, delta, covariance); | 
					
						
							|  |  |  | fg.addRelativePose(1,2, delta, covariance); | 
					
						
							|  |  |  | fg.addRelativePose(2,3, delta, covariance); | 
					
						
							|  |  |  | fg.addRelativePose(3,4, delta, covariance); | 
					
						
							|  |  |  | fg.addRelativePose(4,5, delta, covariance); | 
					
						
							|  |  |  | fg.addRelativePose(5,0, delta, covariance); | 
					
						
							| 
									
										
										
										
											2012-06-04 08:41:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | %% Create initial config | 
					
						
							|  |  |  | initial = pose3SLAMValues; | 
					
						
							|  |  |  | s = 0.10; | 
					
						
							|  |  |  | initial.insertPose(0, p0); | 
					
						
							|  |  |  | initial.insertPose(1, hexagon.pose(1).retract(s*randn(6,1))); | 
					
						
							|  |  |  | initial.insertPose(2, hexagon.pose(2).retract(s*randn(6,1))); | 
					
						
							|  |  |  | initial.insertPose(3, hexagon.pose(3).retract(s*randn(6,1))); | 
					
						
							|  |  |  | initial.insertPose(4, hexagon.pose(4).retract(s*randn(6,1))); | 
					
						
							|  |  |  | initial.insertPose(5, hexagon.pose(5).retract(s*randn(6,1))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | %% Plot Initial Estimate | 
					
						
							| 
									
										
										
										
											2012-06-12 12:38:05 +08:00
										 |  |  | cla | 
					
						
							| 
									
										
										
										
											2012-06-24 10:48:12 +08:00
										 |  |  | T=initial.translations(); | 
					
						
							|  |  |  | plot3(T(:,1),T(:,2),T(:,3),'g-*'); | 
					
						
							| 
									
										
										
										
											2012-06-04 08:41:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | %% optimize | 
					
						
							| 
									
										
										
										
											2012-06-24 10:48:12 +08:00
										 |  |  | result = fg.optimize(initial,1); | 
					
						
							| 
									
										
										
										
											2012-06-04 08:41:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | %% Show Result | 
					
						
							| 
									
										
										
										
											2012-06-13 20:22:31 +08:00
										 |  |  | hold on; plot3DTrajectory(result,'b-*', true, 0.3); | 
					
						
							|  |  |  | axis([-2 2 -2 2 -1 1]); | 
					
						
							|  |  |  | axis equal | 
					
						
							|  |  |  | view(-37,40) | 
					
						
							|  |  |  | colormap hot | 
					
						
							| 
									
										
										
										
											2012-06-04 08:41:13 +08:00
										 |  |  | result.print(sprintf('\nFinal result:\n')); |