timeiSAM2Chain.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 
17 #include <gtsam/base/timing.h>
18 #include <gtsam/slam/dataset.h>
19 #include <gtsam/geometry/Pose2.h>
21 #include <gtsam/inference/Symbol.h>
22 #include <gtsam/nonlinear/ISAM2.h>
24 
25 #include <fstream>
26 #include <boost/archive/binary_oarchive.hpp>
27 #include <boost/archive/binary_iarchive.hpp>
28 #include <boost/serialization/export.hpp>
29 #include <boost/random/mersenne_twister.hpp>
30 #include <boost/random/uniform_real.hpp>
31 #include <boost/random/variate_generator.hpp>
32 
33 using namespace std;
34 using namespace gtsam;
35 using namespace gtsam::symbol_shorthand;
36 
37 typedef Pose2 Pose;
38 
41 noiseModel::Unit::shared_ptr model = noiseModel::Unit::Create(3);
42 
43 int main(int argc, char *argv[]) {
44 
45  const size_t steps = 50000;
46 
47  cout << "Playing forward " << steps << " time steps..." << endl;
48 
49  ISAM2 isam2;
50 
51  // Times
52  vector<double> times(steps);
53 
54  for(size_t step=0; step < steps; ++step) {
55 
56  Values newVariables;
57  NonlinearFactorGraph newFactors;
58 
59  // Collect measurements and new variables for the current step
60  gttic_(Create_measurements);
61  if(step == 0) {
62  // Add prior
63  newFactors.addPrior(0, Pose(), noiseModel::Unit::Create(3));
64  newVariables.insert(0, Pose());
65  } else {
66  Vector eta = Vector::Random(3) * 0.1;
67  Pose2 between = Pose().retract(eta);
68  // Add between
69  newFactors.add(BetweenFactor<Pose>(step-1, step, between, model));
70  newVariables.insert(step, isam2.calculateEstimate<Pose>(step-1) * between);
71  }
72 
73  gttoc_(Create_measurements);
74 
75  // Update iSAM2
76  gttic_(Update_ISAM2);
77  isam2.update(newFactors, newVariables);
78  gttoc_(Update_ISAM2);
79 
81 
82  tictoc_getNode(node, Update_ISAM2);
83  times[step] = node->time();
84 
85  if(step % 1000 == 0) {
86  cout << "Step " << step << endl;
87  tictoc_print_();
88  }
89  }
90 
91  tictoc_print_();
92 
93  // Write times
94  ofstream timesFile("times.txt");
95  for(double t: times) {
96  timesFile << t << "\n"; }
97 
98  return 0;
99 }
timing.h
Timing utilities.
Pose2.h
2D Pose
gtsam::ISAM2
Definition: ISAM2.h:45
gtsam::noiseModel::Unit::shared_ptr
std::shared_ptr< Unit > shared_ptr
Definition: NoiseModel.h:621
gtsam::symbol_shorthand
Definition: inference/Symbol.h:147
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
Pose
Pose2 Pose
Definition: timeiSAM2Chain.cpp:37
dataset.h
utility functions for loading datasets
gttoc_
#define gttoc_(label)
Definition: timing.h:250
BetweenFactor.h
gttic_
#define gttic_(label)
Definition: timing.h:245
gtsam::tictoc_finishedIteration_
void tictoc_finishedIteration_()
Definition: timing.h:264
tictoc_getNode
#define tictoc_getNode(variable, label)
Definition: timing.h:276
gtsam::NonlinearFactorGraph
Definition: NonlinearFactorGraph.h:55
gtsam::NoiseModelFactorN
Definition: NonlinearFactor.h:431
gtsam::NonlinearFactorGraph::addPrior
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
Definition: NonlinearFactorGraph.h:199
gtsam::tictoc_print_
void tictoc_print_()
Definition: timing.h:268
gtsam::utils.visual_isam.step
def step(data, isam, result, truth, currPoseIndex, isamArgs=())
Definition: visual_isam.py:82
NM2
NoiseModelFactorN< Pose, Pose > NM2
Definition: timeiSAM2Chain.cpp:40
Symbol.h
gtsam::ISAM2::calculateEstimate
Values calculateEstimate() const
Definition: ISAM2.cpp:785
ISAM2.h
Incremental update functionality (ISAM2) for BayesTree, with fluid relinearization.
gtsam
traits
Definition: SFMdata.h:40
gtsam::ISAM2::update
virtual ISAM2Result update(const NonlinearFactorGraph &newFactors=NonlinearFactorGraph(), const Values &newTheta=Values(), const FactorIndices &removeFactorIndices=FactorIndices(), const std::optional< FastMap< Key, int > > &constrainedKeys={}, const std::optional< FastList< Key > > &noRelinKeys={}, const std::optional< FastList< Key > > &extraReelimKeys={}, bool force_relinearize=false)
Definition: ISAM2.cpp:400
Marginals.h
A class for computing marginals in a NonlinearFactorGraph.
gtsam::Values
Definition: Values.h:65
std
Definition: BFloat16.h:88
gtsam::Values::insert
void insert(Key j, const Value &val)
Definition: Values.cpp:155
main
int main(int argc, char *argv[])
Definition: timeiSAM2Chain.cpp:43
gtsam::testing::between
T between(const T &t1, const T &t2)
Definition: lieProxies.h:36
gtsam::LieGroup::retract
Class retract(const TangentVector &v) const
retract as required by manifold concept: applies v at *this
Definition: Lie.h:131
model
noiseModel::Unit::shared_ptr model
Definition: timeiSAM2Chain.cpp:41
gtsam::FactorGraph::add
IsDerived< DERIVEDFACTOR > add(std::shared_ptr< DERIVEDFACTOR > factor)
add is a synonym for push_back.
Definition: FactorGraph.h:171
align_3::t
Point2 t(10, 10)
NM1
NoiseModelFactorN< Pose > NM1
Definition: timeiSAM2Chain.cpp:39
gtsam::Pose2
Definition: Pose2.h:39
gtsam::BetweenFactor
Definition: BetweenFactor.h:40


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:08:59