gtsam
GTSAM is a library of C++ classes that implement smoothing and mapping (SAM) in robotics and vision, using factor graphs and Bayes networks as the underlying computing paradigm rather than sparse matrices.
Top Related Projects
A large scale non-linear optimization library
g2o: A General Framework for Graph Optimization
C++ implementation of Lie Groups using Eigen.
The Kalibr visual-inertial calibration toolbox
Quick Overview
GTSAM is an open-source C++ library that implements smoothing and mapping (SAM) in robotics and vision, using factor graphs and Bayes networks as the underlying computing paradigm. It provides a set of nonlinear factor types and inference algorithms to solve simultaneous localization and mapping (SLAM) and structure from motion (SFM) problems.
Pros
- High performance and efficiency due to its C++ implementation
- Flexible and extensible architecture allowing for custom factors and noise models
- Comprehensive documentation and examples for various use cases
- Active community and ongoing development
Cons
- Steep learning curve for beginners due to its complex mathematical foundations
- Limited support for real-time applications compared to some alternatives
- Primarily focused on C++, with limited bindings for other languages
- Can be computationally intensive for large-scale problems
Code Examples
- Creating a simple 2D pose graph:
#include <gtsam/slam/PriorFactor.h>
#include <gtsam/slam/BetweenFactor.h>
#include <gtsam/nonlinear/NonlinearFactorGraph.h>
#include <gtsam/nonlinear/LevenbergMarquardtOptimizer.h>
#include <gtsam/nonlinear/Values.h>
using namespace gtsam;
int main() {
NonlinearFactorGraph graph;
Values initialEstimate;
// Add a prior on the first pose, setting it to the origin
Pose2 priorMean(0.0, 0.0, 0.0);
noiseModel::Diagonal::shared_ptr priorNoise = noiseModel::Diagonal::Sigmas(Vector3(0.3, 0.3, 0.1));
graph.add(PriorFactor<Pose2>(1, priorMean, priorNoise));
// Add odometry factors
Pose2 odometry(2.0, 0.0, 0.0);
noiseModel::Diagonal::shared_ptr odometryNoise = noiseModel::Diagonal::Sigmas(Vector3(0.2, 0.2, 0.1));
graph.add(BetweenFactor<Pose2>(1, 2, odometry, odometryNoise));
// Initialize the first pose at the origin
initialEstimate.insert(1, Pose2(0.0, 0.0, 0.0));
initialEstimate.insert(2, Pose2(2.0, 0.0, 0.0));
// Optimize using Levenberg-Marquardt optimization
LevenbergMarquardtOptimizer optimizer(graph, initialEstimate);
Values result = optimizer.optimize();
return 0;
}
- Adding a landmark to a 2D SLAM problem:
#include <gtsam/slam/BearingRangeFactor.h>
// ... (previous includes and setup)
int main() {
// ... (previous graph and initial estimate setup)
// Add a landmark
Point2 landmark(5.0, 1.0);
initialEstimate.insert(L1, landmark);
// Add a measurement to the landmark
Rot2 bearing = Rot2::fromDegrees(45);
double range = 5.0;
graph.add(BearingRangeFactor<Pose2, Point2>(1, L1, bearing, range, measurementNoise));
// ... (optimization and result handling)
}
- Using ISAM2 for incremental SLAM:
#include <gtsam/nonlinear/ISAM2.h>
// ... (previous includes and setup)
int main() {
ISAM2Params parameters;
parameters.relinearizeThreshold = 0.01;
parameters.relinearizeSkip = 1;
ISAM2 isam(parameters);
for (int i = 0; i < numPoses; ++i) {
NonlinearFactorGraph newFactors
Competitor Comparisons
A large scale non-linear optimization library
Pros of Ceres Solver
- More flexible problem formulation, allowing for a wider range of optimization problems
- Better performance for large-scale problems with sparse structure
- More extensive documentation and examples
Cons of Ceres Solver
- Steeper learning curve, especially for users new to optimization
- Less intuitive API for factor graph problems compared to GTSAM
- Requires more manual setup for certain types of problems
Code Comparison
GTSAM example (factor graph):
NonlinearFactorGraph graph;
graph.add(PriorFactor<Pose3>(X(1), pose_prior, prior_noise));
graph.add(BetweenFactor<Pose3>(X(1), X(2), odom, odom_noise));
Ceres Solver example (general optimization):
ceres::Problem problem;
problem.AddResidualBlock(
new ceres::AutoDiffCostFunction<CostFunctor, 1, 1>(new CostFunctor),
nullptr,
&x);
Both libraries are powerful optimization tools, but GTSAM is more specialized for factor graphs and SLAM problems, while Ceres Solver offers more flexibility for general optimization tasks.
g2o: A General Framework for Graph Optimization
Pros of g2o
- More flexible and extensible architecture, allowing easier implementation of custom graph optimization problems
- Generally faster execution times for large-scale optimization problems
- Better support for 3D vision and robotics applications
Cons of g2o
- Steeper learning curve and more complex API compared to GTSAM
- Less comprehensive documentation and tutorials
- Smaller community and fewer maintained examples
Code Comparison
g2o:
g2o::SparseOptimizer optimizer;
g2o::BlockSolver_6_3::LinearSolverType* linearSolver;
linearSolver = new g2o::LinearSolverEigen<g2o::BlockSolver_6_3::PoseMatrixType>();
g2o::BlockSolver_6_3* solver_ptr = new g2o::BlockSolver_6_3(linearSolver);
g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg(solver_ptr);
GTSAM:
gtsam::NonlinearFactorGraph graph;
gtsam::Values initialEstimate;
gtsam::LevenbergMarquardtOptimizer optimizer(graph, initialEstimate);
gtsam::Values result = optimizer.optimize();
Both libraries offer powerful optimization capabilities, but g2o provides more flexibility at the cost of complexity, while GTSAM offers a more straightforward API with extensive documentation.
C++ implementation of Lie Groups using Eigen.
Pros of Sophus
- Lightweight and focused on Lie groups and algebras
- Easier to integrate into existing projects due to its simplicity
- Header-only library, simplifying build processes
Cons of Sophus
- Limited scope compared to GTSAM's comprehensive functionality
- Fewer optimization and estimation tools
- Smaller community and less extensive documentation
Code Comparison
Sophus example (rotation matrix to quaternion):
Sophus::SO3d R = Sophus::SO3d::exp(Sophus::Vector3d(0.1, 0.2, 0.3));
Eigen::Quaterniond q = R.unit_quaternion();
GTSAM example (rotation matrix to quaternion):
gtsam::Rot3 R = gtsam::Rot3::Expmap(gtsam::Vector3(0.1, 0.2, 0.3));
gtsam::Quaternion q = R.quaternion();
Both libraries provide similar functionality for basic operations, but GTSAM offers a more extensive set of tools for complex robotics and computer vision tasks. Sophus is more focused on efficient Lie group operations, while GTSAM provides a broader range of probabilistic inference and optimization capabilities.
The Kalibr visual-inertial calibration toolbox
Pros of Kalibr
- Specialized for camera-IMU calibration and multi-sensor calibration
- User-friendly GUI for visualization and parameter tuning
- Supports various camera models and sensor configurations
Cons of Kalibr
- More limited in scope compared to GTSAM's general-purpose optimization
- Less active development and community support
- Primarily focused on calibration, lacking broader SLAM capabilities
Code Comparison
Kalibr (Python-based calibration):
import kalibr_common as kc
import kalibr_camera_calibration as kcc
cam = kc.CameraGeometry(geometry_type='pinhole-radtan')
imu = kc.ImuParameters()
calib = kcc.CameraImuCalibration(cam, imu)
calib.optimize()
GTSAM (C++ factor graph optimization):
#include <gtsam/nonlinear/NonlinearFactorGraph.h>
#include <gtsam/slam/PriorFactor.h>
gtsam::NonlinearFactorGraph graph;
graph.add(gtsam::PriorFactor<gtsam::Pose3>(1, initialPose, noisePrior));
gtsam::Values result = gtsam::LevenbergMarquardtOptimizer(graph, initial).optimize();
Both repositories serve different primary purposes, with Kalibr focusing on sensor calibration and GTSAM offering a broader range of optimization tools for various robotics and computer vision applications.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
README - Georgia Tech Smoothing and Mapping Library
Important Note
As of January 2023, the develop
branch is officially in "Pre 4.3" mode. We envision several API-breaking changes as we switch to C++17 and away from boost.
In addition, features deprecated in 4.2 will be removed. Please use the stable 4.2 release if you need those features. However, most are easily converted and can be tracked down (in 4.2) by disabling the cmake flag GTSAM_ALLOW_DEPRECATED_SINCE_V42
.
What is GTSAM?
GTSAM is a C++ library that implements smoothing and mapping (SAM) in robotics and vision, using Factor Graphs and Bayes Networks as the underlying computing paradigm rather than sparse matrices.
The current support matrix is:
Platform | Compiler | Build Status |
---|---|---|
Ubuntu 20.04/22.04 | gcc/clang | |
macOS | clang | |
Windows | MSVC |
On top of the C++ library, GTSAM includes wrappers for MATLAB & Python.
Quickstart
In the root library folder execute:
#!bash
mkdir build
cd build
cmake ..
make check (optional, runs unit tests)
make install
Prerequisites:
- Boost >= 1.65 (Ubuntu:
sudo apt-get install libboost-all-dev
) - CMake >= 3.0 (Ubuntu:
sudo apt-get install cmake
) - A modern compiler, i.e., at least gcc 4.7.3 on Linux.
Optional prerequisites - used automatically if findable by CMake:
- Intel Threaded Building Blocks (TBB) (Ubuntu:
sudo apt-get install libtbb-dev
) - Intel Math Kernel Library (MKL) (Ubuntu: installing using APT)
- See INSTALL.md for more installation information
- Note that MKL may not provide a speedup in all cases. Make sure to benchmark your problem with and without MKL.
GTSAM 4 Compatibility
GTSAM 4 introduces several new features, most notably Expressions and a Python toolbox. It also introduces traits, a C++ technique that allows optimizing with non-GTSAM types. That opens the door to retiring geometric types such as Point2 and Point3 to pure Eigen types, which we also do. A significant change which will not trigger a compile error is that zero-initializing of Point2 and Point3 is deprecated, so please be aware that this might render functions using their default constructor incorrect.
Wrappers
We provide support for MATLAB and Python wrappers for GTSAM. Please refer to the linked documents for more details.
Citation
If you are using GTSAM for academic work, please use the following citation:
@software{gtsam,
author = {Frank Dellaert and GTSAM Contributors},
title = {borglab/gtsam},
month = May,
year = 2022,
publisher = {Georgia Tech Borg Lab},
version = {4.2a8},
doi = {10.5281/zenodo.5794541},
url = {https://github.com/borglab/gtsam)}}
}
To cite the Factor Graphs for Robot Perception
book, please use:
@book{factor_graphs_for_robot_perception,
author={Frank Dellaert and Michael Kaess},
year={2017},
title={Factor Graphs for Robot Perception},
publisher={Foundations and Trends in Robotics, Vol. 6},
url={http://www.cs.cmu.edu/~kaess/pub/Dellaert17fnt.pdf}
}
If you are using the IMU preintegration scheme, please cite:
@book{imu_preintegration,
author={Christian Forster and Luca Carlone and Frank Dellaert and Davide Scaramuzza},
title={IMU preintegration on Manifold for Efficient Visual-Inertial Maximum-a-Posteriori Estimation},
year={2015}
}
The Preintegrated IMU Factor
GTSAM includes a state of the art IMU handling scheme based on
- Todd Lupton and Salah Sukkarieh, "Visual-Inertial-Aided Navigation for High-Dynamic Motion in Built Environments Without Initial Conditions", TRO, 28(1):61-76, 2012. [link]
Our implementation improves on this using integration on the manifold, as detailed in
- Luca Carlone, Zsolt Kira, Chris Beall, Vadim Indelman, and Frank Dellaert, "Eliminating conditionally independent sets in factor graphs: a unifying perspective based on smart factors", Int. Conf. on Robotics and Automation (ICRA), 2014. [link]
- Christian Forster, Luca Carlone, Frank Dellaert, and Davide Scaramuzza, "IMU Preintegration on Manifold for Efficient Visual-Inertial Maximum-a-Posteriori Estimation", Robotics: Science and Systems (RSS), 2015. [link]
If you are using the factor in academic work, please cite the publications above.
In GTSAM 4 a new and more efficient implementation, based on integrating on the NavState tangent space and detailed in this document, is enabled by default. To switch to the RSS 2015 version, set the flag GTSAM_TANGENT_PREINTEGRATION
to OFF.
Additional Information
There is a GTSAM users Google group
for general discussion.
Read about important GTSAM-Concepts
here. A primer on GTSAM Expressions,
which support (superfast) automatic differentiation,
can be found on the GTSAM wiki on BitBucket.
See the INSTALL
file for more detailed installation instructions.
GTSAM is open source under the BSD license, see the LICENSE
and LICENSE.BSD
files.
Please see the examples/
directory and the USAGE
file for examples on how to use GTSAM.
GTSAM was developed in the lab of Frank Dellaert at the Georgia Institute of Technology, with the help of many contributors over the years, see THANKS.
Top Related Projects
A large scale non-linear optimization library
g2o: A General Framework for Graph Optimization
C++ implementation of Lie Groups using Eigen.
The Kalibr visual-inertial calibration toolbox
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot