PlanarSLAMExample.m 975 B

12345678910111213141516171819202122232425
  1. % Create graph container and add factors to it
  2. graph = NonlinearFactorGraph;
  3. % Create keys for variables
  4. i1 = symbol('x',1); i2 = symbol('x',2); i3 = symbol('x',3);
  5. j1 = symbol('l',1); j2 = symbol('l',2);
  6. % Add prior
  7. priorMean = Pose2(0.0, 0.0, 0.0); % prior at origin
  8. priorNoise = noiseModel.Diagonal.Sigmas([0.3; 0.3; 0.1]);
  9. % add directly to graph
  10. graph.add(PriorFactorPose2(i1, priorMean, priorNoise));
  11. % Add odometry
  12. odometry = Pose2(2.0, 0.0, 0.0);
  13. odometryNoise = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1]);
  14. graph.add(BetweenFactorPose2(i1, i2, odometry, odometryNoise));
  15. graph.add(BetweenFactorPose2(i2, i3, odometry, odometryNoise));
  16. % Add bearing/range measurement factors
  17. degrees = pi/180;
  18. brNoise = noiseModel.Diagonal.Sigmas([0.1; 0.2]);
  19. graph.add(BearingRangeFactor2D(i1, j1, Rot2(45*degrees), sqrt(8), brNoise));
  20. graph.add(BearingRangeFactor2D(i2, j1, Rot2(90*degrees), 2, brNoise));
  21. graph.add(BearingRangeFactor2D(i3, j2, Rot2(90*degrees), 2, brNoise));