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 }
def step(data, isam, result, truth, currPoseIndex)
Definition: visual_isam.py:82
#define tictoc_getNode(variable, label)
Definition: timing.h:261
NoiseModelFactor1< Pose > NM1
boost::shared_ptr< Unit > shared_ptr
Definition: NoiseModel.h:601
NoiseModelFactor2< Pose, Pose > NM2
#define gttic_(label)
Definition: timing.h:230
Pose2 Pose
T between(const T &t1, const T &t2)
Definition: lieProxies.h:36
void insert(Key j, const Value &val)
Definition: Values.cpp:140
noiseModel::Unit::shared_ptr model
Definition: Half.h:150
IsDerived< DERIVEDFACTOR > add(boost::shared_ptr< DERIVEDFACTOR > factor)
add is a synonym for push_back.
Definition: FactorGraph.h:190
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
Values calculateEstimate() const
Definition: ISAM2.cpp:763
Eigen::VectorXd Vector
Definition: Vector.h:38
Incremental update functionality (ISAM2) for BayesTree, with fluid relinearization.
void tictoc_print_()
Definition: timing.h:253
traits
Definition: chartTesting.h:28
Class retract(const TangentVector &v) const
retract as required by manifold concept: applies v at *this
Definition: Lie.h:130
virtual ISAM2Result update(const NonlinearFactorGraph &newFactors=NonlinearFactorGraph(), const Values &newTheta=Values(), const FactorIndices &removeFactorIndices=FactorIndices(), const boost::optional< FastMap< Key, int > > &constrainedKeys=boost::none, const boost::optional< FastList< Key > > &noRelinKeys=boost::none, const boost::optional< FastList< Key > > &extraReelimKeys=boost::none, bool force_relinearize=false)
Definition: ISAM2.cpp:396
A class for computing marginals in a NonlinearFactorGraph.
void tictoc_finishedIteration_()
Definition: timing.h:249
2D Pose
int main(int argc, char *argv[])
#define gttoc_(label)
Definition: timing.h:235
utility functions for loading datasets
Timing utilities.
Point2 t(10, 10)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:50:34