Skip to content

Commit 0e0052e

Browse files
gupta-ishnevalsar
andauthored
Add g2o-pose-graphs in state-estimation (#223)
This PR adds a new wiki entry for the g2o library, covering pose graph optimization in C++. It includes an overview, structure, application details, and references. --------- Co-authored-by: Nevin Valsaraj <nevin.valsaraj32@gmail.com>
1 parent f96bb5e commit 0e0052e

3 files changed

Lines changed: 88 additions & 0 deletions

File tree

_data/navigation.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ wiki:
216216
url: /wiki/state-estimation/Cartographer-ROS-Integration/
217217
- title: Externally Referenced State Estimation for GPS Lacking Environments
218218
url: /wiki/state-estimation/gps-lacking-state-estimation-sensors/
219+
- title: Using g2o for Pose Graph Optimization in C++
220+
url: /wiki/state-estimation/g2o-pose-graphs/
219221
- title: Programming
220222
url: /wiki/programming/
221223
children:
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
date: 2025-05-04
3+
title: Using g2o for Pose Graph Optimization in C++
4+
---
5+
6+
This article provides a practical introduction to using **g2o** in C++ for pose graph optimization — a foundational tool in SLAM, calibration, and motion estimation. It is intended for robotics students or practitioners implementing multi-frame optimization, particularly in the context of Visual SLAM or sensor fusion. The article explains what g2o is and how to structure a typical optimization problem.
7+
8+
By the end of this article, you'll understand the essential building blocks of g2o, how to configure it for your graph-based problem, and how it fits into your robotic perception system.
9+
10+
## Overview of g2o
11+
[g2o (General Graph Optimization)](https://github.com/RainerKuemmerle/g2o) is a C++ library that solves nonlinear least-squares problems by representing them as graphs. In robotics, this graph typically consists of:
12+
- **Vertices:** Pose variables or landmark positions.
13+
- **Edges:** Constraints between variables, such as relative transformations.
14+
15+
Each vertex holds a state estimate (e.g., `SE3` pose), and each edge encodes an observation or measurement (e.g., odometry, loop closure). Optimization minimizes the total error across the graph.
16+
17+
> g2o is particularly useful when working with keyframes in SLAM or multi-view geometry where optimization improves the global consistency of pose estimates.
18+
19+
## g2o Structure and Components
20+
21+
### 1. SparseOptimizer
22+
The core of the framework is the `g2o::SparseOptimizer`, which manages all vertices and edges and runs the optimization routine.
23+
24+
### 2. Vertices
25+
Use `g2o::VertexSE3` to represent 6-DoF robot poses. Each vertex is assigned a unique ID and an initial estimate (from odometry or SLAM tracking).
26+
27+
### 3. Edges
28+
Use `g2o::EdgeSE3` to define constraints between two vertices. Edges store the relative pose and an information matrix (inverse covariance) to weigh the constraint.
29+
30+
### 4. Solver
31+
g2o supports different solvers like:
32+
- **Levenberg-Marquardt**
33+
- **Gauss-Newton**
34+
35+
You must also configure a linear solver backend like **CSparse** or **Eigen**.
36+
37+
### 5. Execution Flow
38+
The general flow includes:
39+
1. Initialize `SparseOptimizer` and set solver.
40+
2. Add all `VertexSE3` instances (each with `setEstimate()`).
41+
3. Add all `EdgeSE3` instances with relative pose and information.
42+
4. Call `initializeOptimization()` and then `optimize(n_iters)`.
43+
44+
### Basic Pseudocode
45+
```cpp
46+
g2o::SparseOptimizer optimizer;
47+
// Configure solver and backend
48+
// Add VertexSE3 with unique IDs and initial estimates
49+
// Add EdgeSE3 with relative transforms
50+
optimizer.initializeOptimization();
51+
optimizer.optimize(10);
52+
```
53+
54+
## Applications in Robotics
55+
56+
g2o is widely used in robotics for a variety of estimation and optimization tasks:
57+
58+
- **Visual SLAM**: Optimize camera or keyframe pose graphs for improved global consistency.
59+
- **Loop Closure**: Add constraints between distant frames to reduce accumulated drift in the trajectory.
60+
- **Bundle Adjustment**: Refine both 3D landmarks and camera parameters jointly for better reconstruction accuracy.
61+
- **Sensor Calibration**: Estimate rigid-body transformations between sensors or between the robot and the global frame.
62+
- **Multi-Robot Mapping**: Merge and optimize maps from different agents using inter-robot pose constraints.
63+
64+
These applications help robotic systems maintain accurate maps, trajectories, and spatial awareness under noisy measurements and long-term deployment.
65+
66+
## Summary
67+
68+
g2o is an essential optimization tool in modern robotic systems. With its efficient graph representation and support for custom vertex and edge types, it allows scalable and accurate optimization of nonlinear problems in SLAM, calibration, and state estimation. Once understood, it can be modularized and reused across perception, mapping, and planning tasks in both research and production systems.
69+
70+
## See Also:
71+
- [ORB-SLAM2 Optimization Module](https://github.com/raulmur/ORB_SLAM2)
72+
- [OpenSLAM](https://openslam-org.github.io/g2o.html)
73+
- [Python binding (also installable using pip)](https://github.com/miquelmassot/g2o-python)
74+
75+
## Further Reading
76+
- SLAM Book v2 – Chapter 7: Bundle Adjustment and g2o
77+
78+
## References
79+
- R. Kümmerle, G. Grisetti, H. Strasdat, K. Konolige, and W. Burgard, “g2o: A General Framework for Graph Optimization,” *Proceedings of the IEEE International Conference on Robotics and Automation (ICRA)*, 2011. [Paper PDF](https://ais.informatik.uni-freiburg.de/publications/papers/kuemmerle11icra.pdf)
80+
- g2o GitHub Repository. [https://github.com/RainerKuemmerle/g2o](https://github.com/RainerKuemmerle/g2o)

wiki/state-estimation/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ The "State Estimation" section provides a comprehensive understanding of how to
6161
- Pose-based and image-based approaches.
6262
- Application to drones for precise alignment tasks.
6363

64+
- **[Using g2o for Pose Graph Optimization in C++](/wiki/state-estimation/g2o-pose-graphs/)**
65+
Provides a practical introduction to using g2o for pose graph optimization in C++, essential for SLAM and state estimation.
66+
- Overview of g2o and its graph-based representation.
67+
- Implementation details for vertices, edges, and solvers.
68+
- Common applications in robotic perception and mapping.
69+
6470
## Resources
6571

6672
- [AMCL ROS Wiki](http://wiki.ros.org/amcl)

0 commit comments

Comments
 (0)