Pose2SLAMExample_graphviz.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 // For an explanation of headers below, please see Pose2SLAMExample.cpp
21 #include <gtsam/geometry/Pose2.h>
23 #include <fstream>
24 
25 using namespace std;
26 using namespace gtsam;
27 
28 int main(int argc, char** argv) {
29  // 1. Create a factor graph container and add factors to it
31 
32  // 2a. Add a prior on the first pose, setting it to the origin
33  auto priorNoise = noiseModel::Diagonal::Sigmas(Vector3(0.3, 0.3, 0.1));
34  graph.addPrior(1, Pose2(0, 0, 0), priorNoise);
35 
36  // For simplicity, we will use the same noise model for odometry and loop
37  // closures
38  auto model = noiseModel::Diagonal::Sigmas(Vector3(0.2, 0.2, 0.1));
39 
40  // 2b. Add odometry factors
45 
46  // 2c. Add the loop closure constraint
48 
49  // 3. Create the data structure to hold the initial estimate to the solution
50  // For illustrative purposes, these have been deliberately set to incorrect values
52  initial.insert(1, Pose2(0.5, 0.0, 0.2));
53  initial.insert(2, Pose2(2.3, 0.1, -0.2));
54  initial.insert(3, Pose2(4.1, 0.1, M_PI_2));
55  initial.insert(4, Pose2(4.0, 2.0, M_PI));
56  initial.insert(5, Pose2(2.1, 2.1, -M_PI_2));
57 
58  // Single Step Optimization using Levenberg-Marquardt
60 
61  // save factor graph as graphviz dot file
62  // Render to PDF using "fdp Pose2SLAMExample.dot -Tpdf > graph.pdf"
63  graph.saveGraph("Pose2SLAMExample.dot", result);
64 
65  // Also print out to console
66  graph.dot(cout, result);
67 
68  return 0;
69 }
Pose2.h
2D Pose
gtsam::NonlinearOptimizer::optimize
virtual const Values & optimize()
Definition: NonlinearOptimizer.h:98
LevenbergMarquardtOptimizer.h
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
initial
Values initial
Definition: OdometryOptimize.cpp:2
gtsam::Vector3
Eigen::Vector3d Vector3
Definition: Vector.h:43
gtsam::NonlinearFactorGraph::saveGraph
void saveGraph(const std::string &filename, const Values &values, const KeyFormatter &keyFormatter=DefaultKeyFormatter, const GraphvizFormatting &writer=GraphvizFormatting()) const
output to file with graphviz format, with Values/extra options.
Definition: NonlinearFactorGraph.cpp:160
result
Values result
Definition: OdometryOptimize.cpp:8
gtsam::NonlinearFactorGraph::dot
void dot(std::ostream &os, const Values &values, const KeyFormatter &keyFormatter=DefaultKeyFormatter, const GraphvizFormatting &writer=GraphvizFormatting()) const
Output to graphviz format, stream version, with Values/extra options.
Definition: NonlinearFactorGraph.cpp:102
BetweenFactor.h
gtsam::NonlinearFactorGraph
Definition: NonlinearFactorGraph.h:55
gtsam::NonlinearFactorGraph::addPrior
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
Definition: NonlinearFactorGraph.h:199
main
int main(int argc, char **argv)
Definition: Pose2SLAMExample_graphviz.cpp:28
gtsam::LevenbergMarquardtOptimizer
Definition: LevenbergMarquardtOptimizer.h:35
priorNoise
auto priorNoise
Definition: doc/Code/OdometryExample.cpp:6
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
M_PI_2
#define M_PI_2
Definition: mconf.h:118
gtsam
traits
Definition: SFMdata.h:40
gtsam::Values
Definition: Values.h:65
std
Definition: BFloat16.h:88
initial
Definition: testScenarioRunner.cpp:148
M_PI
#define M_PI
Definition: mconf.h:117
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
gtsam::FactorGraph::emplace_shared
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
Definition: FactorGraph.h:153
gtsam::Pose2
Definition: Pose2.h:39
gtsam::BetweenFactor
Definition: BetweenFactor.h:40


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:03:36