gtsam/examples/Pose2SLAMExample_lago.cpp

65 lines
2.0 KiB
C++
Raw Normal View History

2014-05-21 06:12:26 +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
* -------------------------------------------------------------------------- */
/**
* @file Pose2SLAMExample_lago.cpp
* @brief A 2D Pose SLAM example that reads input from g2o, and solve the Pose2 problem
2014-06-01 00:51:47 +08:00
* using LAGO (Linear Approximation for Graph Optimization). See class lago.h
2014-05-21 06:12:26 +08:00
* Output is written on a file, in g2o format
* Syntax for the script is ./Pose2SLAMExample_lago input.g2o output.g2o
* @date May 15, 2014
* @author Luca Carlone
*/
2014-06-02 00:25:23 +08:00
#include <gtsam/slam/lago.h>
2014-05-21 06:12:26 +08:00
#include <gtsam/slam/dataset.h>
2015-02-21 20:49:53 +08:00
#include <gtsam/geometry/Pose2.h>
2014-05-21 06:12:26 +08:00
#include <fstream>
using namespace std;
using namespace gtsam;
2014-06-01 00:51:47 +08:00
int main(const int argc, const char *argv[]) {
// Read graph from file
string g2oFile;
2014-05-21 06:12:26 +08:00
if (argc < 2)
g2oFile = findExampleDataFile("noisyToyGraph.txt");
2014-06-01 00:51:47 +08:00
else
g2oFile = argv[1];
2014-05-21 06:12:26 +08:00
NonlinearFactorGraph::shared_ptr graph;
Values::shared_ptr initial;
2023-01-19 08:32:29 +08:00
std::tie(graph, initial) = readG2o(g2oFile);
2014-05-21 06:12:26 +08:00
// Add prior on the pose having index (key) = 0
2020-05-10 07:08:31 +08:00
auto priorModel = noiseModel::Diagonal::Variances(Vector3(1e-6, 1e-6, 1e-8));
2020-04-13 01:10:09 +08:00
graph->addPrior(0, Pose2(), priorModel);
graph->print();
2014-05-21 06:12:26 +08:00
std::cout << "Computing LAGO estimate" << std::endl;
Values estimateLago = lago::initialize(*graph);
2014-05-21 06:12:26 +08:00
std::cout << "done!" << std::endl;
2014-06-01 00:51:47 +08:00
if (argc < 3) {
estimateLago.print("estimateLago");
} else {
const string outputFile = argv[2];
std::cout << "Writing results to file: " << outputFile << std::endl;
NonlinearFactorGraph::shared_ptr graphNoKernel;
Values::shared_ptr initial2;
2023-01-19 08:32:29 +08:00
std::tie(graphNoKernel, initial2) = readG2o(g2oFile);
writeG2o(*graphNoKernel, estimateLago, outputFile);
2014-06-01 00:51:47 +08:00
std::cout << "done! " << std::endl;
}
2014-05-21 06:12:26 +08:00
return 0;
}