| 
									
										
										
										
											2013-06-13 04:01:59 +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 | 
					
						
							|  |  |  | % | 
					
						
							| 
									
										
										
										
											2013-06-20 01:50:01 +08:00
										 |  |  | % @brief Checks for serialization using basic string interface | 
					
						
							| 
									
										
										
										
											2013-06-13 04:01:59 +08:00
										 |  |  | % @author Alex Cunningham | 
					
						
							|  |  |  | % @author Frank Dellaert | 
					
						
							|  |  |  | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import gtsam.* | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | %% Create keys for variables | 
					
						
							|  |  |  | i1 = symbol('x',1); i2 = symbol('x',2); i3 = symbol('x',3); | 
					
						
							|  |  |  | j1 = symbol('l',1); j2 = symbol('l',2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-20 01:50:01 +08:00
										 |  |  | %% Create values and verify string serialization | 
					
						
							|  |  |  | pose1=Pose2(0.5, 0.0, 0.2); | 
					
						
							|  |  |  | pose2=Pose2(2.3, 0.1,-0.2); | 
					
						
							|  |  |  | pose3=Pose2(4.1, 0.1, 0.1); | 
					
						
							|  |  |  | landmark1=Point2(1.8, 2.1); | 
					
						
							|  |  |  | landmark2=Point2(4.1, 1.8); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | serialized_pose1 = pose1.string_serialize(); | 
					
						
							|  |  |  | pose1ds = Pose2.string_deserialize(serialized_pose1); | 
					
						
							|  |  |  | CHECK('pose1ds.equals(pose1, 1e-9)', pose1ds.equals(pose1, 1e-9)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | %% Create and serialize Values | 
					
						
							|  |  |  | values = Values; | 
					
						
							|  |  |  | values.insert(i1, pose1); | 
					
						
							|  |  |  | values.insert(i2, pose2); | 
					
						
							|  |  |  | values.insert(i3, pose3); | 
					
						
							|  |  |  | values.insert(j1, landmark1); | 
					
						
							|  |  |  | values.insert(j2, landmark2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | serialized_values = values.string_serialize(); | 
					
						
							|  |  |  | valuesds = Values.string_deserialize(serialized_values); | 
					
						
							|  |  |  | CHECK('valuesds.equals(values, 1e-9)', valuesds.equals(values, 1e-9)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | %% Create graph and factors and serialize | 
					
						
							| 
									
										
										
										
											2013-06-13 04:01:59 +08:00
										 |  |  | graph = NonlinearFactorGraph; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-20 01:50:07 +08:00
										 |  |  | % Prior factor | 
					
						
							| 
									
										
										
										
											2013-06-13 04:01:59 +08:00
										 |  |  | priorMean = Pose2(0.0, 0.0, 0.0); % prior at origin | 
					
						
							| 
									
										
										
										
											2021-12-14 00:18:52 +08:00
										 |  |  | priorNoise = noiseModel.Diagonal.Sigmas([0.3; 0.3; 0.1]); | 
					
						
							| 
									
										
										
										
											2013-06-13 04:01:59 +08:00
										 |  |  | graph.add(PriorFactorPose2(i1, priorMean, priorNoise)); % add directly to graph | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 07:35:33 +08:00
										 |  |  | % Between Factors | 
					
						
							| 
									
										
										
										
											2013-06-20 01:50:07 +08:00
										 |  |  | odometry = Pose2(2.0, 0.0, 0.0); | 
					
						
							| 
									
										
										
										
											2021-12-14 00:18:52 +08:00
										 |  |  | odometryNoise = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1]); | 
					
						
							| 
									
										
										
										
											2013-06-20 01:50:07 +08:00
										 |  |  | graph.add(BetweenFactorPose2(i1, i2, odometry, odometryNoise)); | 
					
						
							|  |  |  | graph.add(BetweenFactorPose2(i2, i3, odometry, odometryNoise)); | 
					
						
							| 
									
										
										
										
											2013-06-20 01:50:05 +08:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2018-12-31 07:35:33 +08:00
										 |  |  | % Range Factors | 
					
						
							| 
									
										
										
										
											2021-12-14 00:18:52 +08:00
										 |  |  | rNoise = noiseModel.Diagonal.Sigmas([0.2]); | 
					
						
							| 
									
										
										
										
											2019-01-01 00:19:46 +08:00
										 |  |  | graph.add(RangeFactor2D(i1, j1, sqrt(4+4), rNoise)); | 
					
						
							|  |  |  | graph.add(RangeFactor2D(i2, j1, 2, rNoise)); | 
					
						
							|  |  |  | graph.add(RangeFactor2D(i3, j2, 2, rNoise)); | 
					
						
							| 
									
										
										
										
											2018-12-31 07:35:33 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | % Bearing Factors | 
					
						
							| 
									
										
										
										
											2013-06-20 01:50:07 +08:00
										 |  |  | degrees = pi/180; | 
					
						
							| 
									
										
										
										
											2021-12-14 00:18:52 +08:00
										 |  |  | bNoise = noiseModel.Diagonal.Sigmas([0.1]); | 
					
						
							| 
									
										
										
										
											2018-12-31 07:35:33 +08:00
										 |  |  | graph.add(BearingFactor2D(i1, j1, Rot2(45*degrees), bNoise)); | 
					
						
							|  |  |  | graph.add(BearingFactor2D(i2, j1, Rot2(90*degrees), bNoise)); | 
					
						
							|  |  |  | graph.add(BearingFactor2D(i3, j2, Rot2(90*degrees), bNoise)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | % BearingRange Factors | 
					
						
							| 
									
										
										
										
											2021-12-14 00:18:52 +08:00
										 |  |  | brNoise = noiseModel.Diagonal.Sigmas([0.1; 0.2]); | 
					
						
							| 
									
										
										
										
											2013-06-20 01:50:07 +08:00
										 |  |  | graph.add(BearingRangeFactor2D(i1, j1, Rot2(45*degrees), sqrt(4+4), brNoise)); | 
					
						
							|  |  |  | graph.add(BearingRangeFactor2D(i2, j1, Rot2(90*degrees), 2, brNoise)); | 
					
						
							|  |  |  | graph.add(BearingRangeFactor2D(i3, j2, Rot2(90*degrees), 2, brNoise)); | 
					
						
							| 
									
										
										
										
											2013-06-13 04:01:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-20 01:50:05 +08:00
										 |  |  | serialized_graph = graph.string_serialize(); | 
					
						
							|  |  |  | graphds = NonlinearFactorGraph.string_deserialize(serialized_graph); | 
					
						
							| 
									
										
										
										
											2013-06-20 01:50:07 +08:00
										 |  |  | CHECK('graphds.equals(graph, 1e-9)', graphds.equals(graph, 1e-9)); |